diff --git a/test.zig b/test.zig index f9855a690b8dd1b6bda5fb9123927a1010c42b3a..b1bc6394085a6c3e00f9c3ac28c6d38ae83b227c 100644 --- a/test.zig +++ b/test.zig @@ -45,17 +45,17 @@ test { const allocator = std.testing.allocator; const url = try totp.generateUrl(allocator, "ACME Co", "john.doe@email.com", &from_hex("3dc6caa4824a6d288767b2331e20b43166cb85d9"), .SHA1, 6, 30); defer allocator.free(url); - try expect(url).toEqualString("otpauth://totp/ACME%20Co:john.doe@email.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&algorithm=SHA1&digits=6&period=30"); + try expect(url).toEqualString("otpauth://totp/ACME%20Co:john.doe@email.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&algorithm=SHA1&digits=6&period=30&issuer=ACME%20Co"); } 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"); + try expect(url).toEqualString("otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&algorithm=SHA1&digits=6&period=30&issuer=Example"); } test { const allocator = std.testing.allocator; const url = try totp.generateUrl(allocator, "otpauth demo", "username@example.org", &from_hex("0000008421d6b5adef7bc6318ce739f7bdefffff"), .SHA1, 6, 30); defer allocator.free(url); - try expect(url).toEqualString("otpauth://totp/otpauth%20demo:username@example.org?secret=AAAABBBB22223333YYYYZZZZ66667777&algorithm=SHA1&digits=6&period=30"); + try expect(url).toEqualString("otpauth://totp/otpauth%20demo:username@example.org?secret=AAAABBBB22223333YYYYZZZZ66667777&algorithm=SHA1&digits=6&period=30&issuer=otpauth%20demo"); } diff --git a/totp.zig b/totp.zig index 9e79855fc2420bf97d5f70f6be05e8010bff361f..2396a2659c300e384b93159fc87fb541c6033911 100644 --- a/totp.zig +++ b/totp.zig @@ -71,6 +71,8 @@ pub fn generateUrl(allocator: std.mem.Allocator, issuer: []const u8, account: [] try list.writer().print("{d}", .{digits}); try list.appendSlice("&period="); try list.writer().print("{d}", .{period}); + try list.appendSlice("&issuer="); + try url.percentEncodeAL(&list, issuer, url.is_query_percent_char); return list.toOwnedSlice(); }