cddl 0.10.7 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/cddl.gemspec +1 -1
  3. data/data/cddl.abnf +3 -2
  4. data/lib/cddl.rb +54 -16
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd34ee2aa2fc9a5d0d504d0dc48222f4e94722b4e19086d4932b8bcc82980e92
4
- data.tar.gz: b397db50185a9f899c6b3d4bc9ce63946a1f57c6989cb7cf55215eb1d6da9868
3
+ metadata.gz: b75dfee163242854b4a139d3a6e84710d9ac31702e57e502ac125b1b5e9dc944
4
+ data.tar.gz: 4a5360b99c364b7cd6c1aa518a332e79616e65331a95243ba2406a8d04712639
5
5
  SHA512:
6
- metadata.gz: 96be7107033f0e3ef5da1ee747738bcd712eeb5af8230e11f128d64d0649920c8d15f5f4a13c5ccfb0ececad19dac7da1a145337f6e1a322ffe3573d7af4c689
7
- data.tar.gz: d3edd46ef0698fde296cb18509101f98700568c942652e77e6d36abdd7a9a79e27d2fb920a3a5efc46160466feff0ecaa0ae0fda45411a94d234ed4ace037deb
6
+ metadata.gz: 1127b09451324ff3842890e59e077c96f3c248082c9dac7f194f453faf88d0c9ffc8e7326c8087677ec953c03b62cbe50e582a2d8362876e57375289453ab3e4
7
+ data.tar.gz: 74ce9832d9a84dd4204411beecd9b029ddb76eacbc9e09e2056512310cbdb4309d439360d9bc1bf6c86ca60a87b7ca3423f9ef8471481657bda327f816b4426b
data/cddl.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'cddl'
3
- s.version = '0.10.7'
3
+ s.version = '0.11.1'
4
4
  s.summary = "CDDL generator and validator."
5
5
  s.description = %{A parser, generator, and validator for CDDL}
6
6
  s.add_dependency('cbor-diag')
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" ["." tagnumber] "(" S type S ")" ; note no space!
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
- tagnumber = uint / ("<" type ">")
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
- case where[2]
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
@@ -439,9 +444,21 @@ module CDDL
439
444
  when 22
440
445
  nil
441
446
  when 0..19, 23, 32..255
442
- CBOR::Simple.new(where[2])
443
- when 25, 26, 27
444
- rand()
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]}"
@@ -710,17 +727,24 @@ module CDDL
710
727
  [:prim, 7, 22] => [true, nil, :nil],
711
728
  }
712
729
  SIMPLE_VALUE_SIMPLE = Set[23] + (0..19) + (32..255)
713
- SIMPLE_VALUE.default_proc = proc { |hash, t|
714
- if t[0] == :prim && t[1] == 7 && SIMPLE_VALUE_SIMPLE.include?(t[2])
715
- [true, CBOR::Simple.new(t[2]), :simple]
716
- end
717
- }
718
730
 
719
731
  def extract_value(t) # []
720
732
  if vt = VALUE_TYPE[t[0]]
721
733
  [true, t[1], vt]
722
- elsif v = SIMPLE_VALUE[t]
723
- v
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
724
748
  elsif t[0] == :anno
725
749
  _, conop, target, control = t
726
750
  # warn ["EXV0", conop, target, control].inspect
@@ -968,6 +992,7 @@ module CDDL
968
992
  end
969
993
 
970
994
  OPERATORS = {lt: :<, le: :<=, gt: :>, ge: :>=, eq: :==, ne: :!=}
995
+ FLOAT_AI_FROM_SIZE = {3 => 25, 5 => 26, 9 => 27}
971
996
 
972
997
  def validate1(d, where)
973
998
  if ENV["CDDL_TRACE"]
@@ -1235,12 +1260,25 @@ module CDDL
1235
1260
  if t
1236
1261
  v.eql? d
1237
1262
  else
1238
- case where[2]
1263
+ case w2 = where[2]
1239
1264
  when nil
1240
- # XXX
1241
- fail [:valnil, d, where].inspect
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)
1242
1280
  when 25, 26, 27
1243
- Float === d
1281
+ Float === d && FLOAT_AI_FROM_SIZE[d.to_cbor.size] == w2
1244
1282
  else
1245
1283
  fail [:val7, d, where].inspect
1246
1284
  end
@@ -1589,7 +1627,7 @@ module CDDL
1589
1627
  when /\A#(\d+)/
1590
1628
  maj = $1.to_i
1591
1629
  s = [:prim, maj, *n.children(:uint).map(&:to_s).map(&:to_i)]
1592
- if tn = n.tagnumber
1630
+ if tn = n.headnumber
1593
1631
  if ui = tn.uint
1594
1632
  s << ui.to_s.to_i
1595
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.10.7
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-26 00:00:00.000000000 Z
11
+ date: 2024-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cbor-diag