Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 134 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"devDependencies": {
"@eslint/js": "^9.7.0",
"@ianvs/prettier-plugin-sort-imports": "^4.3.1",
"@types/cbor-js": "^0.1.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. :)

"@types/eslint__js": "^8.42.3",
"@types/mocha": "^10.0.7",
"@types/node": "^20.14.11",
Expand All @@ -53,7 +52,7 @@
},
"dependencies": {
"@peculiar/x509": "^1.11.0",
"cbor-js": "^0.1.0",
"cbor-x": "^1.5.9",
"crc-32": "^1.2.2",
"pkijs": "^3.2.1"
},
Expand Down
9 changes: 7 additions & 2 deletions src/cose/SigStructure.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import cbor from 'cbor-js';
import * as cbor from 'cbor-x';

export class SigStructure {
public readonly externalAAD: Uint8Array = new Uint8Array(0);
Expand All @@ -10,6 +10,11 @@ export class SigStructure {
) {}

public encode(): Uint8Array {
return new Uint8Array(cbor.encode([this.context, this.protectedBucket, this.externalAAD, this.payload]));
return new cbor.Encoder({ tagUint8Array: false }).encode([
this.context,
this.protectedBucket,
this.externalAAD,
this.payload,
]);
}
}
4 changes: 2 additions & 2 deletions src/cose/Signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
SubjectKeyIdentifierExtension,
X509Certificate,
} from '@peculiar/x509';
import cbor from 'cbor-js';
import * as cbor from 'cbor-x';
import { PKIStatus, SignedData, TimeStampResp, TSTInfo } from 'pkijs';
import { Crypto, ECDSANamedCurve, HashAlgorithm, SigningAlgorithm } from '../crypto';
import * as JUMBF from '../jumbf';
Expand All @@ -35,7 +35,7 @@ export class Signature {

let protectedBucket: ProtectedBucket | undefined;
try {
protectedBucket = cbor.decode(BinaryHelper.toArrayBuffer(rawContent[0])) as ProtectedBucket;
protectedBucket = cbor.decode(rawContent[0]) as ProtectedBucket;
} catch {
/* empty */
}
Expand Down
10 changes: 7 additions & 3 deletions src/jumbf/CBORBox.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import cbor from 'cbor-js';
import { BinaryHelper } from '../util';
import * as cbor from 'cbor-x';
import { Box } from './Box';

export class CBORBox extends Box {
Expand All @@ -14,7 +13,12 @@ export class CBORBox extends Box {
public parse(buf: Uint8Array) {
this.rawContent = buf;
try {
this.content = cbor.decode(BinaryHelper.toArrayBuffer(buf));
this.content = cbor.decode(buf);

// Ignore unknown CBOR tags
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really unknown: Some of the JPEGs have data with tag #18 here, which is COSE_Sign1 according to this list off assigned CBOR tags. I'll add this link in the typed-binary branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, unknown as in „unknown by cbor-x“. The COSE data is supposed to be tagged according to the COSE RFC.

if (this.content instanceof cbor.Tag) {
this.content = this.content.value;
}
} catch {
// TODO This needs to be properly reported as a validation error
throw new Error('CBORBox: Invalid CBOR data');
Expand Down