Skip to content

Commit 12ea0d3

Browse files
committed
fixed
1 parent 66169d2 commit 12ea0d3

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ pub fn main() !void {
8383
std.debug.print("make jwt: {s} \n", .{token_string});
8484
8585
const p = jwt.SigningMethodEdDSA.init(alloc);
86-
var parsed = try p.parse(token_string, kp.public_key);
86+
var token = try p.parse(token_string, kp.public_key);
8787
8888
// output:
8989
// claims aud: example.com
90-
const claims2 = try parsed.getClaims();
90+
const claims2 = try token.getClaims();
9191
std.debug.print("claims aud: {s} \n", .{claims2.object.get("aud").?.string});
9292
}
9393
~~~

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.{
22
.name = "zig-jwt",
33
.description = "A JWT (JSON Web Token) library for zig.",
4-
.version = "1.0.11",
4+
.version = "1.0.12",
55
.paths = .{
66
"build.zig",
77
"build.zig.zon",

src/jwt.zig

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,16 @@ pub fn JWT(comptime Signer: type, comptime SecretKeyType: type, comptime PublicK
8585
try t.setHeader(header);
8686
try t.setClaims(claims);
8787

88-
const signing_string = try t.signingString();
8988
defer t.deinit();
9089

91-
const signature = try self.signer.sign(signing_string, secret_key);
92-
t.withSignature(signature);
90+
const signing_string = try t.signingString();
91+
defer self.alloc.free(signing_string);
9392

93+
const signature = try self.signer.sign(signing_string, secret_key);
9494
defer self.alloc.free(signature);
9595

96+
t.withSignature(signature);
97+
9698
const signed_token = try t.signedString();
9799
return signed_token;
98100
}
@@ -111,13 +113,16 @@ pub fn JWT(comptime Signer: type, comptime SecretKeyType: type, comptime PublicK
111113
}
112114

113115
const signature = t.getSignature();
114-
116+
defer self.alloc.free(signature);
117+
115118
const token_sign = try self.alloc.alloc(u8, signature.len);
116119
@memcpy(token_sign[0..], signature[0..]);
117120

118121
defer self.alloc.free(token_sign);
119122

120123
const signing_string = try t.signingString();
124+
defer self.alloc.free(signing_string);
125+
121126
if (!self.signer.verify(signing_string, token_sign, public_key)) {
122127
return Error.JWTVerifyFail;
123128
}

0 commit comments

Comments
 (0)