cddl 0.11.4 → 0.12.1

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: 2b496a36874447ba9821e185ef347fd7360ec404f7b1fc3fb33f5d2d94c33443
4
- data.tar.gz: be328f5d7b8fe8426bb7b60b11be9d378d6f26f0e3c5598578c75efb5696663a
3
+ metadata.gz: a29d5d85e11598502b09d04e3b08a7ada9b6d0d8a9eb0e425bb01da81b92532b
4
+ data.tar.gz: 61c2a191c264c34600f0b66a8e7cfb2ea1359f3954676828a56a63aa25e3015c
5
5
  SHA512:
6
- metadata.gz: f8ec72cbdeeb7eb1ecb2b7cd4173af652b06efe76c1ddbb0e8017248f1c9edbec499c7bb6c82099b52fa963f1ac7dd7062ed8e11b0142bcf8197c62166999fb4
7
- data.tar.gz: 59cdd71d13a5d9232f5244a644f42f908cd26de059c20f4787ad3e1cae09454145ebff8aa16e69d1efb52bb9387e06940983543b7a3626e76e72188d3f54b13a
6
+ metadata.gz: 671d119f1cb328151c0631cbcd808f5a32d1f82d6c715a64cb5e5c9702b3452c996278a6b5055613de74b00f76489a9874037b336ac3a760947d4a2526d84cc9
7
+ data.tar.gz: 8146d9b66bb87e84b2179507fb9144012676be726dd5f4312da2482a047e46429a6d41d5b1d49097724aa8cfd68519be06e6e8f860e97f0cbc187de0c20242ca
data/bin/cddl CHANGED
@@ -29,7 +29,10 @@ def read_arg(arg, remember_fn = true)
29
29
  else
30
30
  usage unless arg
31
31
  $fn = arg if remember_fn
32
- File.read(arg, mode: "rb")
32
+ File.read(arg, mode: "rb").force_encoding(Encoding::UTF_8).scrub { |c|
33
+ warn "*** replaced invalid UTF-8 byte sequence #{c.inspect} by U+FFFD REPLACEMENT CHARACTER"
34
+ 0xFFFD.chr(Encoding::UTF_8)
35
+ }
33
36
  end
34
37
  end
35
38
 
data/cddl.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'cddl'
3
- s.version = '0.11.4'
3
+ s.version = '0.12.1'
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')
data/data/cddl.abnf CHANGED
@@ -70,27 +70,39 @@ fraction = 1*DIGIT
70
70
  exponent = int
71
71
 
72
72
  text = %x22 *SCHAR %x22
