@@ -14,13 +14,13 @@ pub const eddsa = @import("eddsa.zig");
1414pub const hmac = @import ("hmac.zig" );
1515pub const none = @import ("none.zig" );
1616
17- pub const SigningMethodRS256 = JWT (rsa .SigningRS256 , crypto_rsa .KeyPair , crypto_rsa .PublicKey );
18- pub const SigningMethodRS384 = JWT (rsa .SigningRS384 , crypto_rsa .KeyPair , crypto_rsa .PublicKey );
19- pub const SigningMethodRS512 = JWT (rsa .SigningRS512 , crypto_rsa .KeyPair , crypto_rsa .PublicKey );
17+ pub const SigningMethodRS256 = JWT (rsa .SigningRS256 , crypto_rsa .SecretKey , crypto_rsa .PublicKey );
18+ pub const SigningMethodRS384 = JWT (rsa .SigningRS384 , crypto_rsa .SecretKey , crypto_rsa .PublicKey );
19+ pub const SigningMethodRS512 = JWT (rsa .SigningRS512 , crypto_rsa .SecretKey , crypto_rsa .PublicKey );
2020
21- pub const SigningMethodPS256 = JWT (rsa_pss .SigningPS256 , crypto_rsa .KeyPair , crypto_rsa .PublicKey );
22- pub const SigningMethodPS384 = JWT (rsa_pss .SigningPS384 , crypto_rsa .KeyPair , crypto_rsa .PublicKey );
23- pub const SigningMethodPS512 = JWT (rsa_pss .SigningPS512 , crypto_rsa .KeyPair , crypto_rsa .PublicKey );
21+ pub const SigningMethodPS256 = JWT (rsa_pss .SigningPS256 , crypto_rsa .SecretKey , crypto_rsa .PublicKey );
22+ pub const SigningMethodPS384 = JWT (rsa_pss .SigningPS384 , crypto_rsa .SecretKey , crypto_rsa .PublicKey );
23+ pub const SigningMethodPS512 = JWT (rsa_pss .SigningPS512 , crypto_rsa .SecretKey , crypto_rsa .PublicKey );
2424
2525pub const SigningMethodES256 = JWT (ecdsa .SigningES256 , ecdsa .ecdsa .EcdsaP256Sha256 .SecretKey , ecdsa .ecdsa .EcdsaP256Sha256 .PublicKey );
2626pub const SigningMethodES384 = JWT (ecdsa .SigningES384 , ecdsa .ecdsa .EcdsaP384Sha384 .SecretKey , ecdsa .ecdsa .EcdsaP384Sha384 .PublicKey );
@@ -56,7 +56,7 @@ pub fn JWT(comptime Signer: type, comptime SecretKeyType: type, comptime PublicK
5656 };
5757 }
5858
59- pub fn make (self : Self , claims : anytype , key : SecretKeyType ) ! []const u8 {
59+ pub fn sign (self : Self , claims : anytype , key : SecretKeyType ) ! []const u8 {
6060 var t = token .Token .init (self .alloc );
6161 try t .setHeader (.{
6262 .typ = "JWT" ,
@@ -68,7 +68,7 @@ pub fn JWT(comptime Signer: type, comptime SecretKeyType: type, comptime PublicK
6868 defer t .deinit ();
6969
7070 const signed_string = try self .signer .sign (signed , key );
71- try t . setSignature (signed_string );
71+ t . withSignature (signed_string );
7272
7373 defer self .alloc .free (signed_string );
7474
@@ -95,7 +95,7 @@ pub fn JWT(comptime Signer: type, comptime SecretKeyType: type, comptime PublicK
9595
9696 defer self .alloc .free (signed );
9797
98- const msg = try t . signingString ();
98+ const msg = t . getRawNoSignature ();
9999 if (! self .signer .verify (msg , signed , key )) {
100100 return Error .JWTVerifyFail ;
101101 }
@@ -256,7 +256,7 @@ test "SigningMethodEdDSA" {
256256 };
257257
258258 const s = SigningMethodEdDSA .init (alloc );
259- const token_string = try s .make (claims , kp .secret_key );
259+ const token_string = try s .sign (claims , kp .secret_key );
260260 try testing .expectEqual (true , token_string .len > 0 );
261261
262262 // ==========
@@ -281,7 +281,7 @@ test "SigningMethodES256" {
281281 };
282282
283283 const s = SigningMethodES256 .init (alloc );
284- const token_string = try s .make (claims , kp .secret_key );
284+ const token_string = try s .sign (claims , kp .secret_key );
285285 try testing .expectEqual (true , token_string .len > 0 );
286286
287287 // ==========
@@ -306,7 +306,7 @@ test "SigningMethodES384" {
306306 };
307307
308308 const s = SigningMethodES384 .init (alloc );
309- const token_string = try s .make (claims , kp .secret_key );
309+ const token_string = try s .sign (claims , kp .secret_key );
310310 try testing .expectEqual (true , token_string .len > 0 );
311311
312312 // ==========
@@ -330,7 +330,7 @@ test "SigningMethodHS256" {
330330 const key = "test-key" ;
331331
332332 const s = SigningMethodHS256 .init (alloc );
333- const token_string = try s .make (claims , key );
333+ const token_string = try s .sign (claims , key );
334334 try testing .expectEqual (true , token_string .len > 0 );
335335
336336 // ==========
@@ -354,7 +354,7 @@ test "SigningMethodHS384" {
354354 const key = "test-key" ;
355355
356356 const s = SigningMethodHS384 .init (alloc );
357- const token_string = try s .make (claims , key );
357+ const token_string = try s .sign (claims , key );
358358 try testing .expectEqual (true , token_string .len > 0 );
359359
360360 // ==========
@@ -378,7 +378,7 @@ test "SigningMethodHS512" {
378378 const key = "test-key" ;
379379
380380 const s = SigningMethodHS512 .init (alloc );
381- const token_string = try s .make (claims , key );
381+ const token_string = try s .sign (claims , key );
382382 try testing .expectEqual (true , token_string .len > 0 );
383383
384384 // ==========
@@ -402,7 +402,7 @@ test "SigningMethodNone" {
402402 const key = "" ;
403403
404404 const s = SigningMethodNone .init (alloc );
405- const token_string = try s .make (claims , key );
405+ const token_string = try s .sign (claims , key );
406406 try testing .expectEqual (true , token_string .len > 0 );
407407
408408 // ==========
@@ -451,7 +451,7 @@ test "SigningMethodES256 Check" {
451451 };
452452
453453 const s = SigningMethodES256 .init (alloc );
454- const token_string = try s .make (claims , secret_key );
454+ const token_string = try s .sign (claims , secret_key );
455455 try testing .expectEqual (true , token_string .len > 0 );
456456
457457 // ==========
@@ -487,7 +487,7 @@ test "SigningMethodES384 Check" {
487487 };
488488
489489 const s = SigningMethodES384 .init (alloc );
490- const token_string = try s .make (claims , secret_key );
490+ const token_string = try s .sign (claims , secret_key );
491491 try testing .expectEqual (true , token_string .len > 0 );
492492
493493 // ==========
@@ -546,7 +546,7 @@ test "SigningMethodEdDSA Check" {
546546 };
547547
548548 const s = SigningMethodED25519 .init (alloc );
549- const token_string = try s .make (claims , secret_key );
549+ const token_string = try s .sign (claims , secret_key );
550550 try testing .expectEqual (true , token_string .len > 0 );
551551
552552 // ==========
@@ -599,7 +599,7 @@ test "SigningMethodHS256 Check" {
599599 };
600600
601601 const s = SigningMethodHS256 .init (alloc );
602- const token_string = try s .make (claims , key_bytes );
602+ const token_string = try s .sign (claims , key_bytes );
603603 try testing .expectEqual (true , token_string .len > 0 );
604604
605605 // ==========
@@ -628,7 +628,7 @@ test "SigningMethodHS384 Check" {
628628 };
629629
630630 const s = SigningMethodHS384 .init (alloc );
631- const token_string = try s .make (claims , key_bytes );
631+ const token_string = try s .sign (claims , key_bytes );
632632 try testing .expectEqual (true , token_string .len > 0 );
633633
634634 // ==========
@@ -657,7 +657,7 @@ test "SigningMethodHS512 Check" {
657657 };
658658
659659 const s = SigningMethodHS512 .init (alloc );
660- const token_string = try s .make (claims , key_bytes );
660+ const token_string = try s .sign (claims , key_bytes );
661661 try testing .expectEqual (true , token_string .len > 0 );
662662
663663 // ==========
@@ -711,7 +711,7 @@ test "SigningMethodES256 with JWTClaims" {
711711 };
712712
713713 const s = SigningMethodES256 .init (alloc );
714- const token_string = try s .make (claims , kp .secret_key );
714+ const token_string = try s .sign (claims , kp .secret_key );
715715 try testing .expectEqual (true , token_string .len > 0 );
716716
717717 // ==========
@@ -734,7 +734,7 @@ test "SigningMethodRS256" {
734734 const prikey_bytes = try utils .base64Decode (alloc , prikey );
735735 const pubkey_bytes = try utils .base64Decode (alloc , pubkey );
736736
737- const secret_key = try crypto_rsa .KeyPair .fromDer (prikey_bytes );
737+ const secret_key = try crypto_rsa .SecretKey .fromDer (prikey_bytes );
738738 const public_key = try crypto_rsa .PublicKey .fromDer (pubkey_bytes );
739739
740740 const claims = .{
@@ -743,7 +743,7 @@ test "SigningMethodRS256" {
743743 };
744744
745745 const s = SigningMethodRS256 .init (alloc );
746- const token_string = try s .make (claims , secret_key );
746+ const token_string = try s .sign (claims , secret_key );
747747 try testing .expectEqual (true , token_string .len > 0 );
748748
749749 // ==========
@@ -766,7 +766,7 @@ test "SigningMethodRS384" {
766766 const prikey_bytes = try utils .base64Decode (alloc , prikey );
767767 const pubkey_bytes = try utils .base64Decode (alloc , pubkey );
768768
769- const secret_key = try crypto_rsa .KeyPair .fromDer (prikey_bytes );
769+ const secret_key = try crypto_rsa .SecretKey .fromDer (prikey_bytes );
770770 const public_key = try crypto_rsa .PublicKey .fromDer (pubkey_bytes );
771771
772772 const claims = .{
@@ -775,7 +775,7 @@ test "SigningMethodRS384" {
775775 };
776776
777777 const s = SigningMethodRS384 .init (alloc );
778- const token_string = try s .make (claims , secret_key );
778+ const token_string = try s .sign (claims , secret_key );
779779 try testing .expectEqual (true , token_string .len > 0 );
780780
781781 // ==========
@@ -798,7 +798,7 @@ test "SigningMethodRS512" {
798798 const prikey_bytes = try utils .base64Decode (alloc , prikey );
799799 const pubkey_bytes = try utils .base64Decode (alloc , pubkey );
800800
801- const secret_key = try crypto_rsa .KeyPair .fromDer (prikey_bytes );
801+ const secret_key = try crypto_rsa .SecretKey .fromDer (prikey_bytes );
802802 const public_key = try crypto_rsa .PublicKey .fromDer (pubkey_bytes );
803803
804804 const claims = .{
@@ -807,7 +807,7 @@ test "SigningMethodRS512" {
807807 };
808808
809809 const s = SigningMethodRS512 .init (alloc );
810- const token_string = try s .make (claims , secret_key );
810+ const token_string = try s .sign (claims , secret_key );
811811 try testing .expectEqual (true , token_string .len > 0 );
812812
813813 // ==========
@@ -830,7 +830,7 @@ test "SigningMethodPS256" {
830830 const prikey_bytes = try utils .base64Decode (alloc , prikey );
831831 const pubkey_bytes = try utils .base64Decode (alloc , pubkey );
832832
833- const secret_key = try crypto_rsa .KeyPair .fromDer (prikey_bytes );
833+ const secret_key = try crypto_rsa .SecretKey .fromDer (prikey_bytes );
834834 const public_key = try crypto_rsa .PublicKey .fromDer (pubkey_bytes );
835835
836836 const claims = .{
@@ -839,7 +839,7 @@ test "SigningMethodPS256" {
839839 };
840840
841841 const s = SigningMethodPS256 .init (alloc );
842- const token_string = try s .make (claims , secret_key );
842+ const token_string = try s .sign (claims , secret_key );
843843 try testing .expectEqual (true , token_string .len > 0 );
844844
845845 // ==========
@@ -862,7 +862,7 @@ test "SigningMethodPS384" {
862862 const prikey_bytes = try utils .base64Decode (alloc , prikey );
863863 const pubkey_bytes = try utils .base64Decode (alloc , pubkey );
864864
865- const secret_key = try crypto_rsa .KeyPair .fromDer (prikey_bytes );
865+ const secret_key = try crypto_rsa .SecretKey .fromDer (prikey_bytes );
866866 const public_key = try crypto_rsa .PublicKey .fromDer (pubkey_bytes );
867867
868868 const claims = .{
@@ -871,7 +871,7 @@ test "SigningMethodPS384" {
871871 };
872872
873873 const s = SigningMethodPS384 .init (alloc );
874- const token_string = try s .make (claims , secret_key );
874+ const token_string = try s .sign (claims , secret_key );
875875 try testing .expectEqual (true , token_string .len > 0 );
876876
877877 // ==========
@@ -894,7 +894,7 @@ test "SigningMethodPS512" {
894894 const prikey_bytes = try utils .base64Decode (alloc , prikey );
895895 const pubkey_bytes = try utils .base64Decode (alloc , pubkey );
896896
897- const secret_key = try crypto_rsa .KeyPair .fromDer (prikey_bytes );
897+ const secret_key = try crypto_rsa .SecretKey .fromDer (prikey_bytes );
898898 const public_key = try crypto_rsa .PublicKey .fromDer (pubkey_bytes );
899899
900900 const claims = .{
@@ -903,7 +903,7 @@ test "SigningMethodPS512" {
903903 };
904904
905905 const s = SigningMethodPS512 .init (alloc );
906- const token_string = try s .make (claims , secret_key );
906+ const token_string = try s .sign (claims , secret_key );
907907 try testing .expectEqual (true , token_string .len > 0 );
908908
909909 // ==========
0 commit comments