mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
Fixes base64url encoding for crypto (#3654)
* Fixes base64url encoding for crypto * 🍏 * Update nodejs-apis.md --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
@@ -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.
|
||||
- 🟢
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user