cddl 0.11.5 → 0.12.2

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: 652f1e63847fbed19fceeca1ed0b695b25b5f8aa6d312b2bd17f21c0ac7c6549
4
- data.tar.gz: d55f4a0bff69a37b1c6101b11eb003eb93c00df24ede1dded8d7be9844b4afb1
3
+ metadata.gz: 4b6553d8156f74c2c630f22f6069c537e53b4f34a3d436df02ce73f99e648cb5
4
+ data.tar.gz: 175ddf07c82ef984d40c932eb80f8a8d7cdab54823777d8e9482239251756edc
5
5
  SHA512:
6
- metadata.gz: 6622daf044d0f5a6d0ce4fe90ac57341526f7723aef0ce49e228edd2284711a44302ab0c3a1a28e3e156676db61afb4477a9b97b27269e1509034c41796ca8b9
7
- data.tar.gz: 966fd633edc283925e0e4bbb5ca04cb40de60470044bbbd94e7df41fb05c185f59ff09ae4767d5dea2899491d3f82db50d3feb01a585fe03891d60f073e50557
6
+ metadata.gz: 357a054cb881ab89c00befe26adfcbf9999b8cbd19f400bdd31eccc39a0eb690e50f4552fc446dfa364086987e1187638983e3579e1a3e06084eb874e1311509
7
+ data.tar.gz: bf8e429cf02926f4c078e7911d73ccffb47ee3c96520f627e33673333061cd85b472e3795a122362fe615c7b73f8ac2ad6ac02290c5f9a0a9ba19ebe3b15fae6
data/bin/cddl CHANGED
@@ -22,6 +22,13 @@ def usage
22
22
  exit EX_USAGE
23
23
  end
24
24
 
25
+ def utfify(s)
26
+ s.force_encoding(Encoding::UTF_8).scrub { |c|
27
+ warn "*** replaced invalid UTF-8 byte sequence #{c.inspect} by U+FFFD REPLACEMENT CHARACTER"
28
+ 0xFFFD.chr(Encoding::UTF_8)
29
+ }
30
+ end
31
+
25
32
  def read_arg(arg, remember_fn = true)
26
33
  if arg == "-"
27
34
  $fn = "(stdin)" if remember_fn
@@ -34,7 +41,7 @@ def read_arg(arg, remember_fn = true)
34
41
  end
35
42
 
36
43
  def parser
37
- @parser ||= CDDL::Parser.new(read_arg(ARGV[0], false))
44
+ @parser ||= CDDL::Parser.new(utfify(read_arg(ARGV[0], false)))
38
45
  end
39
46
 
40
47
  def my_pp(v)
@@ -99,7 +106,12 @@ begin
99
106
  instance = if $sequence
100
107
  CBOR.decode("\x9f".b << instance.b << "\xff".b)
101
108
  else
102
- CBOR.decode(instance.b) rescue JSON.load(instance)
109
+ begin
110
+ CBOR.decode(instance.b)
111
+ rescue => e
112
+ warn e.inspect if verbose
113
+ JSON.load(utfify(instance))
114
+ end
103
115
  end
104
116
  instance = instance.cbor_clone if $annotate && ENV["EXPERIMENTAL_ANNOTATE"]
105
117
  warn "#{fn}:" if verbose
@@ -107,6 +119,7 @@ begin
107
119
  # my_pp ann
108
120
  instance.cbor_add_annotations_from(ann) rescue nil
109
121
  my_diag(instance) if $annotate
122
+ warn "ann: #{!!ann}" if verbose
110
123
  unless ann
111
124
  retcode = 1
112
125
  end
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.5'
3
+ s.version = '0.12.2'
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#{
@@ -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]
@@ -5,6 +5,8 @@ a = text .b64u bytes
5
5
  ;;vp "AAAA"
6
6
  ;;vp "AAA-"
7
7
  ;;vp "AAA_"
8
+ ; fail with 0.11.5:
8
9
  ;;vp "AAA+"
9
10
  ;;vp "AAA/"
10
11
  ;;vp "AAA="
12
+ ;;vp "+kd8"
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.5
4
+ version: 0.12.2
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-15 00:00:00.000000000 Z
11
+ date: 2024-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cbor-diag
@@ -290,7 +290,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
290
290
  - !ruby/object:Gem::Version
291
291
  version: '0'
292
292
  requirements: []
293
- rubygems_version: 3.5.4
293
+ rubygems_version: 3.5.11
294
294
  signing_key:
295
295
  specification_version: 4
296
296
  summary: CDDL generator and validator.