cddl 0.8.19 → 0.8.20
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/lib/cddl.rb +17 -8
- data/test-data/oid.cddl +8 -0
- data/test-data/sasl.cddl +24 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 400024278cc4fce962a5e51e60ba6025ec371cd5768685c0ce10534a06393fa2
|
4
|
+
data.tar.gz: cbac2ff6008501c65984cb816cc95b79a8adc361609c4858ba518c073e317937
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71babdced5f362b46a1877fdb8676faf2efec9594069b9b95c80daecdfb9aad5bf13ca73577437089fb1dd4819506b00311c003699831110fbba464c06d86fad
|
7
|
+
data.tar.gz: 2a29deef318b1c31a830e8937618d776fc439bc6a5b792b7daa79545ed29aedb028f6e78ce3f3b04f36767f21cf38ff349f6251ff3d83103f02c94a124132f34
|
data/cddl.gemspec
CHANGED
data/lib/cddl.rb
CHANGED
@@ -244,6 +244,12 @@ module CDDL
|
|
244
244
|
[rule[0], *rule[1]]
|
245
245
|
end
|
246
246
|
|
247
|
+
def remove_indentation(s)
|
248
|
+
l = s.lines
|
249
|
+
indent = l.grep(/\S/).map {|l| l[/^\s*/].size}.min
|
250
|
+
l.map {|l| l.sub(/^ {0,#{indent}}/, "")}.join
|
251
|
+
end
|
252
|
+
|
247
253
|
# Memoize a bit here
|
248
254
|
|
249
255
|
REGEXP_FOR_STRING = Hash.new {|h, k|
|
@@ -404,7 +410,7 @@ module CDDL
|
|
404
410
|
when :anno
|
405
411
|
target = where[2]
|
406
412
|
control = where[3]
|
407
|
-
case where[1]
|
413
|
+
case conop = where[1]
|
408
414
|
when :size
|
409
415
|
should_be_int = generate1(control)
|
410
416
|
unless (Array === target && target[0] == :prim && [0, 2, 3].include?(target[1])) && Integer === should_be_int && should_be_int >= 0
|
@@ -452,9 +458,10 @@ module CDDL
|
|
452
458
|
generate1(target, inmap)
|
453
459
|
when :feature
|
454
460
|
generate1(target, inmap)
|
455
|
-
when :cat
|
461
|
+
when :cat, :bat
|
456
462
|
lhs = generate1(target, inmap)
|
457
463
|
rhs = generate1(control)
|
464
|
+
rhs = remove_indentation(rhs) if conop == :bat
|
458
465
|
begin
|
459
466
|
lhs + rhs
|
460
467
|
rescue Exception => e
|
@@ -488,7 +495,7 @@ module CDDL
|
|
488
495
|
content = Integer(content)
|
489
496
|
case target[1]
|
490
497
|
when 0
|
491
|
-
case
|
498
|
+
case conop
|
492
499
|
when :lt
|
493
500
|
rand(0...content)
|
494
501
|
when :le
|
@@ -523,7 +530,7 @@ module CDDL
|
|
523
530
|
fail "Don't know yet how to generate #{where}"
|
524
531
|
end
|
525
532
|
out = ABNF_PARSER_FOR_STRING[grammar].generate
|
526
|
-
if
|
533
|
+
if conop == :abnfb
|
527
534
|
out = out.codepoints.pack("C*")
|
528
535
|
end
|
529
536
|
enc = bytes ? Encoding::BINARY : Encoding::UTF_8
|
@@ -533,7 +540,7 @@ module CDDL
|
|
533
540
|
fail "Don't know yet how to generate #{where}"
|
534
541
|
end
|
535
542
|
content = CBOR::encode(generate1(control))
|
536
|
-
if
|
543
|
+
if conop == :cborseq
|
537
544
|
# remove the first head
|
538
545
|
n = case content.getbyte(0) - (4 << 5)
|
539
546
|
when 0..23; 1
|
@@ -551,7 +558,7 @@ module CDDL
|
|
551
558
|
content = generate1(target)
|
552
559
|
if validate1(content, control)
|
553
560
|
return content
|
554
|
-
elsif
|
561
|
+
elsif conop == :within
|
555
562
|
warn "*** #{content.inspect} meets #{target.inspect} but not #{control.inspect}"
|
556
563
|
end
|
557
564
|
end
|
@@ -592,7 +599,7 @@ module CDDL
|
|
592
599
|
elsif t[0] == :anno
|
593
600
|
_, conop, target, control = t
|
594
601
|
# warn ["EXV0", conop, target, control].inspect
|
595
|
-
if conop == :cat || conop == :plus
|
602
|
+
if conop == :cat || conop == :plus || conop == :bat
|
596
603
|
ok1, v1, vt1 = extract_value(target)
|
597
604
|
ok2, v2, vt2 = extract_value(control)
|
598
605
|
# warn ["EXV", ok1, v1, vt1, ok2, v2, vt2].inspect
|
@@ -602,6 +609,7 @@ module CDDL
|
|
602
609
|
elsif vt1 == Float
|
603
610
|
[true, v1 + v2, vt1] if vt2 == Integer || vt2 == Float
|
604
611
|
else
|
612
|
+
v2 = remove_indentation(v2) if conop == :bat
|
605
613
|
[true, v1 + v2, vt1] if vt1 == vt2
|
606
614
|
end
|
607
615
|
end rescue nil
|
@@ -846,6 +854,7 @@ module CDDL
|
|
846
854
|
# warn ["ANNO0", ok1, v1, vt1, ok2, v2, vt2, d].inspect
|
847
855
|
if ok1 && ok2
|
848
856
|
v2 = Integer(v2) if vt1 == Integer
|
857
|
+
v2 = remove_indentation(v2) if conop == :bat
|
849
858
|
# warn ["ANNO", ok1, v1, vt1, ok2, v2, vt2, d].inspect
|
850
859
|
[] if d == v1 + v2 # XXX Focus ArgumentError
|
851
860
|
end
|
@@ -1295,7 +1304,7 @@ module CDDL
|
|
1295
1304
|
RANGE_EXCLUDE_END = {".." => false, "..." => true}
|
1296
1305
|
SUPPORTED_ANNOTATIONS = [:bits, :size, :regexp, :cbor, :cborseq, :within, :and,
|
1297
1306
|
:default, :lt, :le, :gt, :ge, :eq, :ne,
|
1298
|
-
:feature, :abnf, :abnfb, :cat, :plus]
|
1307
|
+
:feature, :abnf, :abnfb, :bat, :cat, :plus]
|
1299
1308
|
|
1300
1309
|
def type1(n, canbegroup = false)
|
1301
1310
|
# puts "NVALUE #{n.value.inspect}"
|
data/test-data/oid.cddl
ADDED
data/test-data/sasl.cddl
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
message = text .abnfb ("message" .cat rfc4505)
|
2
|
+
|
3
|
+
rfc4505 = '
|
4
|
+
message = [ email / token ]
|
5
|
+
;; to be prepared in accordance with Section 3
|
6
|
+
|
7
|
+
UTF1 = %x00-3F / %x41-7F ;; less "@" (U+0040)
|
8
|
+
UTF2 = %xC2-DF UTF0
|
9
|
+
UTF3 = %xE0 %xA0-BF UTF0 / %xE1-EC 2(UTF0) /
|
10
|
+
%xED %x80-9F UTF0 / %xEE-EF 2(UTF0)
|
11
|
+
UTF4 = %xF0 %x90-BF 2(UTF0) / %xF1-F3 3(UTF0) /
|
12
|
+
%xF4 %x80-8F 2(UTF0)
|
13
|
+
UTF0 = %x80-BF
|
14
|
+
|
15
|
+
TCHAR = UTF1 / UTF2 / UTF3 / UTF4
|
16
|
+
;; any UTF-8 encoded Unicode character
|
17
|
+
;; except "@" (U+0040)
|
18
|
+
|
19
|
+
email = "too@much.work"; for this example
|
20
|
+
;email = addr-spec
|
21
|
+
;; as defined in [IMAIL]
|
22
|
+
|
23
|
+
token = 1*255TCHAR
|
24
|
+
'
|
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.8.
|
4
|
+
version: 0.8.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carsten Bormann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cbor-diag
|
@@ -166,8 +166,10 @@ files:
|
|
166
166
|
- test-data/mon-val.cddl
|
167
167
|
- test-data/multipart-ct.cddl
|
168
168
|
- test-data/named-group.cddl
|
169
|
+
- test-data/oid.cddl
|
169
170
|
- test-data/patch1.cddl
|
170
171
|
- test-data/reused_named_group.cddl
|
172
|
+
- test-data/sasl.cddl
|
171
173
|
- test-data/sequence.cddl
|
172
174
|
- test-data/structure.cddl
|
173
175
|
- test-data/test-gen.cddl
|