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 +4 -4
- data/bin/cddl +15 -2
- data/cddl.gemspec +1 -1
- data/data/cddl.abnf +21 -9
- data/lib/cddl.rb +38 -3
- data/test-data/b64u-strict.cddl +2 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b6553d8156f74c2c630f22f6069c537e53b4f34a3d436df02ce73f99e648cb5
|
4
|
+
data.tar.gz: 175ddf07c82ef984d40c932eb80f8a8d7cdab54823777d8e9482239251756edc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
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
|
-
|
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 =
|
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 =
|
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 = ";" *
|
94
|
-
|
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(/\\(
|
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
|
-
|
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]
|
data/test-data/b64u-strict.cddl
CHANGED
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.
|
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-
|
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.
|
293
|
+
rubygems_version: 3.5.11
|
294
294
|
signing_key:
|
295
295
|
specification_version: 4
|
296
296
|
summary: CDDL generator and validator.
|