73
- SCHAR = %x20-21 / %x23-7E / SESC
74
- SESC = "\" %x20-7E
73
+ SCHAR = %x20-21 / %x23-5B / %x5D-7E / NONASCII / SESC
74
+
75
+ SESC = "\" ( %x22 / "/" / "\" / ; \" \/ \\
76
+ %x62 / %x66 / %x6E / %x72 / %x74 / ; \b \f \n \r \t
77
+ (%x75 hexchar) ) ; \uXXXX
78
+
79
+ hexchar = "{" (1*"0" [ hexscalar ] / hexscalar) "}" /
80
+ non-surrogate / (high-surrogate "\" %x75 low-surrogate)
81
+ non-surrogate = ((DIGIT / "A"/"B"/"C" / "E"/"F") HEXDIG HEXDIG HEXDIG) /
82
+ ("D" %x30-37 HEXDIG HEXDIG)
83
+ high-surrogate = "D" ("8"/"9"/"A"/"B") HEXDIG HEXDIG
84
+ low-surrogate = "D" ("C"/"D"/"E"/"F") HEXDIG HEXDIG
85
+ hexscalar = "10" HEXDIG HEXDIG HEXDIG HEXDIG / HEXDIG1 HEXDIG HEXDIG HEXDIG HEXDIG
86
+ / non-surrogate / HEXDIG [HEXDIG [HEXDIG]]
75
87
 
76
88
  bytes = [bsqual] %x27 *BCHAR %x27
77
- BCHAR = %x20-26 / %x28-5B / %x5D-7E / SESC / CRLF
78
- bsqual = %x68 ; "h"
79
- / %x62.36.34 ; "b64"
89
+ BCHAR = %x20-26 / %x28-5B / %x5D-7E / NONASCII / SESC / "\'" / CRLF
90
+ bsqual = "h" / "b64"
80
91
 
81
92
  id = EALPHA *(*("-" / ".") (EALPHA / DIGIT))
82
93
  ALPHA = %x41-5A / %x61-7A
83
- EALPHA = %x41-5A / %x61-7A / "@" / "_" / "$"
94
+ EALPHA = ALPHA / "@" / "_" / "$"
84
95
  DIGIT = %x30-39
85
96
  DIGIT1 = %x31-39
86
97
  HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F"
98
+ HEXDIG1 = DIGIT1 / "A" / "B" / "C" / "D" / "E" / "F"
87
99
  BINDIG = %x30-31
88
100
 
89
101
  S = *WS
90
102
  WS = SP / NL
91
103
  SP = %x20
92
104
  NL = COMMENT / CRLF
93
- COMMENT = ";" *(SP / VCHAR) CRLF
94
- VCHAR = %x21-7E
105
+ COMMENT = ";" *PCHAR CRLF
106
+ PCHAR = %x20-7E / NONASCII
107
+ NONASCII = %xA0-D7FF / %xE000-10FFFD
95
108
  CRLF = %x0A / %x0D.0A
96
-
data/lib/cddl.rb CHANGED
@@ -61,7 +61,7 @@ module CDDL
61
61
  if upto - presult < 100
62
62
  part2 = source_text[presult...upto]
63
63
  else
64
- part2 = source_text[presult, 50] + "......." + source_text[upto-50, 50]
64
+ part2 = source_text[presult, 50] + "......." + (source_text[upto-50, 50] || "")
65
65
  end
66
66
  warn "*** Look for syntax problems around the #{
67
67
  "%%%".colorize(background: :light_yellow)} markers:\n#{
