diff --git a/test.zig b/test.zig index 4fcbcf8eb43173579dff6e78fc19e7639f753bed..c8b5ba1e9f2482c570c847409d36bd3191af3c9e 100644 --- a/test.zig +++ b/test.zig @@ -47,3 +47,9 @@ test { defer allocator.free(url); try expect(url).toEqualString("otpauth://totp/ACME%20Co:john.doe@email.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&algorithm=SHA1&digits=6&period=30"); } +test { + const allocator = std.testing.allocator; + const url = try totp.generateUrl(allocator, "Example", "alice@google.com", &from_hex("48656c6c6f21deadbeef"), .SHA1, 6, 30); + defer allocator.free(url); + try expect(url).toEqualString("otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&algorithm=SHA1&digits=6&period=30"); +} diff --git a/totp.zig b/totp.zig index 34107a9ad041e273aedd367e041f857911e0dac8..9e79855fc2420bf97d5f70f6be05e8010bff361f 100644 --- a/totp.zig +++ b/totp.zig @@ -53,7 +53,7 @@ pub const Algorithm = enum { pub fn generateUrl(allocator: std.mem.Allocator, issuer: []const u8, account: []const u8, secret_raw: []const u8, algo: Algorithm, digits: u8, period: u8) ![]const u8 { std.debug.assert(issuer.len > 0); std.debug.assert(account.len > 0); - std.debug.assert(secret_raw.len == algo.digest_length()); + std.debug.assert(secret_raw.len <= algo.digest_length()); std.debug.assert(digits == 6 or digits == 7 or digits == 8); std.debug.assert(period == 15 or period == 30 or period == 60); var list: std.ArrayList(u8) = .init(allocator);