cddl 0.8.6 → 0.8.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8ba44459ee2f7bf888218b60e75e52c6dbf90b38cb498b3de091ae7e5e525213
4
- data.tar.gz: 8fcb86e2209fb4264f55663a47a37a9b150347f32704af94f0be27357d012d18
3
+ metadata.gz: 77b28f069a663ccb82301ec6db8cf42db6b00127b36272020baf874416029a2b
4
+ data.tar.gz: c37387e5d6b1009d054cb9a345d337e43fbc2a9bcc826d009aa0b1cdfeded437
5
5
  SHA512:
6
- metadata.gz: 65f7adeb64757a58a0b548a5c33fcf78ca0e3bb9ae442032d40ddc45c098de7471657437772f1fed07716bcb829467b75d8eaf4982ed04be78ce2abbca780684
7
- data.tar.gz: 6274c24c143aed5cba8d35f17e0beab84fe6af515fd4e44c11133bf3296c68f84cbd8f526616ad6cc2b8ff397f56d60ea2cf16e1d09990dc7f9aec50be5929ef
6
+ metadata.gz: b7818289a708b07c08a58c8b114730777d70a4dbfb43ec94f10fbcacfae21cdbdcd72b11dd225e52471963e1570d30cb5703790f424b470015ab67064cc48ae8
7
+ data.tar.gz: 301eb0733448db7eae4dff9404d51b436c018ede13ed9a2288a6285d783e58d479186e80193e90e38ed075bd24b33fccf1ed2055eb57fd99cd99594621aa1df7
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'cddl'
3
- s.version = '0.8.6'
3
+ s.version = '0.8.11'
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')
@@ -19,3 +19,4 @@ spec = Gem::Specification.new do |s|
19
19
  s.homepage = "http://github.com/cabo/cddl"
20
20
  s.license = 'MIT'
21
21
  end
22
+
@@ -49,10 +49,10 @@ occur = [uint] "*" [uint]
49
49
  / "+"
50
50
  / "?"
51
51
 
52
- uint = ["0x" / "0b"] "0"
53
- / DIGIT1 *DIGIT
52
+ uint = DIGIT1 *DIGIT
54
53
  / "0x" 1*HEXDIG
55
54
  / "0b" 1*BINDIG
55
+ / "0"
56
56
 
57
57
  value = number
58
58
  / text
@@ -329,8 +329,12 @@ module CDDL
329
329
  unless kr
330
330
  case vr[0]
331
331
  when :grpent
332
- fail "grpent in map #{vr.inspect}" unless vr.size == 2
333
- g = Array.new(st) { generate1(vr[1], true) }.flatten(1)
332
+ # fail "grpent in map #{vr.inspect}" unless vr.size == 2
333
+ g = Array.new(st) {
334
+ vr[1..-1].map{ |vrx|
335
+ generate1(vrx, true)
336
+ }.flatten(1)
337
+ }.flatten(1)
334
338
  # warn "GGG #{g.inspect}"
335
339
  return g
336
340
  when :grpchoice
@@ -392,15 +396,19 @@ module CDDL
392
396
  case where[1]
393
397
  when :size
394
398
  should_be_int = generate1(control)
395
- unless (target == [:prim, 2] || target == [:prim, 0]) && Integer === should_be_int && should_be_int >= 0
399
+ unless (Array === target && target[0] == :prim && [0, 2, 3].include?(target[1])) && Integer === should_be_int && should_be_int >= 0
396
400
  fail "Don't know yet how to generate #{where}"
397
401
  end
398
402
  s = Random.new.bytes(should_be_int)
399
- if target == [:prim, 0]
403
+ case target[1]
404
+ when 0
400
405
  # silently restrict to what we can put into a uint
401
406
  s[0...8].bytes.inject(0) {|a, b| a << 8 | b }
402
- else
407
+ when 2
403
408
  s
409
+ when 3
410
+ Base64.urlsafe_encode64(s)[0...should_be_int]
411
+ # XXX generate word a la w = gen_word
404
412
  end
