Skip to content

Commit

Permalink
Merge pull-request #45
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewkmin committed Jul 25, 2024
2 parents 29f5a45 + c01a4fa commit bd88ec0
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion auth/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ <h2>Message log</h2>
var uint8arrayFromHexString = function(hexString, length) {
var hexRegex = /^[0-9A-Fa-f]+$/;
if (!hexString || hexString.length % 2 != 0 || !hexRegex.test(hexString)) {
throw new Error('cannot create uint8array from invalid hex string: "' + hexString + '"');
throw new Error('cannot create uint8array from invalid hex string');
}
var buffer = new Uint8Array(hexString.match(/../g).map((h) => parseInt(h, 16)));
if (!length) {
Expand Down
8 changes: 4 additions & 4 deletions auth/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,19 @@ describe("TKHQ", () => {
// Error case: bad value
expect(() => {
TKHQ.uint8arrayFromHexString({});
}).toThrow('cannot create uint8array from invalid hex string: "[object Object]"');
}).toThrow('cannot create uint8array from invalid hex string');
// Error case: empty string
expect(() => {
TKHQ.uint8arrayFromHexString("");
}).toThrow('cannot create uint8array from invalid hex string: ""');
}).toThrow('cannot create uint8array from invalid hex string');
// Error case: odd number of characters
expect(() => {
TKHQ.uint8arrayFromHexString("123");
}).toThrow('cannot create uint8array from invalid hex string: "123"');
}).toThrow('cannot create uint8array from invalid hex string');
// Error case: bad characters outside of hex range
expect(() => {
TKHQ.uint8arrayFromHexString("oops");
}).toThrow('cannot create uint8array from invalid hex string: "oops"');
}).toThrow('cannot create uint8array from invalid hex string');
// Happy path: if length parameter is included, pad the resulting buffer
expect(TKHQ.uint8arrayFromHexString("01", 2).toString()).toEqual("0,1");
// Happy path: if length parameter is omitted, do not pad the resulting buffer
Expand Down
2 changes: 1 addition & 1 deletion export/index.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ <h2>Message log</h2>
function uint8arrayFromHexString(hexString) {
var hexRegex = /^[0-9A-Fa-f]+$/;
if (!hexString || hexString.length % 2 != 0 || !hexRegex.test(hexString)) {
throw new Error('cannot create uint8array from invalid hex string: "' + hexString + '"');
throw new Error('cannot create uint8array from invalid hex string');
}
return new Uint8Array(hexString.match(/../g).map(h=>parseInt(h,16)));
}
Expand Down
12 changes: 6 additions & 6 deletions export/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,19 @@ describe("TKHQ", () => {
// Error case: bad value
expect(() => {
TKHQ.uint8arrayFromHexString({});
}).toThrow('cannot create uint8array from invalid hex string: "[object Object]"');
}).toThrow('cannot create uint8array from invalid hex string');
// Error case: empty string
expect(() => {
TKHQ.uint8arrayFromHexString("");
}).toThrow('cannot create uint8array from invalid hex string: ""');
}).toThrow('cannot create uint8array from invalid hex string');
// Error case: odd number of characters
expect(() => {
TKHQ.uint8arrayFromHexString("123");
}).toThrow('cannot create uint8array from invalid hex string: "123"');
}).toThrow('cannot create uint8array from invalid hex string');
// Error case: bad characters outside of hex range
expect(() => {
TKHQ.uint8arrayFromHexString("oops");
}).toThrow('cannot create uint8array from invalid hex string: "oops"');
}).toThrow('cannot create uint8array from invalid hex string');
})

it("logs messages and sends messages up", async () => {
Expand Down Expand Up @@ -227,11 +227,11 @@ describe("TKHQ", () => {
// Invalid hex-encoding for signature
await expect(
TKHQ.verifyEnclaveSignature(null, "", "04d32d8e0fe5a401a717971fabfabe02ddb6bea39b72a18a415fc0273579b394650aae97f75b0462ffa8880a1899c7a930569974519685a995d2e74e372e105bf4")
).rejects.toThrow('cannot create uint8array from invalid hex string: ""');
).rejects.toThrow('cannot create uint8array from invalid hex string');

// Invalid hex-encoding for public key
await expect(
TKHQ.verifyEnclaveSignature(null, "30440220773382ac39085f58a584fd5ad8c8b91b50993ad480af2c5eaefe0b09447b6dca02205201c8e20a92bce524caac08a956b0c2e7447de9c68f91ab1e09fd58988041b5", "")
).rejects.toThrow('cannot create uint8array from invalid hex string: ""');
).rejects.toThrow('cannot create uint8array from invalid hex string');
})
});
2 changes: 1 addition & 1 deletion import/index.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
function uint8arrayFromHexString(hexString) {
var hexRegex = /^[0-9A-Fa-f]+$/;
if (!hexString || hexString.length % 2 != 0 || !hexRegex.test(hexString)) {
throw new Error('cannot create uint8array from invalid hex string: "' + hexString + '"');
throw new Error('cannot create uint8array from invalid hex string');
}
return new Uint8Array(hexString.match(/../g).map(h=>parseInt(h,16)));
}
Expand Down
4 changes: 2 additions & 2 deletions import/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ describe("TKHQ", () => {
// Invalid hex-encoding for signature
await expect(
TKHQ.verifyEnclaveSignature(null, "", "04d32d8e0fe5a401a717971fabfabe02ddb6bea39b72a18a415fc0273579b394650aae97f75b0462ffa8880a1899c7a930569974519685a995d2e74e372e105bf4")
).rejects.toThrow('cannot create uint8array from invalid hex string: ""');
).rejects.toThrow('cannot create uint8array from invalid hex string');

// Invalid hex-encoding for public key
await expect(
TKHQ.verifyEnclaveSignature(null, "30440220773382ac39085f58a584fd5ad8c8b91b50993ad480af2c5eaefe0b09447b6dca02205201c8e20a92bce524caac08a956b0c2e7447de9c68f91ab1e09fd58988041b5", "")
).rejects.toThrow('cannot create uint8array from invalid hex string: ""');
).rejects.toThrow('cannot create uint8array from invalid hex string');
})

it("validates styles", async () => {
Expand Down
2 changes: 1 addition & 1 deletion import/standalone.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ <h2>Message log</h2>
function uint8arrayFromHexString(hexString) {
var hexRegex = /^[0-9A-Fa-f]+$/;
if (!hexString || hexString.length % 2 != 0 || !hexRegex.test(hexString)) {
throw new Error('cannot create uint8array from invalid hex string: "' + hexString + '"');
throw new Error('cannot create uint8array from invalid hex string');
}
return new Uint8Array(hexString.match(/../g).map(h=>parseInt(h,16)));
}
Expand Down

0 comments on commit bd88ec0

Please sign in to comment.