cddl 0.8.9 → 0.8.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2864bab5890244b179dd65b3508fa3138f9e5a1d7fbb8a3843090c60212a66bf
4
- data.tar.gz: 5e501ebd3d42e3236a03375586c64a03d3f6db390fa5827cf91f100d6d8a1e4c
3
+ metadata.gz: 3c83003981d07eae336683b02bebaa0340f56941724ed6f91d89c6b8baf8f234
4
+ data.tar.gz: bf5e14489fd50c0b14bd27a99f11c3a35c046ed8113764094d8fc6a7ef4ff0d8
5
5
  SHA512:
6
- metadata.gz: b973bc02bd23664027c8457f18e123e54f53da345381ec5099fc3b5c1f31d9c540ef765c217f237b43e426ab5ff8514f627230c3674f7fff39331f2f541aee54
7
- data.tar.gz: ecb4f59bb8bd4c01a947557229c707f8ff47ebb1b7498cfafb0c5a9ced7b46fd7653186bee6d67585758687dcb0dea7e05d0cc1c5e84399b111fa4484e01a9de
6
+ metadata.gz: 74f3d9b8cb2f1c188aff29fe9e8dcc3496cb978063e67e7a84932cbe7045163529586547836747237f8f5451b2ffaeaf550165df5aea3003ee9a31c882408488
7
+ data.tar.gz: b021259524e95100b668a5b335adf85c714f73fbf4b22fd2cd7a84dcc9ea35c227401339c8a40a06f8e46e77d77fa19d2d0240fef60f89703eb66cff0f31ebf1
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'cddl'
3
- s.version = '0.8.9'
3
+ s.version = '0.8.10'
4
4
  s.summary = "CDDL generator and validator."
5
5
  s.description = %{A parser, generator, and validator for CDDL}
6
6
  s.add_dependency('cbor-diag')
@@ -527,7 +527,7 @@ module CDDL
527
527
  end
528
528
  end
529
529
 