405
413
  when :bits
406
414
  set_of_bits = Array.new(10) { generate1(control) } # XXX: ten?
@@ -431,6 +439,8 @@ module CDDL
431
439
  $default_warned = true
432
440
  end
433
441
  generate1(target, inmap)
442
+ when :feature
443
+ generate1(target, inmap)
434
444
  when :eq
435
445
  content = generate1(control)
436
446
  if validate1(content, where)
@@ -519,7 +529,7 @@ module CDDL
519
529
  end
520
530
  end
521
531
 
522
- VALUE_TYPE = {text: String, int: Integer, float: Float}
532
+ VALUE_TYPE = {text: String, bytes: String, int: Integer, float: Float}
523
533
  SIMPLE_VALUE = {
524
534
  [:prim, 7, 20] => [true, false, :bool],
525
535
  [:prim, 7, 21] => [true, true, :bool],
@@ -543,11 +553,17 @@ module CDDL
543
553
 
544
554
  def validate(d, warn=true)
545
555
  @recursion = 0
556
+ $features = Hash.new {|h, k| h[k] = {}}
546
557
  result = validate1a(d, rules)
547
- unless result
548
- if warn
558
+ if warn
559
+ if result
560
+ if $features != {}
561
+ warn "** Features potentially used: #{$features.map {|k, v| "#{k}: #{v.keys}"}.join(", ")}"
562
+ end
563
+ else
549
564
  warn "CDDL validation failure (#{result.inspect} for #{d.inspect}):"
550
565
  PP::pp(validate_diag, STDERR)
566
+ puts(validate_diag.cbor_diagnostic)
551
567
  end
552
568
  end
553
569
  result
@@ -737,9 +753,12 @@ module CDDL
737
753
  idx, ann = validate_forward(d, 0, where)
738
754
  ann if validate_result(idx == d.size) { "#{validate_diag.inspect} -- cannot complete (#{idx}, #{d.size}) array #{d} for #{where}" }
739
755
  end
740
- when :text, :int, :float, :bytes
756
+ when :int, :float
741
757
  _, v = extract_value(where)
742
758
  [] if d == v
759
+ when :text, :bytes
760
+ _, v = extract_value(where)
761
+ [] if d == v && ((d.encoding == Encoding::BINARY) == (v.encoding == Encoding::BINARY))
743
762
  when :range
744
763
  [] if where[2] === d && where[1].include?(d)
745
764
  when :anno
@@ -785,6 +804,10 @@ module CDDL
785
804
  $default_warned = true
786
805
  end
787
806
  ann
807
+ when :feature
808
+ ok, v, vt = extract_value(control)
809
+ $features[v][d] = true
810
+ ann
788
811
  when :lt, :le, :gt, :ge, :eq, :ne
789
812
  op = OPERATORS[where[1]]
790
813
  ok, v, _vt = extract_value(control)
@@ -833,6 +856,14 @@ module CDDL
833
856
  when 3
834
857
  String === d && d.encoding != Encoding::BINARY # cheat
835
858
  when 6
859
+ if Integer === d
860
+ t = 2 # assuming only 2/3 match an Integer
861
+ if d < 0
862
+ d = ~d
863
+ t = 3
864
+ end
865
+ d = CBOR::Tagged.new(t, d == 0 ? "".b : d.digits(256).reverse!.pack("C*"))
866
+ end
836
867
  CBOR::Tagged === d && d.tag == where[2] && validate1a(d.data, where[3])
837
868
  when 7
838
869
  t, v = extract_value(where)
@@ -955,7 +986,7 @@ module CDDL
955
986
  when ""
956
987
  parts[1].b
957
988
  when "h"
958
- parts[1].gsub(/\s/, "").chars.each_slice(2).map{ |x| Integer(x.join, 16).chr("BINARY") }.join
989
+ parts[1].gsub(/\s/, "").chars.each_slice(2).map{ |x| Integer(x.join, 16).chr("BINARY") }.join.b
959
990
  when "b64"
960
991
  Base64.urlsafe_decode64(parts[1])
961
992
  else
@@ -1138,7 +1169,7 @@ module CDDL
1138
1169
  end
1139
1170
  when :recurse_grpent # XXX we don't have the entry yet
1140
1171
  when :member
1141
- fail "map entry without member key given: #{member}" unless member[3] || member[4][0] == :grpent || member[4][0] == :grpchoice
1172
+ fail "map entry #{member.inspect} without member key given: #{member}" unless member[3] || member[4][0] == :grpent || member[4][0] == :grpchoice
1142
1173
  else
1143
1174
  fail ["type1 member", member].inspect unless member[0] == :member
1144
1175
  end
@@ -1148,7 +1179,7 @@ module CDDL
1148
1179
  BRACE = {"{" => :map, "[" => :array}
1149
1180
  RANGE_EXCLUDE_END = {".." => false, "..." => true}
1150
1181
  SUPPORTED_ANNOTATIONS = [:bits, :size, :regexp, :cbor, :cborseq, :within, :and,
1151
- :default, :lt, :le, :gt, :ge, :eq, :ne]
1182
+ :default, :lt, :le, :gt, :ge, :eq, :ne, :feature]
1152
1183
 
