From 54487dbd6b08763c681e6494b96279d2d86b86ca Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sun, 12 Sep 2021 00:03:38 -0700 Subject: [PATCH] moved base64EncodeAlloc to zig-extras --- src/lib.zig | 9 ++------- zig.mod | 1 + 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/lib.zig b/src/lib.zig index f26bc9eff62f3a2660c42976f393c8e71cec9646..50a13b93cd3b1a61c9c0000e1f756bed1108b46e 100644 --- a/src/lib.zig +++ b/src/lib.zig @@ -8,6 +8,7 @@ const pek = @import("pek"); const uri = @import("uri"); const zfetch = @import("zfetch"); const json = @import("json"); +const extras = @import("extras"); pub const Provider = struct { id: string, @@ -241,7 +242,7 @@ pub fn Handlers(comptime T: type) type { var headers = zfetch.Headers.init(alloc); try headers.appendValue("Content-Type", "application/x-www-form-urlencoded"); - try headers.appendValue("Authorization", try std.fmt.allocPrint(alloc, "Basic {s}", .{try base64EncodeAlloc(alloc, try std.mem.join(alloc, ":", &.{ client.id, client.secret }))})); + try headers.appendValue("Authorization", try std.fmt.allocPrint(alloc, "Basic {s}", .{try extras.base64EncodeAlloc(alloc, try std.mem.join(alloc, ":", &.{ client.id, client.secret }))})); try headers.appendValue("Accept", "application/json"); // TODO print error message to response if this fails @@ -310,12 +311,6 @@ fn fixId(alloc: *std.mem.Allocator, id: json.Value) !string { }; } -fn base64EncodeAlloc(alloc: *std.mem.Allocator, input: string) !string { - const base64 = std.base64.standard_encoder; - var buf = try alloc.alloc(u8, base64.calcSize(input.len)); - return base64.encode(buf, input); -} - // // diff --git a/zig.mod b/zig.mod index 73eea57a4806dd2f26463ae4f92094c891e09b1e..7dde75a8600aa6b3f1eaca79412b3ee422501fc5 100644 --- a/zig.mod +++ b/zig.mod @@ -12,3 +12,4 @@ dependencies: - src: git https://github.com/nektro/iguanaTLS # temporary - src: git https://github.com/truemedian/zfetch - src: git https://github.com/nektro/zig-json + - src: git https://github.com/nektro/zig-extras -- 2.54.0