authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-09-12 00:03:38 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-09-12 00:03:38 -07:00
log54487dbd6b08763c681e6494b96279d2d86b86ca
tree2d034169b4d5ff3c6fcb186cc16f66f5cf7bed81
parentb506dd942bd1a43a89fb46ab9f3ca6386fc381e8

moved base64EncodeAlloc to zig-extras


2 files changed, 3 insertions(+), 7 deletions(-)

src/lib.zig+2-7
......@@ -8,6 +8,7 @@ const pek = @import("pek");
88const uri = @import("uri");
99const zfetch = @import("zfetch");
1010const json = @import("json");
11const extras = @import("extras");
1112
1213pub const Provider = struct {
1314 id: string,
......@@ -241,7 +242,7 @@ pub fn Handlers(comptime T: type) type {
241242
242243 var headers = zfetch.Headers.init(alloc);
243244 try headers.appendValue("Content-Type", "application/x-www-form-urlencoded");
244 try headers.appendValue("Authorization", try std.fmt.allocPrint(alloc, "Basic {s}", .{try base64EncodeAlloc(alloc, try std.mem.join(alloc, ":", &.{ client.id, client.secret }))}));
245 try headers.appendValue("Authorization", try std.fmt.allocPrint(alloc, "Basic {s}", .{try extras.base64EncodeAlloc(alloc, try std.mem.join(alloc, ":", &.{ client.id, client.secret }))}));
245246 try headers.appendValue("Accept", "application/json");
246247
247248 // TODO print error message to response if this fails
......@@ -310,12 +311,6 @@ fn fixId(alloc: *std.mem.Allocator, id: json.Value) !string {
310311 };
311312}
312313
313fn base64EncodeAlloc(alloc: *std.mem.Allocator, input: string) !string {
314 const base64 = std.base64.standard_encoder;
315 var buf = try alloc.alloc(u8, base64.calcSize(input.len));
316 return base64.encode(buf, input);
317}
318
319314//
320315//
321316
zig.mod+1
......@@ -12,3 +12,4 @@ dependencies:
1212 - src: git https://github.com/nektro/iguanaTLS # temporary
1313 - src: git https://github.com/truemedian/zfetch
1414 - src: git https://github.com/nektro/zig-json
15 - src: git https://github.com/nektro/zig-extras