1153
1184
  def type1(n, canbegroup = false)
1154
1185
  # puts "NVALUE #{n.value.inspect}"
@@ -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,136 @@
1
+ start = bundle
2
+
3
+ dtn-time = uint
4
+
5
+ creation-timestamp = [dtn-time, sequence: uint]
6
+
7
+ eid-generic = [uri-code, SSP: any]
8
+
9
+ uri-code = uint
10
+
11
+ eid = eid-choice .within eid-generic
12
+
13
+ eid-choice /= [dtn-code, SSP: (text / 0)]
14
+
15
+ dtn-code = 1 ; TBD
16
+
17
+ eid-choice /= [ipn-code, SSP: [nodenum: uint, servicenum: uint]]
18
+
19
+ ipn-code = 2 ; TBD
20
+
21
+ bundle-control-flags = uint .bits bundleflagbits
22
+
23
+ bundleflagbits = &(
24
+
25
+ reserved: 15
26
+
27
+ reserved: 14
28
+
29
+ reserved: 13
30
+
31
+ bundle-deletion-status-reports-are-requested: 12
32
+
33
+ bundle-delivery-status-reports-are-requested: 11
34
+
35
+ bundle-forwarding-status-reports-are-requested: 10
36
+
37
+ reserved: 9
38
+
39
+ bundle-reception-status-reports-are-requested: 8
40
+
41
+ bundle-contains-a-Manifest-block: 7
42
+
43
+ status-time-is-requested-in-all-status-reports: 6
44
+
45
+ user-application-acknowledgement-is-requested: 5
46
+
47
+ reserved: 4
48
+
49
+ reserved: 3
50
+
51
+ bundle-must-not-be-fragmented: 2
52
+
53
+ payload-is-an-administrative-record: 1
54
+
55
+ bundle-is-a-fragment: 0
56
+
57
+ )
58
+
59
+ crc = bytes
60
+
61
+ block-control-flags = uint .bits blockflagbits
62
+
63
+ blockflagbits = &(
64
+
65
+ reserved: 7
66
+
67
+ reserved: 6
68
+
69
+ reserved: 5
70
+
71
+ reserved: 4
72
+
73
+ bundle-must-be-deleted-if-block-cannot-be-processed: 3
74
+
75
+ status-report-must-be-transmitted-if-block-cannot-be-processed: 2
76
+
77
+ block-must-be-removed-from-bundle-if-it-cannot-be-processed: 1
78
+
79
+ block-must-be-replicated-in-every-fragment: 0
80
+
81
+ )
82
+
83
+ bundle = [primary-block, *extension-block, payload-block]
84
+
85
+ primary-block = [
86
+
87
+ version: 7,
88
+
89
+ bundle-control-flags,
90
+
91
+ crc-type: uint,
92
+
93
+ destination: eid,
94
+
95
+ source-node: eid,
96
+
97
+ report-to: eid,
98
+
99
+ creation-timestamp,
100
+
101
+ lifetime: uint,
102
+
103
+ ? fragment-offset: uint,
104
+
105
+ ? total-application-data-length: uint,
106
+
107
+ ? crc,
108
+
109
+ ]
110
+
111
+ canonical-block = [
112
+
113
+ block-type-code: uint,
114
+
115
+ canonical-block-common,
116
+
117
+ ? crc
118
+
119
+ ]
120
+
121
+ canonical-block-common = (
122
+
123
+ block-number: uint,
124
+
125
+ block-control-flags,
126
+
127
+ crc-type: uint,
128
+
129
+ block-type-specific-data: bytes
130
+
131
+ )
132
+
133
+
134
+ payload-block = ([block-type-code: 1, canonical-block-common, ?crc]) .within canonical-block
135
+
136
+ extension-block = ([block-type-code: (uint .ne 1), canonical-block-common, ?crc]) .within canonical-block
@@ -0,0 +1,181 @@
1
+ start = bundle / #6.55799(bundle)
2
+
3
+ ; Times before 2000 are invalid
4
+ dtn-time = uint
5
+
6
+ ; CRC enumerated type
7
+ crc-type = 0 / 1 / 2
8
+ ; Either 16-bit or 32-bit
9
+ crc-value = (bstr .size 2) / (bstr .size 4)
10
+
11
+ creation-timestamp = [dtn-time, sequence: uint]
12
+
13
+ eid = $eid-choice .within eid-structure
14
+ eid-structure = [
15
+ uri-code: uint,
16
+ SSP: any
17
+ ]
18
+ $eid-choice /= [
19
+ uri-code: 1,
20
+ SSP: (tstr / 0)
21
+ ]
22
+ $eid-choice /= [
23
+ uri-code: 2,
24
+ SSP: [
25
+ nodenum: uint,
26
+ servicenum: uint
27
+ ]
28
+ ]
29
+
30
+ bundle-control-flags = uint .bits bundleflagbits
31
+ bundleflagbits = &(
32
+ reserved: 15
33
+ reserved: 14
34
+ reserved: 13
35
+ bundle-deletion-status-reports-are-requested: 12
36
+ bundle-delivery-status-reports-are-requested: 11
37
+ bundle-forwarding-status-reports-are-requested: 10
38
+ reserved: 9
39
+ bundle-reception-status-reports-are-requested: 8
40
+ bundle-contains-a-Manifest-block: 7
41
+ status-time-is-requested-in-all-status-reports: 6
42
+ user-application-acknowledgement-is-requested: 5
43
+ reserved: 4
44
+ reserved: 3
45
+ bundle-must-not-be-fragmented: 2
46
+ payload-is-an-administrative-record: 1
47
+ bundle-is-a-fragment: 0
48
+ )
49
+
50
+ block-control-flags = uint .bits blockflagbits
51
+ blockflagbits = &(
52
+ reserved: 7
53
+ reserved: 6
54
+ reserved: 5
55
+ reserved: 4
56
+ bundle-must-be-deleted-if-block-cannot-be-processed: 3
57
+ status-report-must-be-transmitted-if-block-cannot-be-processed: 2
58
+ block-must-be-removed-from-bundle-if-it-cannot-be-processed: 1
59
+ block-must-be-replicated-in-every-fragment: 0
60
+ )
61
+
62
+ bundle = [primary-block, *extension-block, payload-block]
63
+
64
+ primary-block = [
65
+ version: 7,
66
+ bundle-control-flags,
67
+ crc-type,
68
+ destination: eid,
69
+ source-node: eid,
70
+ report-to: eid,
71
+ creation-timestamp,
72
+ lifetime: uint,
73
+ ? (
74
+ fragment-offset: uint,
75
+ ; total-application-data-length: uint,
76
+ )
77
+ ? crc-value,
78
+ ]
79
+
80
+ ; Abstract shared structure of all non-primary blocks
81
+ canonical-block-structure = [
82
+ block-type-code: uint,
83
+ block-number: uint,
84
+ block-control-flags,
85
+ crc-type,
86
+ ; Each block type defines the content within the bytestring
87
+ block-type-specific-data,
88
+ ? crc-value
89
+ ]
90
+ block-type-specific-data = bstr / #6.24(bstr)
91
+ ; Extension block type, which does not specialize any more than the code/number
92
+ extension-block = $extension-block-structure .within canonical-block-structure
93
+ $extension-block-structure = [
94
+ block-type-code: (uint .gt 1),
95
+ extension-block-number,
96
+ block-control-flags,
97
+ crc-type,
98
+ ($extension-block-data .within block-type-specific-data)
99
+ ? crc-value
100
+ ]
101
+ extension-block-number = (uint .ne 0)
102
+ ; Payload block type
103
+ payload-block = payload-block-structure .within canonical-block-structure
104
+ payload-block-structure = [
105
+ block-type-code: 1,
106
+ block-number: 0,
107
+ block-control-flags,
108
+ crc-type,
109
+ ($payload-block-data .within block-type-specific-data)
110
+ ? crc-value
111
+ ]
112
+
113
+ ; Arbitrary payload data
114
+ $payload-block-data /= bstr
115
+
116
+
117
+ ; Administrative record as a payload data specialization
118
+ $payload-block-data /= block-type-specific-data .cbor admin-record
119
+ admin-record = $admin-record .within admin-record-structure
120
+ admin-record-structure = [
121
+ record-type-code: uint,
122
+ record-content: any
123
+ ]
124
+ ; Only one defined record type
125
+ $admin-record /= [1, status-record-content]
126
+ status-record-content = [
127
+ bundle-status-information,
128
+ status-report-reason-code: uint,
129
+ source-node-eid: eid,
130
+ subject-creation-timestamp: creation-timestamp,
131
+ ? (
132
+ subject-payload-offset: uint,
133
+ subject-payload-length: uint
134
+ )
135
+ ]
136
+ bundle-status-information = [
137
+ reporting-node-received-bundle: status-info-content,
138
+ reporting-node-forwarded-bundle: status-info-content,
139
+ reporting-node-delivered-bundle: status-info-content,
140
+ reporting-node-deleted-bundle: status-info-content
141
+ ]
142
+ status-info-content = [
143
+ status-indicator: bool,
144
+ ? timestamp: dtn-time
145
+ ]
146
+
147
+ ; Previous Node extension block
148
+ $extension-block-structure /= [
149
+ block-type-code: 7,
150
+ extension-block-number,
151
+ block-control-flags,
152
+ crc-type,
153
+ (block-type-specific-data .cbor ext-data-previous-node)
154
+ ? crc-value
155
+ ]
156
+ ext-data-previous-node = eid
157
+
158
+ ; Bundle Age extension block
159
+ $extension-block-structure /= [
160
+ block-type-code: 8,
161
+ extension-block-number,
162
+ block-control-flags,
163
+ crc-type,
164
+ (block-type-specific-data .cbor ext-data-bundle-age)
165
+ ? crc-value
166
+ ]
167
+ ext-data-bundle-age = uint
168
+
169
+ ; Hop Count extension block
170
+ $extension-block-structure /= [
171
+ block-type-code: 9,
172
+ extension-block-number,
173
+ block-control-flags,
174
+ crc-type,
175
+ (block-type-specific-data .cbor ext-data-hop-count)
176
+ ? crc-value
177
+ ]
178
+ ext-data-hop-count = [
179
+ hop-limit: uint,
180
+ hop-count: uint
181
+ ]