-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from vaxxnz/feature/cbor-forks
Feature/cbor fix
- Loading branch information
Showing
8 changed files
with
58 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
diff --git a/node_modules/cbor/lib/encoder.js b/node_modules/cbor/lib/encoder.js | ||
index 6327959..288c692 100644 | ||
--- a/node_modules/cbor/lib/encoder.js | ||
+++ b/node_modules/cbor/lib/encoder.js | ||
@@ -509,6 +509,9 @@ Call removeLoopDetectors before resuming.`) | ||
if (typeof f === 'function') { | ||
return f.call(obj, this) | ||
} | ||
+ if (Buffer.isBuffer(obj)) { | ||
+ return this.semanticTypes[Buffer.name].call(obj, this, obj) | ||
+ } | ||
const converter = this.semanticTypes[obj.constructor.name] | ||
if (converter) { | ||
return converter.call(obj, this, obj) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
import { base32 } from "rfc4648"; | ||
import cbor from "cbor"; | ||
import { decodeCBOR } from "./cbor"; | ||
|
||
test("CBOR library works", async () => { | ||
const res = base32.parse( | ||
"2KCEVIQEIVVWK6JNGEASNICZAEP2KALYDZSGSZB2O5SWEOTOPJRXALTDN53GSZBRHEXGQZLBNR2GQLTOPICRUYMBTIFAIGTUKBAAUYTWMOSGQQDDN5XHIZLYOSBHQJTIOR2HA4Z2F4XXO53XFZ3TGLTPOJTS6MRQGE4C6Y3SMVSGK3TUNFQWY4ZPOYYXQKTIOR2HA4Z2F4XW46TDOAXGG33WNFSDCOJONBSWC3DUNAXG46RPMNXW45DFPB2HGL3WGFTXMZLSONUW63TFGEXDALRQMR2HS4DFQJ2FMZLSNFTGSYLCNRSUG4TFMRSW45DJMFWG6UDVMJWGSY2DN53GSZCQMFZXG4LDOJSWIZLOORUWC3CTOVRGUZLDOSRWSZ3JOZSW4TTBNVSWISTBMNVWUZTBNVUWY6KOMFWWKZ2TOBQXE4TPO5RWI33CNIYTSNRQFUYDILJRGYDVAYFE6VGU4MCDGK7DHLLYWHVPUS2YIDJOA6Y524TD3AZRM263WTY2BE4DPKIF27WKF3UDNNVSVWRDYIYVJ65IRJJJ6Z25M2DO4YZLBHWFQGVQR5ZLIWEQJOZTS3IQ7JTNCFDX" | ||
); | ||
|
||
const cborobj = cbor.decode(res); | ||
const cborobj = decodeCBOR(res); | ||
|
||
expect(cborobj.err).toEqual(undefined); | ||
expect(cborobj.tag).toEqual(18); | ||
expect(cborobj.value.length).toEqual(4); | ||
}); | ||
|
||
// TODO: test for cbor library encodes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// centralized place where cbor is included, in case we need to patch it | ||
|
||
import util from 'util'; | ||
// @ts-ignore | ||
global.TextDecoder = util.TextDecoder; | ||
// @ts-ignore | ||
global.TextEncoder = util.TextEncoder; | ||
|
||
import cbor from "cbor"; | ||
|
||
|
||
export const encodeCBOR = (obj: any): Buffer => { | ||
return cbor.encode(obj); | ||
} | ||
|
||
export const decodeCBOR = (buf: Buffer | Uint8Array): any => { | ||
return cbor.decode(buf); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters