cddl 0.12.2 → 0.12.14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b6553d8156f74c2c630f22f6069c537e53b4f34a3d436df02ce73f99e648cb5
4
- data.tar.gz: 175ddf07c82ef984d40c932eb80f8a8d7cdab54823777d8e9482239251756edc
3
+ metadata.gz: a4b5bfb31fd9b7fcf4cf66a1d0f2a76550c9682215c486d99a03997bab1ae30b
4
+ data.tar.gz: 97f11378fb18576f115ffb8cbd668fe9e14e33e91e4aac01d874c69e206f2fbd
5
5
  SHA512:
6
- metadata.gz: 357a054cb881ab89c00befe26adfcbf9999b8cbd19f400bdd31eccc39a0eb690e50f4552fc446dfa364086987e1187638983e3579e1a3e06084eb874e1311509
7
- data.tar.gz: bf8e429cf02926f4c078e7911d73ccffb47ee3c96520f627e33673333061cd85b472e3795a122362fe615c7b73f8ac2ad6ac02290c5f9a0a9ba19ebe3b15fae6
6
+ metadata.gz: 623f3945c3fff7c04dd2a4e1c77879d585d347092c87b54d5ead6b8fb3ed3c5ab68a58ae67b7f3f936437c8bc9f92dea6f8597509ba8913fbc5e2e47f43d398a
7
+ data.tar.gz: a04d3f282b0d42182f63dd66988fece8fb0ab7ddb4e159b2f8213705503cff0a97b622a172096b881dc4fe70f16bdcc48a51fa035413bc55421bb5e15d1bcda3
data/cddl.gemspec CHANGED
@@ -1,13 +1,13 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'cddl'
3
- s.version = '0.12.2'
3
+ s.version = '0.12.14'
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')
7
7
  s.add_dependency('abnc', '~> 0.1.1')
8
8
  s.add_dependency('json_pure')
9
9
  s.add_dependency('abnftt')
10
- s.add_dependency('regexp-examples') # , '1.1.0')
10
+ s.add_dependency('regexp-examples', '~> 1.5.1') # , '1.1.0')
11
11
  s.add_dependency('colorize')
12
12
  s.add_dependency('base32', '~> 0.3')
13
13
  s.add_dependency('base45_lite', '~> 1.0')
@@ -16,11 +16,10 @@ spec = Gem::Specification.new do |s|
16
16
  s.files = Dir['lib/**/*.rb'] + %w(cddl.gemspec) + Dir['data/**/*.abnf'] + Dir['data/**/*.cddl'] + Dir['test-data/**/*.cddl'] + Dir['test/**/*.rb']
17
17
  s.require_path = 'lib'
18
18
  s.executables = ['cddl']
19
- s.default_executable = 'cddl'
20
19
  s.required_ruby_version = '>= 2.3'
21
20
  s.author = "Carsten Bormann"
22
21
  s.email = "cabo@tzi.org"
23
- s.homepage = "http://github.com/cabo/cddl"
22
+ s.homepage = "https://www.rfc-editor.org/rfc/rfc8610#appendix-F"
24
23
  s.license = 'MIT'
25
24
  end
26
25
 
data/data/cddl.abnf CHANGED
@@ -41,7 +41,7 @@ grpent = [occur S] [memberkey S] type optcom
41
41
  / [occur S] groupname [genericarg] optcom ; preempted by above
42
42
  / [occur S] "(" S group S ")" optcom
43
43
 
44
- memberkey = type1 S "=>"
44
+ memberkey = type1 S ["^" S] "=>"
45
45
  / bareword S ":"
46
46
  / value S ":"
47
47
 
@@ -65,9 +65,10 @@ value = number
65
65
  int = ["-"] uint
66
66
 
67
67
  ; This is a float if it has fraction or exponent; int otherwise
68
- number = int ["." fraction] ["e" exponent ]
68
+ number = hexfloat / (int ["." fraction] ["e" exponent ])
69
+ hexfloat = ["-"] "0x" 1*HEXDIG ["." 1*HEXDIG] "p" exponent
69
70
  fraction = 1*DIGIT
