| author | |
| committer | |
| log | 6a471164d811280f04d1574d6aade707d17c18e9 |
| tree | f1ef85fef9ce5f6f9cf1ea953bd78720007485c7 |
| parent | 11016cbb4dac6264b640b95f86742dba8bb8140d |
2 files changed, 7 insertions(+), 1 deletions(-)
test.zig+6| ... | ... | @@ -47,3 +47,9 @@ test { |
| 47 | 47 | defer allocator.free(url); |
| 48 | 48 | try expect(url).toEqualString("otpauth://totp/ACME%20Co:john.doe@email.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&algorithm=SHA1&digits=6&period=30"); |
| 49 | 49 | } |
| 50 | test { | |
| 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 { |
| 53 | 53 | 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 { |
| 54 | 54 | std.debug.assert(issuer.len > 0); |
| 55 | 55 | 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()); | |
| 57 | 57 | std.debug.assert(digits == 6 or digits == 7 or digits == 8); |
| 58 | 58 | std.debug.assert(period == 15 or period == 30 or period == 60); |
| 59 | 59 | var list: std.ArrayList(u8) = .init(allocator); |