cddl 0.10.6 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/cddl.gemspec +1 -1
- data/data/cddl.abnf +3 -2
- data/lib/cddl.rb +56 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b75dfee163242854b4a139d3a6e84710d9ac31702e57e502ac125b1b5e9dc944
|
4
|
+
data.tar.gz: 4a5360b99c364b7cd6c1aa518a332e79616e65331a95243ba2406a8d04712639
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1127b09451324ff3842890e59e077c96f3c248082c9dac7f194f453faf88d0c9ffc8e7326c8087677ec953c03b62cbe50e582a2d8362876e57375289453ab3e4
|
7
|
+
data.tar.gz: 74ce9832d9a84dd4204411beecd9b029ddb76eacbc9e09e2056512310cbdb4309d439360d9bc1bf6c86ca60a87b7ca3423f9ef8471481657bda327f816b4426b
|
data/cddl.gemspec
CHANGED
data/data/cddl.abnf
CHANGED
@@ -13,7 +13,8 @@ genericarg = "<" S type1 S *("," S type1 S ) ">"
|
|
13
13
|
type = type1 S *("/" S type1 S)
|
14
14
|
|
15
15
|
type1 = type2 [S (rangeop / annotator) S type2]
|
16
|
-
/ "#" "6" ["."
|
16
|
+
/ "#" "6" ["." headnumber] "(" S type S ")" ; note no space!
|
17
|
+
/ "#" "7" ["." headnumber] ; note no space!
|
17
18
|
/ "#" DIGIT ["." uint] ; major/ai
|
18
19
|
/ "#" ; any
|
19
20
|
/ "~" S typename [genericarg]
|
@@ -22,7 +23,7 @@ type1 = type2 [S (rangeop / annotator) S type2]
|
|
22
23
|
/ "&" S "(" S group S ")"
|
23
24
|
/ "&" S groupname [genericarg]
|
24
25
|
|
25
|
-
|
26
|
+
headnumber = uint / ("<" type ">")
|
26
27
|
|
27
28
|
type2 = value
|
28
29
|
/ typename [genericarg]
|
data/lib/cddl.rb
CHANGED
@@ -2,6 +2,7 @@ require 'abnc'
|
|
2
2
|
require 'pp'
|
3
3
|
require 'pathname'
|
4
4
|
require 'cbor-pure' unless defined?(CBOR::Tagged)
|
5
|
+
require 'half'
|
5
6
|
require 'cbor-deterministic'
|
6
7
|
require 'regexp-examples'
|
7
8
|
require 'abnftt'
|
@@ -429,7 +430,11 @@ module CDDL
|
|
429
430
|
end
|
430
431
|
CBOR::Tagged.new(tn, generate1(where[3]))
|
431
432
|
when 7
|
432
|
-
|
433
|
+
w2 = where[2]
|
434
|
+
if Array === w2
|
435
|
+
w2 = generate1(w2)
|
436
|
+
end
|
437
|
+
case w2
|
433
438
|
when nil
|
434
439
|
Math::PI
|
435
440
|
when 20
|
@@ -438,10 +443,22 @@ module CDDL
|
|
438
443
|
true
|
439
444
|
when 22
|
440
445
|
nil
|
441
|
-
when 23
|
442
|
-
|
443
|
-
when 25
|
444
|
-
rand()
|
446
|
+
when 0..19, 23, 32..255
|
447
|
+
CBOR::Simple.new(w2)
|
448
|
+
when 25
|
449
|
+
while !(hs = Half.encode_from_single_bytes([rand()].pack("g")))
|
450
|
+
end
|
451
|
+
Half.decode(hs)
|
452
|
+
when 26
|
453
|
+
while (a = [rand()].pack("g").unpack("g").first).to_cbor.size != 5
|
454
|
+
end
|
455
|
+
a
|
456
|
+
when 27
|
457
|
+
while (a = rand()).to_cbor.size != 9
|
458
|
+
end
|
459
|
+
a
|
460
|
+
else
|
461
|
+
fail "Can't generate prim #7.#{where[2].inspect}" # XXX retry array generate
|
445
462
|
end
|
446
463
|
else
|
447
464
|
fail "Can't generate prim #{where[1]}"
|
@@ -708,14 +725,26 @@ module CDDL
|
|
708
725
|
[:prim, 7, 20] => [true, false, :bool],
|
709
726
|
[:prim, 7, 21] => [true, true, :bool],
|
710
727
|
[:prim, 7, 22] => [true, nil, :nil],
|
711
|
-
[:prim, 7, 23] => [true, :undefined, :undefined],
|
712
728
|
}
|
729
|
+
SIMPLE_VALUE_SIMPLE = Set[23] + (0..19) + (32..255)
|
713
730
|
|
714
731
|
def extract_value(t) # []
|
715
732
|
if vt = VALUE_TYPE[t[0]]
|
716
733
|
[true, t[1], vt]
|
717
|
-
elsif
|
718
|
-
|
734
|
+
elsif t[0] == :prim && t[1] == 7
|
735
|
+
case t2 = t[2]
|
736
|
+
when Integer
|
737
|
+
when Array
|
738
|
+
a, b, c = extract_value(t2)
|
739
|
+
if a && c == Integer
|
740
|
+
t2 = b
|
741
|
+
end
|
742
|
+
end
|
743
|
+
if v = SIMPLE_VALUE[[:prim, 7, t2]]
|
744
|
+
v
|
745
|
+
elsif SIMPLE_VALUE_SIMPLE === t2
|
746
|
+
[true, CBOR::Simple.new(t2), :simple]
|
747
|
+
end
|
719
748
|
elsif t[0] == :anno
|
720
749
|
_, conop, target, control = t
|
721
750
|
# warn ["EXV0", conop, target, control].inspect
|
@@ -963,6 +992,7 @@ module CDDL
|
|
963
992
|
end
|
964
993
|
|
965
994
|
OPERATORS = {lt: :<, le: :<=, gt: :>, ge: :>=, eq: :==, ne: :!=}
|
995
|
+
FLOAT_AI_FROM_SIZE = {3 => 25, 5 => 26, 9 => 27}
|
966
996
|
|
967
997
|
def validate1(d, where)
|
968
998
|
if ENV["CDDL_TRACE"]
|
@@ -1230,12 +1260,25 @@ module CDDL
|
|
1230
1260
|
if t
|
1231
1261
|
v.eql? d
|
1232
1262
|
else
|
1233
|
-
case where[2]
|
1263
|
+
case w2 = where[2]
|
1234
1264
|
when nil
|
1235
|
-
|
1236
|
-
|
1265
|
+
Float === d || CBOR::Simple === d || [false, true, nil].include?(d)
|
1266
|
+
when Array
|
1267
|
+
headnum = case d
|
1268
|
+
when Float
|
1269
|
+
FLOAT_AI_FROM_SIZE[d.to_cbor.size]
|
1270
|
+
when false
|
1271
|
+
20
|
1272
|
+
when true
|
1273
|
+
21
|
1274
|
+
when nil
|
1275
|
+
22
|
1276
|
+
when CBOR::Simple
|
1277
|
+
d.value
|
1278
|
+
end
|
1279
|
+
validate1a(headnum, w2)
|
1237
1280
|
when 25, 26, 27
|
1238
|
-
Float === d
|
1281
|
+
Float === d && FLOAT_AI_FROM_SIZE[d.to_cbor.size] == w2
|
1239
1282
|
else
|
1240
1283
|
fail [:val7, d, where].inspect
|
1241
1284
|
end
|
@@ -1584,7 +1627,7 @@ module CDDL
|
|
1584
1627
|
when /\A#(\d+)/
|
1585
1628
|
maj = $1.to_i
|
1586
1629
|
s = [:prim, maj, *n.children(:uint).map(&:to_s).map(&:to_i)]
|
1587
|
-
if tn = n.
|
1630
|
+
if tn = n.headnumber
|
1588
1631
|
if ui = tn.uint
|
1589
1632
|
s << ui.to_s.to_i
|
1590
1633
|
elsif tt = tn.type
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cddl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carsten Bormann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02
|
11
|
+
date: 2024-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cbor-diag
|