Skip to content

Commit 2fe481c

Browse files
Add the CBOR Object Signing and Encryption tags (RFC 8152)
This also adds #defines for the CborXxxTag identifiers so user code can Signed-off-by: Thiago Macieira <[email protected]>
1 parent 15dfacf commit 2fe481c

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

src/cbor.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ typedef enum CborKnownTags {
103103
CborNegativeBignumTag = 3,
104104
CborDecimalTag = 4,
105105
CborBigfloatTag = 5,
106+
CborCOSE_Encrypt0Tag = 16,
107+
CborCOSE_Mac0Tag = 17,
108+
CborCOSE_Sign1Tag = 18,
106109
CborExpectedBase64urlTag = 21,
107110
CborExpectedBase64Tag = 22,
108111
CborExpectedBase16Tag = 23,
@@ -112,9 +115,36 @@ typedef enum CborKnownTags {
112115
CborBase64Tag = 34,
113116
CborRegularExpressionTag = 35,
114117
CborMimeMessageTag = 36,
118+
CborCOSE_EncryptTag = 96,
119+
CborCOSE_MacTag = 97,
120+
CborCOSE_SignTag = 98,
115121
CborSignatureTag = 55799
116122
} CborKnownTags;
117123

124+
/* #define the constants so we can check with #ifdef */
125+
#define CborDateTimeStringTag CborDateTimeStringTag
126+
#define CborUnixTime_tTag CborUnixTime_tTag
127+
#define CborPositiveBignumTag CborPositiveBignumTag
128+
#define CborNegativeBignumTag CborNegativeBignumTag
129+
#define CborDecimalTag CborDecimalTag
130+
#define CborBigfloatTag CborBigfloatTag
131+
#define CborCOSE_Encrypt0Tag CborCOSE_Encrypt0Tag
132+
#define CborCOSE_Mac0Tag CborCOSE_Mac0Tag
133+
#define CborCOSE_Sign1Tag CborCOSE_Sign1Tag
134+
#define CborExpectedBase64urlTag CborExpectedBase64urlTag
135+
#define CborExpectedBase64Tag CborExpectedBase64Tag
136+
#define CborExpectedBase16Tag CborExpectedBase16Tag
137+
#define CborEncodedCborTag CborEncodedCborTag
138+
#define CborUrlTag CborUrlTag
139+
#define CborBase64urlTag CborBase64urlTag
140+
#define CborBase64Tag CborBase64Tag
141+
#define CborRegularExpressionTag CborRegularExpressionTag
142+
#define CborMimeMessageTag CborMimeMessageTag
143+
#define CborCOSE_EncryptTag CborCOSE_EncryptTag
144+
#define CborCOSE_MacTag CborCOSE_MacTag
145+
#define CborCOSE_SignTag CborCOSE_SignTag
146+
#define CborSignatureTag CborSignatureTag
147+
118148
/* Error API */
119149

120150
typedef enum CborError {

src/cborvalidation.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,21 @@
153153
<td>array</td>
154154
<td>Bigfloat</td>
155155
</td>
156+
<tr>
157+
<td>16</td>
158+
<td>array</td>
159+
<td>COSE Single Recipient Encrypted Data Object (RFC 8152)</td>
160+
</td>
161+
<tr>
162+
<td>17</td>
163+
<td>array</td>
164+
<td>COSE Mac w/o Recipients Object (RFC 8152)</td>
165+
</td>
166+
<tr>
167+
<td>18</td>
168+
<td>array</td>
169+
<td>COSE Single Signer Data Object (RFC 8162)</td>
170+
</td>
156171
<tr>
157172
<td>21</td>
158173
<td>byte string, array, map</td>
@@ -198,6 +213,21 @@
198213
<td>UTF-8 text string</td>
199214
<td>MIME message</td>
200215
</td>
216+
<tr>
217+
<td>96</td>
218+
<td>array</td>
219+
<td>COSE Encrypted Data Object (RFC 8152)</td>
220+
</td>
221+
<tr>
222+
<td>97</td>
223+
<td>array</td>
224+
<td>COSE MACed Data Object (RFC 8152)</td>
225+
</td>
226+
<tr>
227+
<td>98</td>
228+
<td>array</td>
229+
<td>COSE Signed Data Object (RFC 8152)</td>
230+
</td>
201231
<tr>
202232
<td>55799</td>
203233
<td>any</td>
@@ -214,6 +244,9 @@ static const struct KnownTagData knownTagData[] = {
214244
{ 3, (uint8_t)CborByteStringType },
215245
{ 4, (uint8_t)CborArrayType },
216246
{ 5, (uint8_t)CborArrayType },
247+
{ 16, (uint8_t)CborArrayType },
248+
{ 17, (uint8_t)CborArrayType },
249+
{ 18, (uint8_t)CborArrayType },
217250
{ 21, (uint8_t)CborByteStringType | ((uint8_t)CborArrayType << 8) | ((uint8_t)CborMapType << 16) },
218251
{ 22, (uint8_t)CborByteStringType | ((uint8_t)CborArrayType << 8) | ((uint8_t)CborMapType << 16) },
219252
{ 23, (uint8_t)CborByteStringType | ((uint8_t)CborArrayType << 8) | ((uint8_t)CborMapType << 16) },
@@ -223,6 +256,9 @@ static const struct KnownTagData knownTagData[] = {
223256
{ 34, (uint8_t)CborTextStringType },
224257
{ 35, (uint8_t)CborTextStringType },
225258
{ 36, (uint8_t)CborTextStringType },
259+
{ 96, (uint8_t)CborArrayType },
260+
{ 97, (uint8_t)CborArrayType },
261+
{ 98, (uint8_t)CborArrayType },
226262
{ 55799, 0U }
227263
};
228264

src/parsetags.pl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@
8585
$comma = ",";
8686
}
8787
print "\n} CborKnownTags;";
88+
print "\n/* #define the constants so we can check with #ifdef */";
89+
for my $n (@tagnumbers) {
90+
printf "#define Cbor%sTag Cbor%sTag\n", $tags{$n}{id}, $tags{$n}{id};
91+
}
8892

8993
print "\n==== search table ====\n";
9094
print "struct KnownTagData { uint32_t tag; uint32_t types; };";

src/tags.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
3;NegativeBignum;ByteString;Negative bignum
66
4;Decimal;Array;Decimal fraction
77
5;Bigfloat;Array;Bigfloat
8+
16;COSE_Encrypt0;Array;COSE Single Recipient Encrypted Data Object (RFC 8152)
9+
17;COSE_Mac0;Array;COSE Mac w/o Recipients Object (RFC 8152)
10+
18;COSE_Sign1;Array;COSE Single Signer Data Object (RFC 8162)
811
21;ExpectedBase64url;ByteString,Array,Map;Expected conversion to base64url encoding
912
22;ExpectedBase64;ByteString,Array,Map;Expected conversion to base64 encoding
1013
23;ExpectedBase16;ByteString,Array,Map;Expected conversion to base16 encoding
@@ -14,4 +17,7 @@
1417
34;Base64;TextString;base64
1518
35;RegularExpression;TextString;Regular expression
1619
36;MimeMessage;TextString;MIME message
20+
96;COSE_Encrypt;Array;COSE Encrypted Data Object (RFC 8152)
21+
97;COSE_Mac;Array;COSE MACed Data Object (RFC 8152)
22+
98;COSE_Sign;Array;COSE Signed Data Object (RFC 8152)
1723
55799;Signature;;Self-describe CBOR

0 commit comments

Comments
 (0)