@@ -1271,7 +1271,7 @@ module CDDL
1271
1271
  String === d && (
1272
1272
  decoded = case conop
1273
1273
  when :b64u
1274
- /=/ !~ d &&
1274
+ /[+\/=]/ !~ d &&
1275
1275
  Base64.urlsafe_decode64(d)
1276
1276
  when :"b64u-sloppy"
1277
1277
  /[-_=]/ !~ d &&
@@ -1473,6 +1473,18 @@ module CDDL
1473
1473
  end
1474
1474
  end
1475
1475
 
1476
+ STRING_ESCAPES = {
1477
+ "\"" => "\"",
1478
+ "/" => "/",
1479
+ "\\" => "\\",
1480
+ "'" => "'",
1481
+ "b" => "\b",
1482
+ "f" => "\f",
1483
+ "n" => "\n",
1484
+ "r" => "\r",
1485
+ "t" => "\t",
1486
+ }
1487
+
1476
1488
  def value(n)
1477
1489
  # cheat:
1478
1490
  # warn n
@@ -1482,7 +1494,20 @@ module CDDL
1482
1494
  if parts[-1] != ""
1483
1495
  warn "*** Problem decoding byte string #{s.inspect}"
1484
1496
  end
1485
- bsval = parts[0...-1].join("'").gsub(/\\(.)/){$1}
1497
+ bsval = parts[0...-1].join("'").gsub(/\\u([Dd][89AaBb][0-9a-zA-Z]{2})\\u([Dd][CcDdEeFf][0-9a-zA-Z]{2})|\\u([0-9a-zA-Z]{4})|\\u\{([0-9a-zA-Z]+)\}|\r?(\n)|\\([^u])/) {
1498
+ if hex = $3 || $4
1499
+ hex.to_i(16).chr(Encoding::UTF_8)
1500
+ elsif lf = $5
1501
+ lf
1502
+ elsif escaped = $6
1503
+ STRING_ESCAPES[$6] or (
1504
+ fail "Invalid String Escape #{escaped.inspect} in #{s.inspect}"
1505
+ )
1506
+ else
1507
+ ((($1.to_i(16) & 0x3ff) << 10) +
1508
+ ($2.to_i(16) & 0x3ff) + 0x10000).chr(Encoding::UTF_8)
1509
+ end
1510
+ }
1486
1511
  [:bytes,
1487
1512
  case bsqual
1488
1513
  when ""
@@ -1496,7 +1521,17 @@ module CDDL
1496
1521
  end
1497
1522
  ]
1498
1523
  else
1499
- val = eval(n.to_s)
1524
+ if s[-1] == '"'
1525
+ s.gsub!(/\\u([Dd][89AaBb][0-9a-zA-Z]{2})\\u([Dd][CcDdEeFf][0-9a-zA-Z]{2})|\\([^u]|u[0-9a-zA-Z]{4})/) {
1526
+ if $3
1527
+ "\\#$3" # skip this, use eval parser
1528
+ else
1529
+ ((($1.to_i(16) & 0x3ff) << 10) +
1530
+ ($2.to_i(16) & 0x3ff) + 0x10000).chr(Encoding::UTF_8)
1531
+ end
1532
+ }
1533
+ end
1534
+ val = eval(s)
1500
1535
  # warn val
1501
1536
  case val
1502
1537
  when Integer; [:int, val]
@@ -0,0 +1,12 @@
1
+ a = text .b64u bytes
2
+
3
+ ;;gp 10
4
+
5
+ ;;vp "AAAA"
6
+ ;;vp "AAA-"
7
+ ;;vp "AAA_"
8
+ ; fail with 0.11.5:
9
+ ;;vp "AAA+"
10
+ ;;vp "AAA/"
11
+ ;;vp "AAA="
12
+ ;;vp "+kd8"
@@ -0,0 +1,14 @@
1
+ terminal-color = &basecolors
2
+ basecolors = (
3
+ black: 0, red: 1, green: 2, yellow: 3,
4
+ blue: 4, magenta: 5, cyan: 6, white: 7,
5
+ reserved: (8..255) .feature "extension"
6
+ )
7
+ ; extended-color = &(
8
+ ; basecolors,
9
+ ; orange: 8, pink: 9, purple: 10, brown: 11,
10
+ ; )
11
+
12
+ ;;gp 10
13
+ ;;vp 42
14
+ ;;vp 433
@@ -0,0 +1,12 @@
1
+ terminal-color = $terminal-color / text .feature "extension"
2
+ $terminal-color /= &basecolors
3
+ basecolors = (
4
+ black: "black", red: "red", green: "green",
5
+ )
6
+
7
+ pastelcolors = ( pink: "pink", mauve: "mauve", peach: "peach", lavender: "lavender" )
8
+ $terminal-color /= &pastelcolors
9
+
10
+ ;;gp 10
11
+ ;;vp "florp"
12
+ ;;vp "lavender"
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
4
+ version: 0.12.1
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-13 00:00:00.000000000 Z
11
+ date: 2024-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cbor-diag
@@ -163,6 +163,7 @@ files:
163
163
  - test-data/b.cddl
164
164
  - test-data/b64c-sloppy.cddl
165
165
  - test-data/b64c.cddl
166
+ - test-data/b64u-strict.cddl
166
167
  - test-data/b64u.cddl
167
168
  - test-data/badaddr.cddl
168
169
  - test-data/base32.cddl
@@ -191,6 +192,8 @@ files:
191
192
  - test-data/dotplus3.cddl
192
193
  - test-data/dotplus4.cddl
193
194
  - test-data/dotsize.cddl
195
+ - test-data/enum.cddl
196
+ - test-data/enum1.cddl
194
197
  - test-data/extractor-demo.cddl
195
198
  - test-data/feat1.cddl
196
199
  - test-data/feature-controller.cddl
@@ -287,7 +290,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
287
290
  - !ruby/object:Gem::Version
288
291
  version: '0'
289
292
  requirements: []
290
- rubygems_version: 3.5.4
293
+ rubygems_version: 3.5.9
291
294
  signing_key:
292
295
  specification_version: 4
293
296
  summary: CDDL generator and validator.