authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-02 13:39:28 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-02 13:39:28 -08:00
loga951b17d475ed3f64d8b0c3bf1c85efd049e705c
treea92fefac3042acf6d866d811da5fab75a6275253
parent7d475aab88647fc334988d27b3458f09d5c69710

turns out google authenticator does need &issuer param


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

test.zig+3-3
......@@ -45,17 +45,17 @@ test {
4545 const allocator = std.testing.allocator;
4646 const url = try totp.generateUrl(allocator, "ACME Co", "john.doe@email.com", &from_hex("3dc6caa4824a6d288767b2331e20b43166cb85d9"), .SHA1, 6, 30);
4747 defer allocator.free(url);
48 try expect(url).toEqualString("otpauth://totp/ACME%20Co:john.doe@email.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&algorithm=SHA1&digits=6&period=30");
48 try expect(url).toEqualString("otpauth://totp/ACME%20Co:john.doe@email.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&algorithm=SHA1&digits=6&period=30&issuer=ACME%20Co");
4949}
5050test {
5151 const allocator = std.testing.allocator;
5252 const url = try totp.generateUrl(allocator, "Example", "alice@google.com", &from_hex("48656c6c6f21deadbeef"), .SHA1, 6, 30);
5353 defer allocator.free(url);
54 try expect(url).toEqualString("otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&algorithm=SHA1&digits=6&period=30");
54 try expect(url).toEqualString("otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&algorithm=SHA1&digits=6&period=30&issuer=Example");
5555}
5656test {
5757 const allocator = std.testing.allocator;
5858 const url = try totp.generateUrl(allocator, "otpauth demo", "username@example.org", &from_hex("0000008421d6b5adef7bc6318ce739f7bdefffff"), .SHA1, 6, 30);
5959 defer allocator.free(url);
60 try expect(url).toEqualString("otpauth://totp/otpauth%20demo:username@example.org?secret=AAAABBBB22223333YYYYZZZZ66667777&algorithm=SHA1&digits=6&period=30");
60 try expect(url).toEqualString("otpauth://totp/otpauth%20demo:username@example.org?secret=AAAABBBB22223333YYYYZZZZ66667777&algorithm=SHA1&digits=6&period=30&issuer=otpauth%20demo");
6161}
totp.zig+2
......@@ -71,6 +71,8 @@ pub fn generateUrl(allocator: std.mem.Allocator, issuer: []const u8, account: []
7171 try list.writer().print("{d}", .{digits});
7272 try list.appendSlice("&period=");
7373 try list.writer().print("{d}", .{period});
74 try list.appendSlice("&issuer=");
75 try url.percentEncodeAL(&list, issuer, url.is_query_percent_char);
7476 return list.toOwnedSlice();
7577}
7678