70
- exponent = int
71
+ exponent = ["+"/"-"] 1*DIGIT
71
72
 
72
73
  text = %x22 *SCHAR %x22
73
74
  SCHAR = %x20-21 / %x23-5B / %x5D-7E / NONASCII / SESC
data/lib/cddl.rb CHANGED
@@ -40,6 +40,7 @@ module CDDL
40
40
  [{}, {}]
41
41
  end
42
42
 
43
+ CDDL_UNUSED_OK = ENV["CDDL_UNUSED_OK"]
43
44
 
44
45
  class BackTrack < Exception; end
45
46
 
@@ -118,6 +119,16 @@ module CDDL
118
119
  r.compact
119
120
  end
120
121
 
122
+ def longest_initial_match(old, now)
123
+ md = /\A(.*)(.*)\n\1(.*)\z/.match([old,now].join("\n"))
124
+ md[1..3]
125
+ end
126
+
127
+ def diff_message(old, now)
128
+ c, l, r = longest_initial_match(old, now)
129
+ "-- common: >#{c}< -- old: >#{l}< -- new: >#{r}<"
130
+ end
131
+
121
132
  def cname(s)
122
133
  s.to_s.gsub(/-/, "_")
123
134
  end
@@ -204,7 +215,8 @@ module CDDL
204
215
  ids = g.children(:id).map(&:to_s)
205
216
  # puts ["ids", ids].inspect
206
217
  if b = @generics[n]
207
- fail "Duplicate generics definition #{n} as #{rule_ast} (was #{b})"
218
+ fail "Duplicate generics definition #{n} #{
219
+ diff_message(strip_nodes(b[0]).inspect, strip_nodes(rule_ast).inspect)}"
208
220
  end
209
221
  @generics[n] = [rule_ast, ids]
210
222
  else
@@ -216,7 +228,7 @@ module CDDL
216
228
  if a == b
217
229
  warn "*** Warning: Identical redefinition of #{n} as #{a}"
218
230
  else
219
- fail "Duplicate rule definition #{n} as #{b} (was #{a})"
231
+ fail "Duplicate rule definition #{n} #{diff_message(b, a)}"
220
232
  end
221
233
  end
222
234
  @rules[n] = rule_ast
@@ -248,7 +260,7 @@ module CDDL
248
260
  r_process("used_in_cddl_prelude", @rules["used_in_cddl_prelude"])
249
261
  @rules.each do |n, r|
250
262
  # r_process(n, r) # debug only loop
251
- warn "*** Unused rule #{n}" unless @stage1[n]
263
+ warn "*** Unused rule #{n}" unless @stage1[n] || CDDL_UNUSED_OK
252
264
  end
253
265
  if result[0] == :grpent
254
266
  warn "Group at top -- first rule must be a type!"
@@ -302,6 +314,12 @@ module CDDL
302
314
  abnfb: Encoding::BINARY
303
315
  }
304
316
 
317
+ def myfrand(exp)
318
+ exprange = 1 << exp
319
+ expoffset= exprange >> 1
320
+ (rand(2)*2-1) * rand() * 2.0**(rand(exprange)-expoffset)
321
+ end
322
+
305
323
  def generate
306
324
  @recursion = 0
307
325
  generate1(rules)
@@ -446,15 +464,15 @@ module CDDL
446
464
  when 0..19, 23, 32..255
447
465
  CBOR::Simple.new(w2)
448
466
  when 25
449
- while !(hs = Half.encode_from_single_bytes([rand()].pack("g")))
467
+ while !(hs = Half.encode_from_single_bytes([myfrand(5)].pack("g")))
450
468
  end
451
469
  Half.decode(hs)
452
470
  when 26
453
- while (a = [rand()].pack("g").unpack("g").first).to_cbor.size != 5
471
+ while (a = [myfrand(8)].pack("g").unpack("g").first).to_cbor.size != 5
454
472
  end
