@@ -17,7 +17,7 @@ use std::{borrow::Cow, marker::PhantomData};
1717///
1818/// - get token: from `Authorization: Bearer <here>`
1919/// - customizable by `.get_token_by( 〜 )`
20- /// - verifying algorithm: `HMAC-SHA256`
20+ /// - verification algorithm: `HMAC-SHA256`
2121/// - `HMAC-SHA{256, 384, 512}` are available now
2222/// - issuer: `None`
2323/// - configured by `.with_issuer(...)`
@@ -48,7 +48,7 @@ use std::{borrow::Cow, marker::PhantomData};
4848/// }
4949///
5050/// fn our_jwt() -> Jwt<OurJwtPayload> {
51- /// Jwt::default ("OUR_JWT_SECRET_KEY")
51+ /// Jwt::new_hs256 ("OUR_JWT_SECRET_KEY")
5252/// }
5353///
5454/// async fn hello(
@@ -183,23 +183,34 @@ const _: () = {
183183} ;
184184
185185impl < Payload : Serialize + for < ' de > Deserialize < ' de > + SendSyncOnThreaded + ' static > Jwt < Payload > {
186- /// Just `new_256`; use HMAC-SHA256 as verifying algorithm
187- #[ inline]
186+ #[ deprecated( since = "0.24.8" , note = "use `Jwt::new_hs256` instead." ) ]
188187 pub fn default ( secret : impl Into < Cow < ' static , str > > ) -> Self {
189- Self :: new_256 ( secret)
188+ Self :: new_hs256 ( secret)
190189 }
191- /// Use HMAC-SHA256 as verifying algorithm
192- pub fn new_256 ( secret : impl Into < Cow < ' static , str > > ) -> Self {
190+ /// Use HMAC-SHA256 as verification algorithm
191+ pub fn new_hs256 ( secret : impl Into < Cow < ' static , str > > ) -> Self {
193192 Self :: new ( VerifyingAlgorithm :: HS256 , secret)
194193 }
195- /// Use HMAC-SHA384 as verifying algorithm
196- pub fn new_384 ( secret : impl Into < Cow < ' static , str > > ) -> Self {
194+ #[ deprecated( since = "0.24.8" , note = "use `Jwt::new_hs256` instead." ) ]
195+ pub fn new_256 ( secret : impl Into < Cow < ' static , str > > ) -> Self {
196+ Self :: new_hs256 ( secret)
197+ }
198+ /// Use HMAC-SHA384 as verification algorithm
199+ pub fn new_hs384 ( secret : impl Into < Cow < ' static , str > > ) -> Self {
197200 Self :: new ( VerifyingAlgorithm :: HS384 , secret)
198201 }
199- /// Use HMAC-SHA512 as verifying algorithm
200- pub fn new_512 ( secret : impl Into < Cow < ' static , str > > ) -> Self {
202+ #[ deprecated( since = "0.24.8" , note = "use `Jwt::new_hs384` instead." ) ]
203+ pub fn new_384 ( secret : impl Into < Cow < ' static , str > > ) -> Self {
204+ Self :: new_hs384 ( secret)
205+ }
206+ /// Use HMAC-SHA512 as verification algorithm
207+ pub fn new_hs512 ( secret : impl Into < Cow < ' static , str > > ) -> Self {
201208 Self :: new ( VerifyingAlgorithm :: HS512 , secret)
202209 }
210+ #[ deprecated( since = "0.24.8" , note = "use `Jwt::new_hs512` instead." ) ]
211+ pub fn new_512 ( secret : impl Into < Cow < ' static , str > > ) -> Self {
212+ Self :: new_hs512 ( secret)
213+ }
203214
204215 /// Set issuer; used for `iss` claim verification
205216 pub fn with_issuer ( mut self , iss : impl Into < String > ) -> Self {
@@ -218,7 +229,6 @@ impl<Payload: Serialize + for<'de> Deserialize<'de> + SendSyncOnThreaded + 'stat
218229 pub fn get_token_by (
219230 mut self ,
220231 get_token : fn ( & Request ) -> Option < & str > ,
221-
222232 #[ cfg( feature = "openapi" ) ] openapi_security : crate :: openapi:: security:: SecurityScheme ,
223233 ) -> Self {
224234 #[ cfg( feature = "openapi" ) ]
@@ -551,7 +561,7 @@ mod test {
551561 }
552562
553563 assert_eq ! {
554- & * Jwt :: default ( "secret" ) . issue( Payload {
564+ & * Jwt :: new_hs256 ( "secret" ) . issue( Payload {
555565 iat: 1516239022 ,
556566 id: 42 ,
557567 name: "kanarus" . to_string( )
@@ -560,14 +570,14 @@ mod test {
560570 }
561571
562572 assert_eq ! {
563- Jwt :: default ( "secret" )
573+ Jwt :: new_hs256 ( "secret" )
564574 . with_issuer( "https://auth.example.com" )
565575 . issue( Payload {
566576 iat: 1516239022 ,
567577 id: 42 ,
568578 name: "kanarus" . to_string( )
569579 } ) ,
570- Jwt :: default ( "secret" )
580+ Jwt :: new_hs256 ( "secret" )
571581 . issue( PayloadWithIss {
572582 iss: "https://auth.example.com" . to_string( ) ,
573583 iat: 1516239022 ,
@@ -577,14 +587,14 @@ mod test {
577587 }
578588
579589 assert_eq ! {
580- Jwt :: default ( "secret" )
590+ Jwt :: new_hs256 ( "secret" )
581591 . with_audience( "https://auth.example.com" )
582592 . issue( Payload {
583593 iat: 1516239022 ,
584594 id: 42 ,
585595 name: "kanarus" . to_string( )
586596 } ) ,
587- Jwt :: default ( "secret" )
597+ Jwt :: new_hs256 ( "secret" )
588598 . issue( PayloadWithAud {
589599 aud: "https://auth.example.com" . to_string( ) ,
590600 iat: 1516239022 ,
@@ -594,15 +604,15 @@ mod test {
594604 }
595605
596606 assert_eq ! {
597- Jwt :: default ( "secret" )
607+ Jwt :: new_hs256 ( "secret" )
598608 . with_issuer( "https://auth.example.com" )
599609 . with_audience( "https://auth.example.com" )
600610 . issue( Payload {
601611 iat: 1516239022 ,
602612 id: 42 ,
603613 name: "kanarus" . to_string( )
604614 } ) ,
605- Jwt :: default ( "secret" )
615+ Jwt :: new_hs256 ( "secret" )
606616 . issue( PayloadWithIssAud {
607617 iss: "https://auth.example.com" . to_string( ) ,
608618 aud: "https://auth.example.com" . to_string( ) ,
@@ -638,7 +648,7 @@ mod test {
638648 }
639649
640650 let j =
641- Jwt :: < :: serde_json:: Value > :: default ( "ohkami-realworld-jwt-authorization-secret-key" ) ;
651+ Jwt :: < :: serde_json:: Value > :: new_hs256 ( "ohkami-realworld-jwt-authorization-secret-key" ) ;
642652 {
643653 assert_eq ! (
644654 verified!( j, GET "/" {
@@ -765,7 +775,7 @@ mod test {
765775 use crate :: openapi;
766776
767777 fn my_jwt ( ) -> Jwt < MyJwtPayload > {
768- Jwt :: default ( "myverysecretjwtsecretkey" )
778+ Jwt :: new_hs256 ( "myverysecretjwtsecretkey" )
769779 }
770780
771781 #[ derive( serde:: Serialize , serde:: Deserialize ) ]
0 commit comments