cddl 0.11.3 → 0.11.4
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 +102 -10
- data/test-data/cat-re.cddl +2 -0
- data/test-data/catb64.cddl +8 -0
- data/test-data/json1.cddl +15 -0
- data/test-data/jwt.cddl +15 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b496a36874447ba9821e185ef347fd7360ec404f7b1fc3fb33f5d2d94c33443
|
4
|
+
data.tar.gz: be328f5d7b8fe8426bb7b60b11be9d378d6f26f0e3c5598578c75efb5696663a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8ec72cbdeeb7eb1ecb2b7cd4173af652b06efe76c1ddbb0e8017248f1c9edbec499c7bb6c82099b52fa963f1ac7dd7062ed8e11b0142bcf8197c62166999fb4
|
7
|
+
data.tar.gz: 59cdd71d13a5d9232f5244a644f42f908cd26de059c20f4787ad3e1cae09454145ebff8aa16e69d1efb52bb9387e06940983543b7a3626e76e72188d3f54b13a
|
data/cddl.gemspec
CHANGED
data/lib/cddl.rb
CHANGED
@@ -747,7 +747,7 @@ module CDDL
|
|
747
747
|
end
|
748
748
|
elsif t[0] == :anno
|
749
749
|
_, conop, target, control = t
|
750
|
-
|
750
|
+
warn ["EXV0", conop, target, control].inspect if ENV["CDDL_TRACE"]
|
751
751
|
if conop == :cat || conop == :plus || conop == :det
|
752
752
|
ok1, v1, vt1 = extract_value(target)
|
753
753
|
ok2, v2, vt2 = extract_value(control)
|
@@ -980,6 +980,19 @@ module CDDL
|
|
980
980
|
}
|
981
981
|
end
|
982
982
|
|
983
|
+
def validate1a_ignore_encoding(d, where)
|
984
|
+
if String === d
|
985
|
+
validate1a(d.force_encoding(Encoding::BINARY), where) or (
|
986
|
+
text = d.force_encoding(Encoding::UTF_8).scrub {
|
987
|
+
fail "can't use bytes as text"
|
988
|
+
} rescue :NOT_A_TEXT_STRING
|
989
|
+
validate1a(text, where)
|
990
|
+
)
|
991
|
+
else
|
992
|
+
validate1a(d, where)
|
993
|
+
end
|
994
|
+
end
|
995
|
+
|
983
996
|
def validate1a(d, where)
|
984
997
|
if ann = validate1(d, where)
|
985
998
|
here = [d, where]
|
@@ -1039,7 +1052,7 @@ module CDDL
|
|
1039
1052
|
if conop == :cat || conop == :plus || conop == :det
|
1040
1053
|
ok1, v1, vt1 = extract_value(target)
|
1041
1054
|
ok2, v2, vt2 = extract_value(control)
|
1042
|
-
|
1055
|
+
warn ["ANNO0", ok1, v1, vt1, ok2, v2, vt2, d].inspect if ENV["CDDL_TRACE"]
|
1043
1056
|
if ok1 && ok2
|
1044
1057
|
v2 = Integer(v2) if vt1 == Integer
|
1045
1058
|
if conop == :det
|
@@ -1048,6 +1061,24 @@ module CDDL
|
|
1048
1061
|
end
|
1049
1062
|
# warn ["ANNO", ok1, v1, vt1, ok2, v2, vt2, d].inspect
|
1050
1063
|
[] if d == v1 + v2 # XXX Focus ArgumentError
|
1064
|
+
elsif conop == :cat && String === d
|
1065
|
+
warn ["CAT-L", ok1, v1, vt1, ok2, v2, vt2, d].inspect if ENV["CDDL_TRACE"]
|
1066
|
+
if ok1 && vt1 == String
|
1067
|
+
# d and lhs (v1) need to agree in encoding
|
1068
|
+
if d.encoding == v1.encoding
|
1069
|
+
if d[0...v1.length] == v1
|
1070
|
+
d2 = d[v1.length..-1]
|
1071
|
+
warn ["CAT-L1", d2, d2.encoding, control].inspect if ENV["CDDL_TRACE"]
|
1072
|
+
validate1a_ignore_encoding(d2, control)
|
1073
|
+
end
|
1074
|
+
end
|
1075
|
+
elsif ok2 && vt2 == String
|
1076
|
+
warn ["CAT-R", ok1, v1, vt1, ok2, v2, vt2, d].inspect if ENV["CDDL_TRACE"]
|
1077
|
+
if d[-v2.length..-1] == v2
|
1078
|
+
d1 = d[0...-v2.length]
|
1079
|
+
validate1a(d1, control)
|
1080
|
+
end
|
1081
|
+
end
|
1051
1082
|
elsif conop == :plus && Integer === d
|
1052
1083
|
if ok1 && vt1 == Integer
|
1053
1084
|
validate1a(d - Integer(v1), control)
|
@@ -1163,14 +1194,75 @@ module CDDL
|
|
1163
1194
|
end
|
1164
1195
|
)
|
1165
1196
|
when :join
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1197
|
+
t = control
|
1198
|
+
v = if t[0] == :array
|
1199
|
+
t[1..-1].map { |el|
|
1200
|
+
if el[0..2] == [:member, 1, 1]
|
1201
|
+
ok, v, vt = extract_value(el[4])
|
1202
|
+
if ok
|
1203
|
+
[true, v, vt]
|
1204
|
+
else
|
1205
|
+
[false, el[4]]
|
1206
|
+
end
|
1207
|
+
end
|
1208
|
+
}
|
1209
|
+
end
|
1210
|
+
warn "@@@JOIN@@@ #{v.inspect}" if ENV["CDDL_TRACE"]
|
1211
|
+
ok = true
|
1212
|
+
if v
|
1213
|
+
ix = 0
|
1214
|
+
rest = d.dup
|
1215
|
+
while ix < v.length
|
1216
|
+
if left = v[ix]
|
1217
|
+
if left[0] # match constant value first
|
1218
|
+
fail "Not a string for #{left.inspect} in #{where}" unless String == left[2]
|
1219
|
+
want = left[1]
|
1220
|
+
have = rest[0...left[1].length]
|
1221
|
+
if want == have
|
1222
|
+
rest[0...left[1].length] = ''
|
1223
|
+
ix += 1
|
1224
|
+
next
|
1225
|
+
else
|
1226
|
+
fail ".join: want #{want.inspect}, have #{have.inspect}"
|
1227
|
+
end
|
1228
|
+
else
|
1229
|
+
ix += 1
|
1230
|
+
if ix == v.length # match remaining
|
1231
|
+
warn "@@@JOIN ok in #{ok.inspect} rest #{rest.inspect}" if ENV["CDDL_TRACE"]
|
1232
|
+
ok &&= validate1(rest, left[1])
|
1233
|
+
warn "@@@JOIN ok out #{ok.inspect}" if ENV["CDDL_TRACE"]
|
1234
|
+
# more diag
|
1235
|
+
rest = ''
|
1236
|
+
next
|
1237
|
+
else
|
1238
|
+
if mid = v[ix]
|
1239
|
+
if mid[0] # have constant value to split over
|
1240
|
+
fail "Not a string for #{mid} in #{where}" unless String == mid[2]
|
1241
|
+
rest1, rest2 = rest.split(mid[1], 2)
|
1242
|
+
if rest2
|
1243
|
+
warn "@@@JOIN ok in #{ok.inspect} rest1 #{rest1.inspect}" if ENV["CDDL_TRACE"]
|
1244
|
+
ok &&= validate1(rest1, left[1])
|
1245
|
+
warn "@@@JOIN ok out #{ok.inspect}" if ENV["CDDL_TRACE"]
|
1246
|
+
rest = rest2
|
1247
|
+
ix += 1
|
1248
|
+
next
|
1249
|
+
else
|
1250
|
+
fail "Can't find #{mid[1].inspect} in #{rest.inspect}"
|
1251
|
+
end
|
1252
|
+
else
|
1253
|
+
fail "Cannot validate consecutive non-constant members of .join in #{where}"
|
1254
|
+
end
|
1255
|
+
else
|
1256
|
+
fail "Cannot handle .join over #{t[ix+1]} in #{where}"
|
1257
|
+
end
|
1258
|
+
end
|
1259
|
+
end
|
1260
|
+
else
|
1261
|
+
fail "Cannot handle .join over #{t[ix+1]} in #{where}"
|
1262
|
+
end
|
1263
|
+
end
|
1264
|
+
fail "Can't match #{rest.inspect} for .join in #{where}" if rest != ''
|
1265
|
+
ann if ok
|
1174
1266
|
else
|
1175
1267
|
fail "Don't know yet how to validate against #{where}"
|
1176
1268
|
end
|
data/test-data/cat-re.cddl
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
; JWT-JWS = text .join ([
|
2
|
+
; b64u<jwt-headers>, ".",
|
3
|
+
; b64u<jwt-payload>, ".",
|
4
|
+
; b64u<jwt-signature>])
|
5
|
+
; ; a = jwt-headers
|
6
|
+
; ; a = b64u<"abc"> ; fails
|
7
|
+
; ; a = b64u<'abc'> ; succeeds
|
8
|
+
; b64u<B> = text .b64u B
|
9
|
+
jwt-headers = '' .cat jwt-headers1
|
10
|
+
jwt-headers1 = text .json jwt-headermap
|
11
|
+
jwt-headermap = { * text => any } ; simplified
|
12
|
+
jwt-payload = bytes
|
13
|
+
jwt-signature = bytes
|
14
|
+
|
15
|
+
;;gp 10
|
data/test-data/jwt.cddl
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
JWT-JWS = text .join ([
|
2
|
+
b64u<jwt-headers>, ".",
|
3
|
+
b64u<jwt-payload>, ".",
|
4
|
+
b64u<jwt-signature>])
|
5
|
+
; a = jwt-headers
|
6
|
+
; a = b64u<"abc"> ; fails
|
7
|
+
; a = b64u<'abc'> ; succeeds
|
8
|
+
b64u<B> = text .b64u B
|
9
|
+
jwt-headers = '' .cat jwt-headers1
|
10
|
+
jwt-headers1 = text .json jwt-headermap
|
11
|
+
jwt-headermap = { * text => any } ; simplified
|
12
|
+
jwt-payload = bytes
|
13
|
+
jwt-signature = bytes
|
14
|
+
|
15
|
+
;;gp 10
|
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.11.
|
4
|
+
version: 0.11.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: 2024-04-
|
11
|
+
date: 2024-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cbor-diag
|
@@ -173,6 +173,7 @@ files:
|
|
173
173
|
- test-data/bpv7a.cddl
|
174
174
|
- test-data/bpv7b.cddl
|
175
175
|
- test-data/cat-re.cddl
|
176
|
+
- test-data/catb64.cddl
|
176
177
|
- test-data/cdni-ct.cddl
|
177
178
|
- test-data/complex-occ.cddl
|
178
179
|
- test-data/coral.cddl
|
@@ -217,8 +218,10 @@ files:
|
|
217
218
|
- test-data/joini.cddl
|
218
219
|
- test-data/joinx.cddl
|
219
220
|
- test-data/json.cddl
|
221
|
+
- test-data/json1.cddl
|
220
222
|
- test-data/json2.cddl
|
221
223
|
- test-data/jsoniodef.cddl
|
224
|
+
- test-data/jwt.cddl
|
222
225
|
- test-data/kevin5.cddl
|
223
226
|
- test-data/lint1.cddl
|
224
227
|
- test-data/map-group.cddl
|