Skip to content

Commit

Permalink
Fixes #14684
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Oct 19, 2024
1 parent 33af9cd commit e447ed0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/bun.js/api/BunObject.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1221,9 +1221,10 @@ pub const Crypto = struct {
pub usingnamespace bun.New(@This());

pub fn init(algorithm: EVP.Algorithm, key: []const u8) ?*HMAC {
const md = algorithm.md() orelse return null;
var ctx: BoringSSL.HMAC_CTX = undefined;
BoringSSL.HMAC_CTX_init(&ctx);
if (BoringSSL.HMAC_Init_ex(&ctx, key.ptr, @intCast(key.len), algorithm.md(), null) != 1) {
if (BoringSSL.HMAC_Init_ex(&ctx, key.ptr, @intCast(key.len), md, null) != 1) {
BoringSSL.HMAC_CTX_cleanup(&ctx);
return null;
}
Expand Down Expand Up @@ -2714,7 +2715,7 @@ pub const Crypto = struct {
BoringSSL.ERR_clear_error();
globalThis.throwValue(instance);
} else {
globalThis.throwTODO("HMAC is not supported for this algorithm");
globalThis.throwTODO("HMAC is not supported for this algorithm yet");
}
}
return null;
Expand Down
14 changes: 12 additions & 2 deletions test/js/bun/util/bun-cryptohasher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,18 @@ describe("HMAC", () => {
});
}

test("ripemd160 is not supported", () => {
expect(() => new Bun.CryptoHasher("ripemd160", "key")).toThrow();
const unsupported = [
["sha3-224"],
["sha3-256"],
["sha3-384"],
["sha3-512"],
["shake128"],
["shake256"],
["ripemd160"],
] as const;
test.each(unsupported)("%s is not supported", algorithm => {
expect(() => new Bun.CryptoHasher(algorithm, "key")).toThrow();
expect(() => new Bun.CryptoHasher(algorithm)).not.toThrow();
});
});

Expand Down

0 comments on commit e447ed0

Please sign in to comment.