cddl 0.6.5 → 0.7.0
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 +42 -1
- data/test/test-cddl.rb +99 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ea47a90f675f5589227fb3a10db240bddaae6c8e
|
|
4
|
+
data.tar.gz: 04f10cc045bbc451c244e2d6de26e8a1c0a64cf9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7d1bda5f7bf502ba4dbb0d11ff1ac40ee249892a086e95c0c00dc4f4928e2384b6a8b26a2940c6ea7e7b342af06ec8aa5320d61ea019bce101945b287910bb8b
|
|
7
|
+
data.tar.gz: 7f69f714dcc39eb85474df6823a48b7a67b8dfdbc5fcfdb8b459ba7798a411e66673de622a690486dfe85ad6feb88ea9188ab4966b3d5b3a028982c1f97d9f75
|
data/cddl.gemspec
CHANGED
data/lib/cddl.rb
CHANGED
|
@@ -415,6 +415,34 @@ module CDDL
|
|
|
415
415
|
fail "Don't know yet how to generate #{where}"
|
|
416
416
|
end
|
|
417
417
|
REGEXP_FOR_STRING[regexp].random_example(max_repeater_variance: 5)
|
|
418
|
+
when :cbor, :cborseq
|
|
419
|
+
unless target == [:prim, 2]
|
|
420
|
+
fail "Don't know yet how to generate #{where}"
|
|
421
|
+
end
|
|
422
|
+
content = CBOR::encode(generate1(control))
|
|
423
|
+
if where[1] == :cborseq
|
|
424
|
+
# remove the first head
|
|
425
|
+
n = case content.getbyte(0) - (4 << 5)
|
|
426
|
+
when 0..23; 1
|
|
427
|
+
when 24; 2
|
|
428
|
+
when 25; 3
|
|
429
|
+
when 26; 5
|
|
430
|
+
when 27; 9 # unlikely :-)
|
|
431
|
+
else fail "Generated .cborseq sequence for #{where} not an array"
|
|
432
|
+
end
|
|
433
|
+
content[0...n] = ''
|
|
434
|
+
end
|
|
435
|
+
content
|
|
436
|
+
when :within, :and
|
|
437
|
+
32.times do
|
|
438
|
+
content = generate1(target)
|
|
439
|
+
if validate1(content, control)
|
|
440
|
+
return content
|
|
441
|
+
elsif where[1] == :within
|
|
442
|
+
warn "*** #{content.inspect} meets #{target.inspect} but not #{control.inspect}"
|
|
443
|
+
end
|
|
444
|
+
end
|
|
445
|
+
fail "Not smart enough to generate #{where}"
|
|
418
446
|
else
|
|
419
447
|
fail "Don't know yet how to generate from #{where}"
|
|
420
448
|
end
|
|
@@ -684,6 +712,19 @@ module CDDL
|
|
|
684
712
|
end
|
|
685
713
|
end
|
|
686
714
|
)
|
|
715
|
+
when :cbor
|
|
716
|
+
ann if validate1((CBOR::decode(d) rescue :BAD_CBOR), control)
|
|
717
|
+
when :cborseq
|
|
718
|
+
ann if validate1((CBOR::decode("\x9f".b << d << "\xff".b) rescue :BAD_CBOR), control)
|
|
719
|
+
when :within
|
|
720
|
+
if validate1(d, control)
|
|
721
|
+
ann
|
|
722
|
+
else
|
|
723
|
+
warn "*** #{d.inspect} meets #{target} but not #{control}"
|
|
724
|
+
nil
|
|
725
|
+
end
|
|
726
|
+
when :and
|
|
727
|
+
ann if validate1(d, control)
|
|
687
728
|
else
|
|
688
729
|
fail "Don't know yet how to validate against #{where}"
|
|
689
730
|
end
|
|
@@ -996,7 +1037,7 @@ module CDDL
|
|
|
996
1037
|
|
|
997
1038
|
BRACE = {"{" => :map, "[" => :array}
|
|
998
1039
|
RANGE_EXCLUDE_END = {".." => false, "..." => true}
|
|
999
|
-
SUPPORTED_ANNOTATIONS = [:bits, :size, :regexp]
|
|
1040
|
+
SUPPORTED_ANNOTATIONS = [:bits, :size, :regexp, :cbor, :cborseq, :within, :and]
|
|
1000
1041
|
|
|
1001
1042
|
def type1(n, canbegroup = false)
|
|
1002
1043
|
# puts "NVALUE #{n.value.inspect}"
|
data/test/test-cddl.rb
CHANGED
|
@@ -902,6 +902,104 @@ HERE
|
|
|
902
902
|
refute parser.validate("re", false)
|
|
903
903
|
end
|
|
904
904
|
|
|
905
|
+
def test_cbor_annotation1
|
|
906
|
+
parser = CDDL::Parser.new <<HERE
|
|
907
|
+
test = bytes .cbor 1
|
|
908
|
+
HERE
|
|
909
|
+
pp parser.rules
|
|
910
|
+
5.times do
|
|
911
|
+
gen = parser.generate
|
|
912
|
+
assert_equal "\x01", gen
|
|
913
|
+
pp gen
|
|
914
|
+
assert parser.validate(gen)
|
|
915
|
+
end
|
|
916
|
+
assert parser.validate("\x01".b)
|
|
917
|
+
assert parser.validate("\x18\x01".b)
|
|
918
|
+
refute parser.validate("1", false)
|
|
919
|
+
refute parser.validate("\x00".b, false)
|
|
920
|
+
end
|
|
921
|
+
|
|
922
|
+
def test_cbor_annotation_uint
|
|
923
|
+
parser = CDDL::Parser.new <<HERE
|
|
924
|
+
test = bytes .cbor uint
|
|
925
|
+
HERE
|
|
926
|
+
pp parser.rules
|
|
927
|
+
5.times do
|
|
928
|
+
gen = parser.generate
|
|
929
|
+
assert String === gen
|
|
930
|
+
assert_equal 0, gen.getbyte(0) >> 5
|
|
931
|
+
pp ["CAU", gen]
|
|
932
|
+
assert parser.validate(gen)
|
|
933
|
+
end
|
|
934
|
+
assert parser.validate("\x01".b)
|
|
935
|
+
assert parser.validate("\x00".b)
|
|
936
|
+
assert parser.validate("\x18\x01".b)
|
|
937
|
+
refute parser.validate("1", false)
|
|
938
|
+
refute parser.validate("\x00\x00".b, false)
|
|
939
|
+
end
|
|
940
|
+
|
|
941
|
+
def test_cborseq_annotation_uint
|
|
942
|
+
parser = CDDL::Parser.new <<HERE
|
|
943
|
+
test = bytes .cborseq uint
|
|
944
|
+
HERE
|
|
945
|
+
assert_raise {
|
|
946
|
+
parser.generate
|
|
947
|
+
}
|
|
948
|
+
end
|
|
949
|
+
|
|
950
|
+
def test_cbor_annotation_uint_array
|
|
951
|
+
parser = CDDL::Parser.new <<HERE
|
|
952
|
+
test = bytes .cborseq myarray
|
|
953
|
+
myarray = [1*4uint]
|
|
954
|
+
HERE
|
|
955
|
+
pp parser.rules
|
|
956
|
+
5.times do
|
|
957
|
+
gen = parser.generate
|
|
958
|
+
assert String === gen
|
|
959
|
+
pp ["CAUA", gen]
|
|
960
|
+
assert_equal 0, gen.getbyte(0) >> 5 unless gen == ''
|
|
961
|
+
assert parser.validate(gen)
|
|
962
|
+
end
|
|
963
|
+
assert parser.validate("\x01".b)
|
|
964
|
+
assert parser.validate("\x18\x01".b)
|
|
965
|
+
refute parser.validate("1", false)
|
|
966
|
+
refute parser.validate("\x00\x00\x00\x00\x00".b, false)
|
|
967
|
+
end
|
|
968
|
+
|
|
969
|
+
def test_and_annotation
|
|
970
|
+
parser = CDDL::Parser.new <<HERE
|
|
971
|
+
test = mtype .and uint
|
|
972
|
+
mtype = 1/2/3/4/-1
|
|
973
|
+
HERE
|
|
974
|
+
pp parser.rules
|
|
975
|
+
5.times do
|
|
976
|
+
gen = parser.generate
|
|
977
|
+
assert Integer === gen
|
|
978
|
+
pp ["CAA", gen]
|
|
979
|
+
assert parser.validate(gen)
|
|
980
|
+
end
|
|
981
|
+
assert parser.validate(1)
|
|
982
|
+
refute parser.validate(-1, false)
|
|
983
|
+
refute parser.validate(0, false)
|
|
984
|
+
end
|
|
985
|
+
|
|
986
|
+
def test_within_annotation
|
|
987
|
+
parser = CDDL::Parser.new <<HERE
|
|
988
|
+
test = mtype .within uint
|
|
989
|
+
mtype = 1/2/3/4/-1
|
|
990
|
+
HERE
|
|
991
|
+
pp parser.rules
|
|
992
|
+
20.times do
|
|
993
|
+
gen = parser.generate
|
|
994
|
+
assert Integer === gen
|
|
995
|
+
pp ["CWA", gen] # should also generate some warnings
|
|
996
|
+
assert parser.validate(gen)
|
|
997
|
+
end
|
|
998
|
+
assert parser.validate(1)
|
|
999
|
+
refute parser.validate(-1, false)
|
|
1000
|
+
refute parser.validate(0, false)
|
|
1001
|
+
end
|
|
1002
|
+
|
|
905
1003
|
def test_dcaf
|
|
906
1004
|
parser1 = CDDL::Parser.new(File.read("#{TEST_DATA_DIR}/dcaf1.cddl"))
|
|
907
1005
|
# assert_equal EXPECTED_RULES, parser1.rules
|
|
@@ -1196,7 +1294,7 @@ HERE
|
|
|
1196
1294
|
# pp parser.rules
|
|
1197
1295
|
assert_equal(["abs"], parser.generate.keys)
|
|
1198
1296
|
v = {}
|
|
1199
|
-
|
|
1297
|
+
20.times do # OK, this is probabilistic...
|
|
1200
1298
|
v[parser.generate["abs"]] = true
|
|
1201
1299
|
end
|
|
1202
1300
|
assert_equal({3 => true, -3 => true}, v)
|
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.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Carsten Bormann
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-12-
|
|
11
|
+
date: 2015-12-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: cbor-diag
|