From 878e5b1b648512317a01c838005cc7dbed475ee0 Mon Sep 17 00:00:00 2001 From: Orie Steele Date: Mon, 15 Apr 2024 14:45:21 -0500 Subject: [PATCH] fix render bug --- src/__fixtures__/ecdsa-examples/ecdsa-sig-02.txt | 10 ---------- src/render.ts | 2 +- tests/cose-sign1.test.ts | 15 +++++++++++++++ tests/render.test.ts | 12 ------------ 4 files changed, 16 insertions(+), 23 deletions(-) delete mode 100644 src/__fixtures__/ecdsa-examples/ecdsa-sig-02.txt delete mode 100644 tests/render.test.ts diff --git a/src/__fixtures__/ecdsa-examples/ecdsa-sig-02.txt b/src/__fixtures__/ecdsa-examples/ecdsa-sig-02.txt deleted file mode 100644 index 307f8c2..0000000 --- a/src/__fixtures__/ecdsa-examples/ecdsa-sig-02.txt +++ /dev/null @@ -1,10 +0,0 @@ -/ cose-sign1 / 18([ - / protected / << { - / alg / 1 : -35 / ES384 / - } >>>, - / unprotected / { - / kid / 4 : h'50333834' - }, - / payload / h'54686973...656e742e', - / signature / h'5f150abd...59622a3c' -]) \ No newline at end of file diff --git a/src/render.ts b/src/render.ts index 6c3c765..3f0bc2b 100644 --- a/src/render.ts +++ b/src/render.ts @@ -58,7 +58,7 @@ const renderSeqPlaintext = async (seq: EDNSeq): Promise => { value.iana = algs.IANACOSEHeaderParameters[`${value.value}`] } } - entry.edn = `/ protected / << ${await renderMapPlaintext(protectedHeader)} >>>` + entry.edn = `/ protected / << ${await renderMapPlaintext(protectedHeader)} >>` } return `${entry.edn ? ' ' + entry.edn : await recursiveRenderPlaintext(entry)}${trailingComma}`; }))).join('\n'); diff --git a/tests/cose-sign1.test.ts b/tests/cose-sign1.test.ts index 3a94c53..6e77f71 100644 --- a/tests/cose-sign1.test.ts +++ b/tests/cose-sign1.test.ts @@ -9,4 +9,19 @@ it(testCase.title, async () => { expect(graph1.seq.get(0).value.toString('hex')).toBe('a1013822') const graph2 = await edn.parse(Buffer.from(testCase.output.cbor, 'hex')) as edn.EDNCoseSign1 expect(graph2.seq.get(0).value.toString('hex')).toBe('a1013822') + + const text = await edn.render(Buffer.from(testCase.output.cbor, 'hex'), 'application/cbor-diagnostic') + expect(text).toBe(` +/ cose-sign1 / 18([ + / protected / << { + / alg / 1 : -35 / ES384 / + } >>, + / unprotected / { + / kid / 4 : h'50333834' + }, + / payload / h'54686973...656e742e', + / signature / h'5f150abd...59622a3c' +]) + `.trim()) + }) diff --git a/tests/render.test.ts b/tests/render.test.ts deleted file mode 100644 index 19a581a..0000000 --- a/tests/render.test.ts +++ /dev/null @@ -1,12 +0,0 @@ -import fs from 'fs' - -import * as edn from '../src' - -const testCase = JSON.parse(fs.readFileSync('./src/__fixtures__/ecdsa-examples/ecdsa-sig-02.json').toString()) - -it(testCase.title, async () => { - const message = Buffer.from(testCase.output.cbor, 'hex'); - const text = await edn.render(message, 'application/cbor-diagnostic') - expect(text).toBe(fs.readFileSync(`./src/__fixtures__/ecdsa-examples/ecdsa-sig-02.txt`).toString()) - fs.writeFileSync(`./src/__fixtures__/ecdsa-examples/ecdsa-sig-02.txt`, text) -})