455
473
  a
456
474
  when 27
457
- while (a = rand()).to_cbor.size != 9
475
+ while (a = myfrand(11)).to_cbor.size != 9
458
476
  end
459
477
  a
460
478
  else
@@ -619,7 +637,13 @@ module CDDL
619
637
  end
620
638
  content = JSON::dump(generate1(control))
621
639
  content
622
- when :decimal
640
+ when :decimal, :base10
641
+ if conop == :decimal
642
+ unless @decimal_warned
643
+ warn "** .decimal control operator is now called .base10"
644
+ @decimal_warned = true
645
+ end
646
+ end
623
647
  unless target == [:prim, 3]
624
648
  fail "Don't know yet how to generate #{where}"
625
649
  end
@@ -686,6 +710,7 @@ module CDDL
686
710
  fail "Not smart enough to generate #{where}#{@last_message}"
687
711
  when :within, :and
688
712
  try_generate(target) do |content|
713
+ $features ||= Hash.new {|h, k| h[k] = {}}
689
714
  if validate1(content, control)
690
715
  return content
691
716
  elsif conop == :within
@@ -1005,6 +1030,7 @@ module CDDL
1005
1030
  end
1006
1031
 
1007
1032
  OPERATORS = {lt: :<, le: :<=, gt: :>, ge: :>=, eq: :==, ne: :!=}
1033
+ OPERATORS_MATCH = {eq: true, ne: false}
1008
1034
  FLOAT_AI_FROM_SIZE = {3 => 25, 5 => 26, 9 => 27}
1009
1035
 
1010
1036
  def validate1(d, where)
@@ -1016,6 +1042,9 @@ module CDDL
1016
1042
  @last_data = d
1017
1043
  @last_rule = where
1018
1044
  ann = nil
1045
+ if CBOR::Tagged === d && d.tag === 888 && ENV["CDDL_888"]
1046
+ return []
1047
+ end
1019
1048
  case where[0]
1020
1049
  when :type1
1021
1050
  if where[1..-1].any? {|r| ann = validate1a(d, r)}
@@ -1135,6 +1164,11 @@ module CDDL
1135
1164
  ok, v, _vt = extract_value(control)
1136
1165
  if ok
1137
1166
  ann if d.send(op, v) rescue nil # XXX Focus ArgumentError
1167
+ else
1168
+ needs_to_match = OPERATORS_MATCH[conop]
1169
+ unless needs_to_match.nil?
1170
+ ann if !!validate1(d, control) == needs_to_match
1171
+ end
1138
1172
  end
1139
1173
  when :regexp
