diff options
-rw-r--r-- | docs/runtime/nodejs-apis.md | 3 | ||||
-rw-r--r-- | src/bun.js/node/types.zig | 17 | ||||
-rw-r--r-- | test/js/node/crypto/node-crypto.test.js | 4 |
3 files changed, 11 insertions, 13 deletions
diff --git a/docs/runtime/nodejs-apis.md b/docs/runtime/nodejs-apis.md index db4844b7e..79b01ebff 100644 --- a/docs/runtime/nodejs-apis.md +++ b/docs/runtime/nodejs-apis.md @@ -26,8 +26,7 @@ This page is updated regularly to reflect compatibility status of the latest ver --- - {% anchor id="node_buffer" %} [`node:buffer`](https://nodejs.org/api/buffer.html) {% /anchor %} -- 🟡 -- Incomplete implementation of `base64` and `base64url` encodings. +- 🟢 --- diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig index e035c01a6..0b19c7fcc 100644 --- a/src/bun.js/node/types.zig +++ b/src/bun.js/node/types.zig @@ -528,12 +528,10 @@ pub const Encoding = enum(u8) { return JSC.ZigString.init(base64[0..len]).toValueGC(globalThis); }, .base64url => { - var buf: [std.base64.url_safe.Encoder.calcSize(size) + "data:;base64,".len]u8 = undefined; - var encoded = std.base64.url_safe.Encoder.encode(buf["data:;base64,".len..], input); - buf[0.."data:;base64,".len].* = "data:;base64,".*; + var buf: [std.base64.url_safe_no_pad.Encoder.calcSize(size)]u8 = undefined; + var encoded = std.base64.url_safe_no_pad.Encoder.encode(&buf, input); - const result = JSC.ZigString.init(buf[0 .. "data:;base64,".len + encoded.len]).toValueGC(globalThis); - return result; + return JSC.ZigString.init(buf[0..encoded.len]).toValueGC(globalThis); }, .hex => { var buf: [size * 4]u8 = undefined; @@ -566,13 +564,10 @@ pub const Encoding = enum(u8) { return result; }, .base64url => { - var buf_: [std.base64.url_safe.Encoder.calcSize(max_size) + "data:;base64,".len]u8 = undefined; - var buf = buf_[0 .. std.base64.url_safe.Encoder.calcSize(size) + "data:;base64,".len]; - var encoded = std.base64.url_safe.Encoder.encode(buf["data:;base64,".len..], input); - buf[0.."data:;base64,".len].* = "data:;base64,".*; + var buf: [std.base64.url_safe_no_pad.Encoder.calcSize(max_size)]u8 = undefined; + var encoded = std.base64.url_safe_no_pad.Encoder.encode(&buf, input); - const result = JSC.ZigString.init(buf[0 .. "data:;base64,".len + encoded.len]).toValueGC(globalThis); - return result; + return JSC.ZigString.init(buf[0..encoded.len]).toValueGC(globalThis); }, .hex => { var buf: [max_size * 4]u8 = undefined; diff --git a/test/js/node/crypto/node-crypto.test.js b/test/js/node/crypto/node-crypto.test.js index 2489f96c7..8db87d9f3 100644 --- a/test/js/node/crypto/node-crypto.test.js +++ b/test/js/node/crypto/node-crypto.test.js @@ -59,6 +59,10 @@ describe("createHash", () => { 97, 105, 50, 105, 67, 85, 79, 84, 72, 112, 103, 48, 47, 66, 76, 80, 53, 98, 116, 72, 117, 57, 109, 117, 81, 48, 105, 97, 77, 72, 74, 112, 89, 114, 86, 50, 57, 79, 79, 90, 80, 108, 65, 61, ], + base64url: [ + 97, 105, 50, 105, 67, 85, 79, 84, 72, 112, 103, 48, 95, 66, 76, 80, 53, 98, 116, 72, 117, 57, 109, 117, 81, 48, + 105, 97, 77, 72, 74, 112, 89, 114, 86, 50, 57, 79, 79, 90, 80, 108, 65, + ], hex: [ 54, 97, 50, 100, 97, 50, 48, 57, 52, 51, 57, 51, 49, 101, 57, 56, 51, 52, 102, 99, 49, 50, 99, 102, 101, 53, 98, 98, 52, 55, 98, 98, 100, 57, 97, 101, 52, 51, 52, 56, 57, 97, 51, 48, 55, 50, 54, 57, 54, 50, 98, 53, 55, 54, 102, |