530
- VALUE_TYPE = {text: String, int: Integer, float: Float}
530
+ VALUE_TYPE = {text: String, bytes: String, int: Integer, float: Float}
531
531
  SIMPLE_VALUE = {
532
532
  [:prim, 7, 20] => [true, false, :bool],
533
533
  [:prim, 7, 21] => [true, true, :bool],
@@ -556,6 +556,7 @@ module CDDL
556
556
  if warn
557
557
  warn "CDDL validation failure (#{result.inspect} for #{d.inspect}):"
558
558
  PP::pp(validate_diag, STDERR)
559
+ puts(validate_diag.cbor_diagnostic)
559
560
  end
560
561
  end
561
562
  result
@@ -745,9 +746,12 @@ module CDDL
745
746
  idx, ann = validate_forward(d, 0, where)
746
747
  ann if validate_result(idx == d.size) { "#{validate_diag.inspect} -- cannot complete (#{idx}, #{d.size}) array #{d} for #{where}" }
747
748
  end
748
- when :text, :int, :float, :bytes
749
+ when :int, :float
749
750
  _, v = extract_value(where)
750
751
  [] if d == v
752
+ when :text, :bytes
753
+ _, v = extract_value(where)
754
+ [] if d == v && ((d.encoding == Encoding::BINARY) == (v.encoding == Encoding::BINARY))
751
755
  when :range
752
756
  [] if where[2] === d && where[1].include?(d)
753
757
  when :anno
@@ -841,6 +845,14 @@ module CDDL
841
845
  when 3
842
846
  String === d && d.encoding != Encoding::BINARY # cheat
843
847
  when 6
848
+ if Integer === d
849
+ t = 2 # assuming only 2/3 match an Integer
850
+ if d < 0
851
+ d = ~d
852
+ t = 3
853
+ end
854
+ d = CBOR::Tagged.new(t, d == 0 ? "".b : d.digits(256).reverse!.pack("C*"))
855
+ end
844
856
  CBOR::Tagged === d && d.tag == where[2] && validate1a(d.data, where[3])
845
857
  when 7
846
858
  t, v = extract_value(where)
@@ -963,7 +975,7 @@ module CDDL
963
975
  when ""
964
976
  parts[1].b
965
977
  when "h"
966
- parts[1].gsub(/\s/, "").chars.each_slice(2).map{ |x| Integer(x.join, 16).chr("BINARY") }.join
978
+ parts[1].gsub(/\s/, "").chars.each_slice(2).map{ |x| Integer(x.join, 16).chr("BINARY") }.join.b
967
979
  when "b64"
968
980
  Base64.urlsafe_decode64(parts[1])
969
981
  else
@@ -0,0 +1,14 @@
1
+ coap-problem-details = {
2
+ type => uint,
3
+ ? title => text,
4
+ ? response-code => bstr .size 1,
5
+ ? detail => text,
6
+ ? instance => uri,
7
+ * $$coap-problem-details-extension,
8
+ }
9
+
10
+ type = 0
11
+ title = 1
12
+ response-code = 2
13
+ detail = 3
14
+ instance = 4
@@ -0,0 +1 @@
1
+ abignum = unsigned
@@ -0,0 +1,10 @@
1
+ coral = [+ s-exp]
2
+ s-exp = ((text, value, ?coral) // directive)
3
+ value = ctext / cbytes / cint / cfloat / cboolean / cdatetime / null / {"_link": tstr} / {"_form": tstr}
4
+ ctext = text / {"_text": text}
5
+ cint = {"_int": int}
6
+ cfloat = float / {"_float": float}
7
+ cboolean = bool / {"_bool": bool}
8
+ cdatetime = {"_datetime": text}
9
+ cbytes = {"_bytes": text} ; base64url no padding
10
+ directive = (("_using", {* text => text}) // ("_base", text))
@@ -0,0 +1,5 @@
1
+ document = {*element}
2
+ element = (relation => value / [2*value])
3
+
4
+ relation = text
5
+ value = text
@@ -0,0 +1,7 @@
1
+ document = {*element}
2
+ element = (text => value / [2*value])
3
+ value = text / float / bool / tagged
4
+ tagged = {"_int":int,*element} / {"_float":float,*element} / {"_text":text,*element} / {"_bytes":bytes,*element} / {"_datetime":text,*element} / {"_bool":bool,*element} / {"_link":ciri,*element} / {"_form":ciri,*element}
5
+ ciri = text ; full IRI given
6
+ / [text] ; suffix for default prefix
7
+ / [text, text] ; prefix, suffix for that prefix
@@ -0,0 +1,7 @@
1
+ document = {? ("_using" => {* text => text}), *element}
2
+ element = (text => value / [2*value])
3
+ value = text / float / bool / tagged / {*element}
4
+ tagged = {"_int": int, *element} / {"_float": float, *element} / {"_text": text, *element} / {"_bytes": bytes, *element} / {"_datetime": text, *element} / {"_bool": bool, *element} / {"_link": ciri, *element} / {"_form": ciri, *element}
5
+ ciri = text ; full IRI given
6
+ / [text] ; suffix for default prefix
7
+ / [text, text] ; prefix, suffix for that prefix
@@ -0,0 +1,11 @@
1
+
2
+ map-example = {
3
+ ? optional-key : int,
4
+ * map-example-extension,
5
+ * tstr => any
6
+ }
7
+
8
+ map-example-extension = ()
9
+
10
+ map-example-extension //= (another-optional-key : tstr,)
11
+ map-example-extension //= ("and a third" : bstr,)
@@ -0,0 +1,12 @@
1
+ map-example = {
2
+ ? "optional-key" : int,
3
+ map-example-extensions,
4
+ * tstr => any
5
+ }
6
+
7
+ map-example-extensions = ()
8
+
9
+ map-example-extensions //= (
10
+ "another-optional-key" : tstr,
11
+ "and a third": bstr
12
+ )
@@ -0,0 +1,9 @@
1
+ BLEIdentification = {
2
+ ? 0 : bool,
3
+ ? 1 : bool,
4
+ ? 10 : bstr,
5
+ ; Indicates support for Peripheral server mode
6
+ ; Indicates support for Central client mode
7
+ ; Optional UUID for peripheral server mode
8
+ ? 11 : bstr ; Optional MAC address for peripheral server mode
9
+ }
@@ -0,0 +1,54 @@
1
+ deviceEngagement = [
2
+ uint,
3
+ security,
4
+ transferMethods,
5
+ options,
6
+ ? proprietary
7
+ ]
8
+ security = [
9
+ bstr,
10
+ uint, uint
11
+ ]
12
+ transferMethods = [
13
+ * transferMethod
14
+ ]
15
+ options = {
16
+ ?"WebAPI" : WebAPI,
17
+ ?"OIDC" : OIDC,
18
+ ?"compact" : bool
19
+ }
20
+ proprietary = {
21
+ * tstr => any
22
+ }
23
+ transferMethod = [
24
+ uint,
25
+ uint, * any
26
+ ]
27
+ OIDC = [
28
+ uint,
29
+ tstr,
30
+ tstr
31
+ ]
32
+ WebAPI = [
33
+ uint,
34
+ tstr, tstr
35
+ ]
36
+ ; Version of device engagement structure, currently 1
37
+ ; Security structure
38
+ ; Transfer methods
39
+ ; Optional elements
40
+ ; Proprietary elements
41
+ ; mDL public ephemeral key, mDL.EPub
42
+ ; curve identifier, see Table 23
43
+ ; cipher suite identifier, see Table 22
44
+ ; details for transfer methods
45
+ ; any number of elements
46
+ ; type
47
+ ; version
48
+ ; specific option(s) to the type
49
+ ; version
50
+ ; url
51
+ ; token
52
+ ; version
53
+ ; url
54
+ ; token
@@ -0,0 +1,11 @@
1
+ driving_privileges = [
2
+ * driving_privilege
3
+ ]
4
+ driving_privilege = {
5
+ vehicle_category_code: tstr
6
+ ?issue_date: #6.0(tstr)
7
+ ?expiry_date: #6.0(tstr)
8
+ ?code: tstr
9
+ ?sign: tstr
10
+ ?value: int
11
+ }
@@ -0,0 +1,20 @@
1
+ MobileSecurityObject = {
2
+ "DigestAlgorithm" : tstr,
3
+ "ValueDigests" : ValueDigests,
4
+ "DeviceKey" : COSE_Key,
5
+ "DocType" : tstr
6
+ }
7
+ ValueDigests = {
8
+ "NameSpaces" : NameSpaces
9
+ }
10
+ NameSpaces = {
11
+ + NameSpace => DigestIDs
12
+ }
13
+ DigestIDs = {
14
+ + DigestID => Digest
15
+ }
16
+ NameSpace = tstr
17
+ DigestID = uint
18
+ Digest = bstr
19
+
20
+ COSE_Key = "COSE_Key"
@@ -0,0 +1,26 @@
1
+ Request = {
2
+ "Version" : tstr,
3
+ "DocRequests" : [+ DocRequest]
4
+ }
5
+ DocRequest = {
6
+ "ItemsRequest" : ItemsRequest,
7
+ ? "ReaderAuth" : COSE_Sign1
8
+ }
9
+ ItemsRequest = {
10
+ ? "DocType" : DocType,
11
+ "NameSpaces" : NameSpaces,
12
+ ? "RequestInfo" : {* tstr => any}
13
+ }
14
+ NameSpaces = {
15
+ + NameSpace => DataItemNames
16
+ }
17
+ DocType = tstr
18
+ NameSpace = tstr
19
+ DataItemNames = [ + tstr ]
20
+ ; Additional info the reader wants to provide
21
+ ; Requested data elements for each NameSpace
22
+ ; See 7.3.2
23
+ ; See 7.3.3
24
+ ; See Table 2
25
+
26
+ COSE_Sign1 = "COSE_Sign1"
@@ -0,0 +1,66 @@
1
+ Response = {
2
+ "Version" : tstr,
3
+ ? "Documents" : Documents,
4
+ ? "Error" : int
5
+ }
6
+ Documents = {
7
+ + DocType => ResponseData
8
+ }
9
+ ; Version of the structure, currently 1.0
10
+ ; Returned documents, may be absent if Error is present
11
+ ; Error codes according to Table 8
12
+ ResponseData = {
13
+ "IssuerSigned" : IssuerSigned, ; Responded data elements signed by the issuer
14
+ "DeviceSigned" : DeviceSigned, ; Responded data elements signed by the mDL
15
+ "Errors" : Errors
16
+ }
17
+ IssuerSigned = {
18
+ "NameSpaces" : IssuerNameSpaces,
19
+ "IssuerAuth" : COSE_Sign1 ; The payload is the MobileSecurityObject, see 9.2.1.4
20
+ }
21
+ IssuerNameSpaces = {
22
+ + NameSpace => [ + IssuerSignedItem ]
23
+ }
24
+ IssuerSignedItem = [
25
+ uint,
26
+ bstr,
27
+ tstr,
28
+ any
29
+ ]
30
+ DeviceSigned = {
31
+ "NameSpaces" : DeviceNameSpaces, ; Currently only online token and URL are defined as DeviceSignedItems
32
+ "DeviceAuth" : DeviceAuth
33
+ }
34
+ DeviceNameSpaces = {
35
+ * NameSpace => DeviceSignedItems
36
+ }
37
+ DeviceSignedItems = {
38
+ + DataItemName => DataItemValue
39
+ }
40
+ DeviceAuth = {
41
+ "Signature" : COSE_Sign1, //
42
+ ; Use a nil value for the payload, the detached content is the DeviceAuthentication structure, see 9.2.2.4
43
+ "MAC" : COSE_Mac0
44
+ }
45
+ Errors = {
46
+ * NameSpace => [ + ErrorItem ]
47
+ }
48
+ ErrorItem = {
49
+ DataItemName => ErrorCode
50
+ }
51
+ DocType = tstr
52
+ NameSpace = tstr
53
+ DataItemName = tstr
54
+ DataItemValue = any
55
+ ErrorCode = int
56
+ ; See table 9
57
+ ; See 7.3.2
58
+ ; See 7.3.3
59
+ ; See Table 2
60
+ ; See Table 2
61
+ ; Error codes according to Table 9
62
+ ; Structures used for DeviceAuth signature or MAC generation, see 9.2.2.4
63
+ ; Structures used for MobileSecurityObject, see 9.2.1.4
64
+
65
+ COSE_Sign1 = "COSE_Sign1"
66
+ COSE_Mac0 = "COSE_Mac0"
@@ -0,0 +1,11 @@
1
+ driving_privileges = [
2
+ * driving_privilege
3
+ ]
4
+ driving_privilege = {
5
+ vehicle_category_code: tstr
6
+ ?issue_date: #6.0(tstr)
7
+ ?expiry_date: #6.0(tstr)
8
+ ?code: tstr
9
+ ?sign: tstr
10
+ ?value: int
11
+ }
@@ -0,0 +1 @@
1
+ decimal-monetary-value = text .regexp "-?[0-9]+(\\.[0-9]+)?"
@@ -0,0 +1,2 @@
1
+ multipart-core = [* multipart-part]
2
+ multipart-part = (type: uint .size 2, part: bytes / null)
@@ -171,6 +171,57 @@ HERE
171
171
  assert parser.validate_for_test(true)
172
172
  end
173
173
 
174
+ def test_validate_bignum
175
+ parser = CDDL::Parser.new <<HERE
176
+ test = bigint
177
+ HERE
178
+ assert parser.validate_for_test(2**4711)
179
+ assert parser.validate_for_test(-2**815)
180
+ assert parser.validate_for_test(1)
181
+ assert parser.validate_for_test(0)
182
+ assert parser.validate_for_test(-11)
183
+ end
184
+
185
+ def test_aaaaaaaa_invalidate_bignum
186
+ parser = CDDL::Parser.new <<HERE
187
+ test = bignint
188
+ HERE
189
+ refute parser.validate_for_test(2**4711, false)
190
+ assert parser.validate_for_test(-2**815)
191
+ refute parser.validate_for_test(1, false)
192
+ refute parser.validate_for_test(0, false)
193
+ assert parser.validate_for_test(-11)
194
+ end
195
+
196
+
197
+ def test_aaaaaaaa_validate_bignum0b
198
+ parser = CDDL::Parser.new <<HERE
199
+ test = #6.2("")
200
+ HERE
201
+ refute parser.validate_for_test(1, false)
202
+ refute parser.validate_for_test(0, false)
203
+ end
204
+
205
+
206
+ def test_aaaaaaaa_validate_bignum0
207
+ parser = CDDL::Parser.new <<HERE
208
+ test = #6.2(h'')
209
+ HERE
210
+ assert parser.validate_for_test(0)
211
+ refute parser.validate_for_test(1, false)
212
+ end
213
+
214
+
215
+ def test_aaaaaaaa_validate_bignum1
216
+ parser = CDDL::Parser.new <<HERE
217
+ test = #6.2(h'01')
218
+ HERE
219
+ assert parser.validate_for_test(1)
220
+ refute parser.validate_for_test(0, false)
221
+ refute parser.validate_for_test(2, false)
222
+ end
223
+
224
+
174
225
  def test_validate_a
175
226
  parser = CDDL::Parser.new <<HERE
176
227
  test = [* one: 1]
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.9
4
+ version: 0.8.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-20 00:00:00.000000000 Z
11
+ date: 2019-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cbor-diag
@@ -97,7 +97,9 @@ files:
97
97
  - test-data/7071-concise-cut.cddl
98
98
  - test-data/7071-concise.cddl
99
99
  - test-data/7071-verbose.cddl
100
+ - test-data/7807.cddl
100
101
  - test-data/a.cddl
102
+ - test-data/abignum.cddl
101
103
  - test-data/ambig.cddl
102
104
  - test-data/b.cddl
103
105
  - test-data/badaddr.cddl
@@ -106,6 +108,10 @@ files:
106
108
  - test-data/bpv7a.cddl
107
109
  - test-data/bpv7b.cddl
108
110
  - test-data/cdni-ct.cddl
111
+ - test-data/coral.cddl
112
+ - test-data/coral1.cddl
113
+ - test-data/coral2.cddl
114
+ - test-data/coral3.cddl
109
115
  - test-data/cose.cddl
110
116
  - test-data/dcaf.cddl
111
117
  - test-data/dcaf1.cddl
@@ -123,11 +129,22 @@ files:
123
129
  - test-data/ifmap-metadata-2.2v9_fh-cabo.cddl
124
130
  - test-data/ifmap2.cddl
125
131
  - test-data/jcr-ex.cddl
132
+ - test-data/jim-cut-2.cddl
133
+ - test-data/jim-cut.cddl
126
134
  - test-data/jsoniodef.cddl
127
135
  - test-data/kevin5.cddl
128
136
  - test-data/map-group.cddl
129
137
  - test-data/mapkey.cddl
138
+ - test-data/mdl-ble.cddl
139
+ - test-data/mdl-deve.cddl
140
+ - test-data/mdl-dp.cddl
141
+ - test-data/mdl-mso.cddl
142
+ - test-data/mdl-request.cddl
143
+ - test-data/mdl-response.cddl
144
+ - test-data/mdl.cddl
130
145
  - test-data/minimal.cddl
146
+ - test-data/mon-val.cddl
147
+ - test-data/multipart-ct.cddl
131
148
  - test-data/named-group.cddl
132
149
  - test-data/patch1.cddl
133
150
  - test-data/reused_named_group.cddl
@@ -160,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
177
  - !ruby/object:Gem::Version
161
178
  version: '0'
162
179
  requirements: []
163
- rubygems_version: 3.0.3
180
+ rubygems_version: 3.0.6
164
181
  signing_key:
165
182
  specification_version: 4
166
183
  summary: CDDL generator and validator.