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");...@@ -8,6 +8,7 @@ const pek = @import("pek");
8const uri = @import("uri");8const uri = @import("uri");
9const zfetch = @import("zfetch");9const zfetch = @import("zfetch");
10const json = @import("json");10const json = @import("json");
11const extras = @import("extras");
1112
12pub const Provider = struct {13pub const Provider = struct {
13 id: string,14 id: string,
...@@ -241,7 +242,7 @@ pub fn Handlers(comptime T: type) type {...@@ -241,7 +242,7 @@ pub fn Handlers(comptime T: type) type {
241242
242 var headers = zfetch.Headers.init(alloc);243 var headers = zfetch.Headers.init(alloc);
243 try headers.appendValue("Content-Type", "application/x-www-form-urlencoded");244 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 }))}));
245 try headers.appendValue("Accept", "application/json");246 try headers.appendValue("Accept", "application/json");
246247
247 // TODO print error message to response if this fails248 // TODO print error message to response if this fails
...@@ -310,12 +311,6 @@ fn fixId(alloc: *std.mem.Allocator, id: json.Value) !string {...@@ -310,12 +311,6 @@ fn fixId(alloc: *std.mem.Allocator, id: json.Value) !string {
310 };311 };
311}312}
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
319//314//
320//315//
321316
zig.mod+1
...@@ -12,3 +12,4 @@ dependencies:...@@ -12,3 +12,4 @@ dependencies:
12 - src: git https://github.com/nektro/iguanaTLS # temporary12 - src: git https://github.com/nektro/iguanaTLS # temporary
13 - src: git https://github.com/truemedian/zfetch13 - src: git https://github.com/truemedian/zfetch
14 - src: git https://github.com/nektro/zig-json14 - src: git https://github.com/nektro/zig-json
15 - src: git https://github.com/nektro/zig-extras