authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-02-21 00:21:40 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-02-21 00:21:51 -08:00
log6a471164d811280f04d1574d6aade707d17c18e9
treef1ef85fef9ce5f6f9cf1ea953bd78720007485c7
parent11016cbb4dac6264b640b95f86742dba8bb8140d

add another test


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

test.zig+6
......@@ -47,3 +47,9 @@ test {
4747 defer allocator.free(url);
4848 try expect(url).toEqualString("otpauth://totp/ACME%20Co:john.doe@email.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&algorithm=SHA1&digits=6&period=30");
4949}
50test {
51 const allocator = std.testing.allocator;
52 const url = try totp.generateUrl(allocator, "Example", "alice@google.com", &from_hex("48656c6c6f21deadbeef"), .SHA1, 6, 30);
53 defer allocator.free(url);
54 try expect(url).toEqualString("otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&algorithm=SHA1&digits=6&period=30");
55}
totp.zig+1-1
......@@ -53,7 +53,7 @@ pub const Algorithm = enum {
5353pub fn generateUrl(allocator: std.mem.Allocator, issuer: []const u8, account: []const u8, secret_raw: []const u8, algo: Algorithm, digits: u8, period: u8) ![]const u8 {
5454 std.debug.assert(issuer.len > 0);
5555 std.debug.assert(account.len > 0);
56 std.debug.assert(secret_raw.len == algo.digest_length());
56 std.debug.assert(secret_raw.len <= algo.digest_length());
5757 std.debug.assert(digits == 6 or digits == 7 or digits == 8);
5858 std.debug.assert(period == 15 or period == 30 or period == 60);
5959 var list: std.ArrayList(u8) = .init(allocator);