1140
1174
  ann if (
@@ -1187,7 +1221,14 @@ module CDDL
1187
1221
  end
1188
1222
  when :json
1189
1223
  ann if validate1((JSON::load(d) rescue :BAD_JSON), control)
1190
- when :decimal
1224
+ when :decimal, :base10
1225
+ if conop == :decimal
1226
+ unless @decimal_warned
1227
+ warn "** .decimal control operator is now called .base10"
1228
+ @decimal_warned = true
1229
+ end
1230
+ end
1231
+
1191
1232
  ann if (
1192
1233
  if /\A0|-?[1-9][0-9]*\z/ === d
1193
1234
  validate1((d.to_i rescue :BAD_JSON), control)
@@ -1428,6 +1469,10 @@ module CDDL
1428
1469
  else
1429
1470
  [:type1]
1430
1471
  end
1472
+ elsif s = ENV["CDDL_INVENT"]
1473
+ s = "_" if s == ""
1474
+ r = [:type1, [:text, "#{s}-#{name}"]]
1475
+ return r
1431
1476
  end
1432
1477
  end
1433
1478
  if r
@@ -1531,7 +1576,11 @@ module CDDL
1531
1576
  end
1532
1577
  }
1533
1578
  end
1534
- val = eval(s)
1579
+ if s =~ /p.*\d\z/ # hexfloat
1580
+ val = s.scanf("%a").first
1581
+ else
1582
+ val = eval(s)
1583
+ end
1535
1584
  # warn val
1536
1585
  case val
1537
1586
  when Integer; [:int, val]
@@ -1724,7 +1773,7 @@ module CDDL
1724
1773
  :within, :and,
1725
1774
  :default, :lt, :le, :gt, :ge, :eq, :ne,
1726
1775
  :feature, :abnf, :abnfb, :det, :cat, :plus,
1727
- :json, :decimal, :join,
1776
+ :json, :decimal, :base10, :join,
1728
1777
  :b64u, :"b64u-sloppy", :b64c, :"b64c-sloppy",
1729
1778
  :b45, :b32, :h32, :hex, :hexlc, :hexuc,
1730
1779
  :printf,
@@ -0,0 +1 @@
1
+ s = [text .decimal 4711, text .base10 4712]
@@ -0,0 +1,16 @@
1
+ cwt = [
2
+ bstr .cbor protected-map,
3
+ unprotected-map,
4
+ bstr .cbor payload-map,
5
+ bstr ; signature
6
+ ]
7
+
8
+ protected-map = {
9
+ &(alg: 1) => int,
10
+ ? &(typ: 16) => text,
11
+ * key => any
12
+ }
13
+
14
+ unprotected-map = ()
15
+ key = "key"
16
+ payload-map = { payload: "map"}
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cddl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.2
4
+ version: 0.12.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-06-02 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: cbor-diag
@@ -70,16 +69,16 @@ dependencies:
70
69
  name: regexp-examples
71
70
  requirement: !ruby/object:Gem::Requirement
72
71
  requirements:
73
- - - ">="
72
+ - - "~>"
74
73
  - !ruby/object:Gem::Version
75
- version: '0'
74
+ version: 1.5.1
76
75
  type: :runtime
77
76
  prerelease: false
78
77
  version_requirements: !ruby/object:Gem::Requirement
79
78
  requirements:
80
- - - ">="
79
+ - - "~>"
81
80
  - !ruby/object:Gem::Version
82
- version: '0'
81
+ version: 1.5.1
83
82
  - !ruby/object:Gem::Dependency
84
83
  name: colorize
85
84
  requirement: !ruby/object:Gem::Requirement
@@ -184,6 +183,7 @@ files:
184
183
  - test-data/cose.cddl
185
184
  - test-data/dcaf.cddl
186
185
  - test-data/dcaf1.cddl
186
+ - test-data/decimal-warn.cddl
187
187
  - test-data/decimal.cddl
188
188
  - test-data/decimal2.cddl
189
189
  - test-data/det1.cddl
@@ -263,6 +263,7 @@ files:
263
263
  - test-data/toerless0.cddl
264
264
  - test-data/toerless1.cddl
265
265
  - test-data/two_anonymous_groups.cddl
266
+ - test-data/valemb.cddl
266
267
  - test-data/wrong1.cddl
267
268
  - test-data/wrong1a.cddl
268
269
  - test-data/wrong2.cddl
@@ -271,11 +272,10 @@ files:
271
272
  - test-data/yangid.cddl
272
273
  - test-data/yaron1.cddl
273
274
  - test/test-cddl.rb
274
- homepage: http://github.com/cabo/cddl
275
+ homepage: https://www.rfc-editor.org/rfc/rfc8610#appendix-F
275
276
  licenses:
276
277
  - MIT
277
278
  metadata: {}
278
- post_install_message:
279
279
  rdoc_options: []
280
280
  require_paths:
281
281
  - lib
@@ -290,8 +290,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
290
290
  - !ruby/object:Gem::Version
291
291
  version: '0'
292
292
  requirements: []
293
- rubygems_version: 3.5.11
294
- signing_key:
293
+ rubygems_version: 4.0.8
295
294
  specification_version: 4
296
295
  summary: CDDL generator and validator.
297
296
  test_files: []