cddl 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/cddl +3 -0
- data/cddl.gemspec +1 -1
- data/data/prelude.cddl +2 -1
- data/lib/cbor-pp.rb +11 -1
- data/lib/cddl.rb +17 -0
- data/test-data/grasp-01.cddl +90 -0
- data/test/test-cddl.rb +45 -14
- 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: 57c85df19d5a0b7d9070f233f0d4a59a3cee1bb2
|
4
|
+
data.tar.gz: ac391af699e243e95ae1fce85de5fdf9c863a24d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 121cbda92cc8112171d3b7395373fe09e502786a90887e2b54dd2f7639f8082a5197b5f64d6b8fa8c157555c46e476e7a81f463fd33b2f5f085cb5b5b74b0908
|
7
|
+
data.tar.gz: 0ed8f5e200aabf211c5489cd66487bf22e5bcde1d06894795cb36341d4e848d9f479e77cbaa30d6e81d6fd28d66b9fe9cec724b460ae9fd357d3dd981b4995ee
|
data/bin/cddl
CHANGED
data/cddl.gemspec
CHANGED
data/data/prelude.cddl
CHANGED
@@ -18,6 +18,7 @@ biguint = #6.2(bstr)
|
|
18
18
|
bignint = #6.3(bstr)
|
19
19
|
bigint = biguint / bignint
|
20
20
|
integer = int / bigint
|
21
|
+
unsigned = uint / biguint
|
21
22
|
decfrac = #6.4([e10: int, m: integer])
|
22
23
|
bigfloat = #6.5([e2: int, m: integer])
|
23
24
|
eb64url = #6.21(any)
|
@@ -45,4 +46,4 @@ nil = #7.22
|
|
45
46
|
null = nil
|
46
47
|
undefined = #7.23
|
47
48
|
|
48
|
-
used_in_cddl_prelude = any / bytes / tdate / time / number / biguint / bignint / bigint / integer / decfrac / bigfloat / eb64url / eb64legacy / eb16 / encoded-cbor / uri / b64url / b64legacy / regexp / mime-message / cbor-any / float16 / float32 / float64 / float16-32 / float32-64 / float / false / true / bool / null / undefined / uint / nint / int / text
|
49
|
+
used_in_cddl_prelude = any / bytes / tdate / time / number / biguint / bignint / bigint / integer / unsigned / decfrac / bigfloat / eb64url / eb64legacy / eb16 / encoded-cbor / uri / b64url / b64legacy / regexp / mime-message / cbor-any / float16 / float32 / float64 / float16-32 / float32-64 / float / false / true / bool / null / undefined / uint / nint / int / text
|
data/lib/cbor-pp.rb
CHANGED
@@ -131,6 +131,12 @@ class Class
|
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
|
+
class String
|
135
|
+
def cbor_clone
|
136
|
+
frozen? ? dup : self
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
134
140
|
class Array # :nodoc:
|
135
141
|
def cbor_pp(q) # :nodoc:
|
136
142
|
s = "#{cbor_annotation_format}["
|
@@ -161,7 +167,11 @@ class Hash # :nodoc:
|
|
161
167
|
}
|
162
168
|
end
|
163
169
|
def cbor_clone
|
164
|
-
to_a.cbor_clone.to_h
|
170
|
+
# to_a.cbor_clone.to_h # this breaks for unknown reasons
|
171
|
+
h = {}
|
172
|
+
each {|k, v| h[k.cbor_clone] = v.cbor_clone}
|
173
|
+
each {|k, v| fail [h, k, h[k], v].inspect unless h[k] == v}
|
174
|
+
h
|
165
175
|
end
|
166
176
|
end
|
167
177
|
|
data/lib/cddl.rb
CHANGED
@@ -70,6 +70,23 @@ module CDDL
|
|
70
70
|
}]
|
71
71
|
end
|
72
72
|
|
73
|
+
# Generate some simple #define lines from the value-only rules
|
74
|
+
def defines(prefix)
|
75
|
+
s = ''
|
76
|
+
prefix ||= "CDDL"
|
77
|
+
ast.each :rule do |rule|
|
78
|
+
if rulename = rule.typename
|
79
|
+
t = rule.type.children(:type1)
|
80
|
+
if t.size == 1
|
81
|
+
if (t2 = t.first.children(:type2)) && t2.size == 1 && (v = t2.first.value)
|
82
|
+
s += "#define #{prefix}_#{rulename.to_s.gsub(/-/, "_")} " << v.to_s << "\n"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
s
|
88
|
+
end
|
89
|
+
|
73
90
|
def rules
|
74
91
|
@rules = {}
|
75
92
|
@generics = {}
|
@@ -0,0 +1,90 @@
|
|
1
|
+
grasp-message = message
|
2
|
+
|
3
|
+
session-id = 0..16777215
|
4
|
+
; that is up to 24 bits
|
5
|
+
|
6
|
+
message /= discovery-message
|
7
|
+
discovery-message = [M_DISCOVERY, session-id, objective]
|
8
|
+
|
9
|
+
message /= response-message
|
10
|
+
response-message = [M_RESPONSE, session-id,
|
11
|
+
(+locator-option // divert-option // objective)]
|
12
|
+
|
13
|
+
message /= request-message
|
14
|
+
request-message = [M_REQUEST, session-id, objective]
|
15
|
+
|
16
|
+
message /= negotiation-message
|
17
|
+
negotiation-message = [M_NEGOTIATE, session-id, objective]
|
18
|
+
|
19
|
+
message /= end-message
|
20
|
+
end-message = [M_END, session-id, (accept-option / decline-option)]
|
21
|
+
|
22
|
+
message /= wait-message
|
23
|
+
wait-message = [M_WAIT, session-id, waiting-time-option]
|
24
|
+
|
25
|
+
divert-option = [O_DIVERT, +locator-option]
|
26
|
+
|
27
|
+
accept-option = [O_ACCEPT]
|
28
|
+
|
29
|
+
decline-option = [O_DECLINE]
|
30
|
+
|
31
|
+
waiting-time-option = [O_WAITING, option-waiting-time]
|
32
|
+
option-waiting-time = 0..4294967295 ; in milliseconds
|
33
|
+
|
34
|
+
option-device-id = [O_DEVICE_ID, bytes]
|
35
|
+
|
36
|
+
locator-option /= ipv4-locator-option
|
37
|
+
ipv4-locator-option = bytes .size 4
|
38
|
+
; this is simpler than [O_IPv4_LOCATOR, bytes .size 4]
|
39
|
+
|
40
|
+
locator-option /= ipv6-locator-option
|
41
|
+
ipv6-locator-option = bytes .size 16
|
42
|
+
|
43
|
+
locator-option /= fqdn-locator-option
|
44
|
+
fqdn-locator-option = [O_FQDN_LOCATOR, text]
|
45
|
+
|
46
|
+
locator-option /= url-locator-option
|
47
|
+
url-locator-option = [O_URL_LOCATOR, text]
|
48
|
+
|
49
|
+
objective-flags = uint .bits objective-flag
|
50
|
+
|
51
|
+
objective-flag = &(
|
52
|
+
D: 0
|
53
|
+
N: 1
|
54
|
+
S: 2
|
55
|
+
)
|
56
|
+
|
57
|
+
; D means valid for discovery only
|
58
|
+
; N means valid for discovery and negotiation
|
59
|
+
; S means valid for discovery and synchronization
|
60
|
+
|
61
|
+
objective /= generic-obj
|
62
|
+
generic-obj = [objective-name, objective-flags, loop-count, ?any]
|
63
|
+
|
64
|
+
objective /= vendor-obj
|
65
|
+
vendor-obj = [{"PEN":pen}, objective-name, objective-flags,
|
66
|
+
loop-count, ?any]
|
67
|
+
|
68
|
+
; A PEN is used to distinguish vendor-specific options.
|
69
|
+
|
70
|
+
pen = 0..4294967295
|
71
|
+
objective-name = tstr
|
72
|
+
loop-count = 0..255
|
73
|
+
|
74
|
+
; Constants
|
75
|
+
|
76
|
+
M_DISCOVERY = 1
|
77
|
+
|
78
|
+
M_RESPONSE = 2
|
79
|
+
M_REQUEST = 3
|
80
|
+
M_NEGOTIATE = 4
|
81
|
+
M_END = 5
|
82
|
+
M_WAIT = 6
|
83
|
+
|
84
|
+
O_DIVERT = 100
|
85
|
+
O_ACCEPT = 101
|
86
|
+
O_DECLINE = 102
|
87
|
+
O_WAITING = 103
|
88
|
+
O_DEVICE_ID = 104
|
89
|
+
O_FQDN_LOCATOR = 105
|
90
|
+
O_URL_LOCATOR = 106
|
data/test/test-cddl.rb
CHANGED
@@ -5,6 +5,7 @@ require 'cbor-pretty.rb'
|
|
5
5
|
require 'cbor-diagnostic.rb'
|
6
6
|
|
7
7
|
require_relative '../lib/cddl'
|
8
|
+
require_relative '../lib/cbor-pp'
|
8
9
|
|
9
10
|
|
10
11
|
class TestABNF < Test::Unit::TestCase
|
@@ -100,6 +101,37 @@ HERE
|
|
100
101
|
refute parser1.validate(g, false)
|
101
102
|
end
|
102
103
|
|
104
|
+
def test_aaaaaaa_cbor_clone_hash
|
105
|
+
a = "x".cbor_clone
|
106
|
+
b = {a => 1}
|
107
|
+
assert_equal 1, b[a]
|
108
|
+
assert_equal 1, b["x".cbor_clone]
|
109
|
+
assert_equal 1, b["x"]
|
110
|
+
assert_equal 1, b.fetch("x".cbor_clone, :not_found)
|
111
|
+
assert_equal 1, b.fetch("x", :not_found)
|
112
|
+
b = {"x" => 1}.cbor_clone
|
113
|
+
assert_equal 1, b["x"]
|
114
|
+
assert_equal 1, b["x".cbor_clone]
|
115
|
+
assert_equal 1, b[a]
|
116
|
+
assert_equal 1, b.fetch("x".cbor_clone, :not_found)
|
117
|
+
assert_equal 1, b.fetch("x", :not_found)
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_aaaaa_validate_clone
|
121
|
+
parser1 = CDDL::Parser.new(File.read("test-data/7071-concise.cddl"))
|
122
|
+
g = parser1.generate
|
123
|
+
pp g
|
124
|
+
g = g.cbor_clone
|
125
|
+
|
126
|
+
assert parser1.validate(g)
|
127
|
+
old = g["application"]
|
128
|
+
g["application"] = 4711.cbor_clone
|
129
|
+
refute parser1.validate(g, false)
|
130
|
+
g["application"] = old
|
131
|
+
g["reputons"] << 5712.cbor_clone
|
132
|
+
refute parser1.validate(g, false)
|
133
|
+
end
|
134
|
+
|
103
135
|
def test_validate_1
|
104
136
|
parser = CDDL::Parser.new <<HERE
|
105
137
|
test = 1
|
@@ -1030,7 +1062,7 @@ HERE
|
|
1030
1062
|
}
|
1031
1063
|
end
|
1032
1064
|
|
1033
|
-
|
1065
|
+
|
1034
1066
|
def test_group_recursion2
|
1035
1067
|
parser = CDDL::Parser.new <<HERE
|
1036
1068
|
b = {1: 2, a}
|
@@ -1049,7 +1081,7 @@ HERE
|
|
1049
1081
|
}
|
1050
1082
|
end
|
1051
1083
|
|
1052
|
-
|
1084
|
+
|
1053
1085
|
def test_group_recursion_fail1
|
1054
1086
|
parser = CDDL::Parser.new <<HERE
|
1055
1087
|
b = {a}
|
@@ -1089,7 +1121,7 @@ HERE
|
|
1089
1121
|
assert parser.validate({})
|
1090
1122
|
end
|
1091
1123
|
|
1092
|
-
|
1124
|
+
|
1093
1125
|
def test_empty_group_augmented
|
1094
1126
|
parser = CDDL::Parser.new <<HERE
|
1095
1127
|
a = {b}
|
@@ -1105,7 +1137,7 @@ HERE
|
|
1105
1137
|
assert_equal({}, parser.generate)
|
1106
1138
|
assert parser.validate({})
|
1107
1139
|
end
|
1108
|
-
|
1140
|
+
|
1109
1141
|
def test_simple_group_augmented
|
1110
1142
|
parser = CDDL::Parser.new <<HERE
|
1111
1143
|
a = {b}
|
@@ -1128,7 +1160,7 @@ HERE
|
|
1128
1160
|
assert parser.validate({"abs" => 5})
|
1129
1161
|
assert parser.validate({"abs" => -3})
|
1130
1162
|
end
|
1131
|
-
|
1163
|
+
|
1132
1164
|
def test_simple_group_augmented_uninitialized
|
1133
1165
|
parser = CDDL::Parser.new <<HERE
|
1134
1166
|
a = {b}
|
@@ -1150,7 +1182,7 @@ HERE
|
|
1150
1182
|
assert parser.validate({"abs" => -3})
|
1151
1183
|
end
|
1152
1184
|
|
1153
|
-
|
1185
|
+
|
1154
1186
|
def test_simple_type_augmented
|
1155
1187
|
parser = CDDL::Parser.new <<HERE
|
1156
1188
|
a = {b}
|
@@ -1172,7 +1204,7 @@ HERE
|
|
1172
1204
|
assert parser.validate({"abs" => -3})
|
1173
1205
|
end
|
1174
1206
|
|
1175
|
-
|
1207
|
+
|
1176
1208
|
def test_empty_type_socket
|
1177
1209
|
parser = CDDL::Parser.new <<HERE
|
1178
1210
|
a = {b}
|
@@ -1185,7 +1217,7 @@ HERE
|
|
1185
1217
|
assert_raise { parser.generate }
|
1186
1218
|
end
|
1187
1219
|
|
1188
|
-
|
1220
|
+
|
1189
1221
|
def test_empty_group_socket
|
1190
1222
|
parser = CDDL::Parser.new <<HERE
|
1191
1223
|
a = {$$t2}
|
@@ -1197,7 +1229,7 @@ HERE
|
|
1197
1229
|
assert_raise { parser.generate }
|
1198
1230
|
end
|
1199
1231
|
|
1200
|
-
|
1232
|
+
|
1201
1233
|
def test_validate_empty_type_socket
|
1202
1234
|
parser = CDDL::Parser.new <<HERE
|
1203
1235
|
a = {b}
|
@@ -1211,7 +1243,7 @@ HERE
|
|
1211
1243
|
assert parser.validate({"abs" => 17})
|
1212
1244
|
end
|
1213
1245
|
|
1214
|
-
|
1246
|
+
|
1215
1247
|
def test_validate_empty_group_socket
|
1216
1248
|
parser = CDDL::Parser.new <<HERE
|
1217
1249
|
a = {$$t2 // a: 1}
|
@@ -1224,7 +1256,7 @@ HERE
|
|
1224
1256
|
assert parser.validate({"a" => 1})
|
1225
1257
|
end
|
1226
1258
|
|
1227
|
-
|
1259
|
+
|
1228
1260
|
def test_validate_empty_group_socket_in_star
|
1229
1261
|
parser = CDDL::Parser.new <<HERE
|
1230
1262
|
a = {* $$t2}
|
@@ -1265,7 +1297,7 @@ HERE
|
|
1265
1297
|
assert parser.validate({"seq" => 1, "ack" => 2})
|
1266
1298
|
end
|
1267
1299
|
|
1268
|
-
|
1300
|
+
|
1269
1301
|
def test_simple_type_augmented_uninitialized
|
1270
1302
|
parser = CDDL::Parser.new <<HERE
|
1271
1303
|
a = {b}
|
@@ -1376,8 +1408,7 @@ HERE
|
|
1376
1408
|
# end
|
1377
1409
|
end
|
1378
1410
|
|
1379
|
-
|
1380
|
-
def test_aaaaa_false_map_values
|
1411
|
+
def test_false_map_values
|
1381
1412
|
parser = CDDL::Parser.new <<HERE
|
1382
1413
|
a = {a: nil}
|
1383
1414
|
HERE
|
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.6.
|
4
|
+
version: 0.6.4
|
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-
|
11
|
+
date: 2015-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cbor-diag
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- test-data/cdni-ct.cddl
|
103
103
|
- test-data/dcaf.cddl
|
104
104
|
- test-data/dcaf1.cddl
|
105
|
+
- test-data/grasp-01.cddl
|
105
106
|
- test-data/grasp-v1.cddl
|
106
107
|
- test-data/grasp-v2X.cddl
|
107
108
|
- test-data/ifmap-base-2.0v17.cddl
|