cddl 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cddl.gemspec +1 -1
- data/lib/cddl.rb +12 -5
- data/test-data/cose.cddl +68 -0
- data/test/test-cddl.rb +22 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8803ef067ea0ea2959c233dadcdb2c6b9efc951c
|
4
|
+
data.tar.gz: 59b76d0a3da17193115e4d023414d486b07b80b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2c84dc9a1eed0643f1bfe619fbc922290f4815d3f77e04ca5e076421b717c45eb0ccd48b00636d71a602d2324aacaaf8be2256b59bcb6f6a9712dfe40f3bc21
|
7
|
+
data.tar.gz: bccdb7d885651ded32f13eb95aaffaed70a2c2ad4490465f4d866703d18c49c843ce84820067834287c8adb1aeddcf658719f41ee49dd5a360d749d89d0f9b89
|
data/cddl.gemspec
CHANGED
data/lib/cddl.rb
CHANGED
@@ -101,15 +101,22 @@ module CDDL
|
|
101
101
|
|
102
102
|
# Generate some simple #define lines from the value-only rules
|
103
103
|
def defines(prefix)
|
104
|
+
prefix ||= "CDDL"
|
105
|
+
if prefix =~ /%\d*\$?s/
|
106
|
+
format = prefix
|
107
|
+
format += "\n" unless format[-1] == "\n"
|
108
|
+
else
|
109
|
+
format = "#define #{prefix}_%s %s\n"
|
110
|
+
end
|
104
111
|
s = {} # keys form crude set of defines
|
112
|
+
add = proc { |*a| s[format % a] = true }
|
105
113
|
r = rules
|
106
|
-
prefix ||= "CDDL"
|
107
114
|
ast.each :rule do |rule|
|
108
115
|
if rulename = rule.typename
|
109
116
|
t = rule.type.children(:type1)
|
110
117
|
if t.size == 1
|
111
118
|
if (t2 = t.first.children(:type2)) && t2.size == 1 && (v = t2.first.value)
|
112
|
-
|
119
|
+
add.(cname(rulename), v.to_s)
|
113
120
|
end
|
114
121
|
end
|
115
122
|
end
|
@@ -122,7 +129,7 @@ module CDDL
|
|
122
129
|
subtree[1..-1].each do |x|
|
123
130
|
if memname = x.cbor_annotations
|
124
131
|
memname = "#{enumname}_#{cname(memname.first)}"
|
125
|
-
|
132
|
+
add.(memname, x[1].to_s)
|
126
133
|
end
|
127
134
|
end
|
128
135
|
end
|
@@ -138,8 +145,8 @@ module CDDL
|
|
138
145
|
memname = memname.first # use value annotation otherwise
|
139
146
|
end
|
140
147
|
if memname
|
141
|
-
memname = "#{arrayname}_#{cname(memname)}"
|
142
|
-
|
148
|
+
memname = "#{arrayname}_#{cname(memname)}_index"
|
149
|
+
add.(memname, i.to_s)
|
143
150
|
end
|
144
151
|
end
|
145
152
|
if x[0] == :member && (x[1] != 1 || x[2] != 1)
|
data/test-data/cose.cddl
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
COSE_MSG = [ 1, COSE_Sign ] / [2, COSE_encrypt] / [3, COSE_mac]
|
2
|
+
|
3
|
+
|
4
|
+
COSE_Sign = (
|
5
|
+
headers,
|
6
|
+
payload : opt<bstr>,
|
7
|
+
signatures: ([+[COSE_signature]] / [COSE_signature])
|
8
|
+
)
|
9
|
+
|
10
|
+
COSE_SignMessage = #6.999([ COSE_Sign ])
|
11
|
+
|
12
|
+
keys = int / tstr
|
13
|
+
header_map = {+ keys => any}
|
14
|
+
|
15
|
+
opt<t> = t / nil
|
16
|
+
|
17
|
+
headers = (
|
18
|
+
protected: opt<bstr>,
|
19
|
+
unprotected: opt<header_map>
|
20
|
+
)
|
21
|
+
|
22
|
+
COSE_signature = (
|
23
|
+
headers,
|
24
|
+
signaturne : bstr
|
25
|
+
)
|
26
|
+
|
27
|
+
Sig_structure = [
|
28
|
+
headers,
|
29
|
+
payload : bstr
|
30
|
+
]
|
31
|
+
|
32
|
+
COSE_encrypt = (
|
33
|
+
headers,
|
34
|
+
iv : opt<bstr>,
|
35
|
+
aad : opt<bstr>,
|
36
|
+
ciphertext : opt<bstr>,
|
37
|
+
recipients : ([+COSE_encrypt_a] / [COSE_encrypt] / nil)
|
38
|
+
)
|
39
|
+
|
40
|
+
COSE_encrypt_a = [COSE_encrypt]
|
41
|
+
|
42
|
+
Enc_structure = [
|
43
|
+
protected : opt<bstr>,
|
44
|
+
aad : opt<bstr>
|
45
|
+
]
|
46
|
+
|
47
|
+
COSE_mac = (
|
48
|
+
headers,
|
49
|
+
payload : bstr,
|
50
|
+
tag : bstr,
|
51
|
+
recipients : ([+COSE_encrypt_a] / [COSE_encrypt] / nil)
|
52
|
+
)
|
53
|
+
|
54
|
+
MAC_structure = [
|
55
|
+
protected : opt<bstr>
|
56
|
+
payload : bstr
|
57
|
+
]
|
58
|
+
|
59
|
+
COSE_Key = {
|
60
|
+
"kty" : tstr,
|
61
|
+
? "use" : tstr,
|
62
|
+
? "key_ops" : [+tstr],
|
63
|
+
? "alg" : tstr,
|
64
|
+
? "kid" : tstr,
|
65
|
+
* keys => values
|
66
|
+
}
|
67
|
+
|
68
|
+
COSE_KeySet = [+COSE_Key]
|
data/test/test-cddl.rb
CHANGED
@@ -1191,7 +1191,7 @@ HERE
|
|
1191
1191
|
p parser.rules
|
1192
1192
|
10.times {
|
1193
1193
|
g = parser.generate
|
1194
|
-
pp ["recurse-group-test2", g]
|
1194
|
+
# pp ["recurse-group-test2", g]
|
1195
1195
|
assert parser.validate(g)
|
1196
1196
|
refute parser.validate(g.merge(baz: 3), false)
|
1197
1197
|
}
|
@@ -1564,6 +1564,27 @@ HERE
|
|
1564
1564
|
assert_equal expected, d
|
1565
1565
|
end
|
1566
1566
|
|
1567
|
+
def test_extractor_type1_format_string
|
1568
|
+
parser = CDDL::Parser.new <<HERE
|
1569
|
+
BAR = a/b/c
|
1570
|
+
a = 1
|
1571
|
+
b = 2
|
1572
|
+
c = 3
|
1573
|
+
d = 4
|
1574
|
+
HERE
|
1575
|
+
expected = <<HERE
|
1576
|
+
C_a = 1
|
1577
|
+
C_b = 2
|
1578
|
+
C_c = 3
|
1579
|
+
C_d = 4
|
1580
|
+
C_BAR_a = 1
|
1581
|
+
C_BAR_b = 2
|
1582
|
+
C_BAR_c = 3
|
1583
|
+
HERE
|
1584
|
+
d = parser.defines("C_%s = %s")
|
1585
|
+
assert_equal expected, d
|
1586
|
+
end
|
1587
|
+
|
1567
1588
|
def test_extractor_enum
|
1568
1589
|
parser = CDDL::Parser.new <<HERE
|
1569
1590
|
|
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.7.
|
4
|
+
version: 0.7.2
|
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-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cbor-diag
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- test-data/b.cddl
|
101
101
|
- test-data/basic_syntax_example.cddl
|
102
102
|
- test-data/cdni-ct.cddl
|
103
|
+
- test-data/cose.cddl
|
103
104
|
- test-data/dcaf.cddl
|
104
105
|
- test-data/dcaf1.cddl
|
105
106
|
- test-data/extractor-demo.cddl
|