1- use std:: fmt;
21use std:: time:: { Duration , SystemTime , UNIX_EPOCH } ;
32
43use jsonwebtoken:: { Algorithm , Header , encode} ;
@@ -12,21 +11,12 @@ use crate::jwt::SigningKey;
1211#[ derive( Debug , Clone , PartialEq , Eq ) ]
1312pub struct CalloutIssuer ( String ) ;
1413
15- #[ derive( Debug , PartialEq , Eq ) ]
14+ #[ derive( Debug , PartialEq , Eq , thiserror :: Error ) ]
1615pub enum CalloutIssuerError {
16+ #[ error( "callout issuer must be non-empty" ) ]
1717 Empty ,
1818}
1919
20- impl fmt:: Display for CalloutIssuerError {
21- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
22- match self {
23- Self :: Empty => f. write_str ( "callout issuer must be non-empty" ) ,
24- }
25- }
26- }
27-
28- impl std:: error:: Error for CalloutIssuerError { }
29-
3020impl CalloutIssuer {
3121 pub fn new ( issuer : impl Into < String > ) -> Result < Self , CalloutIssuerError > {
3222 let s = issuer. into ( ) ;
@@ -44,21 +34,12 @@ impl CalloutIssuer {
4434#[ derive( Debug , Clone , PartialEq , Eq ) ]
4535pub struct ServerAudience ( String ) ;
4636
47- #[ derive( Debug , PartialEq , Eq ) ]
37+ #[ derive( Debug , PartialEq , Eq , thiserror :: Error ) ]
4838pub enum ServerAudienceError {
39+ #[ error( "server audience must be non-empty" ) ]
4940 Empty ,
5041}
5142
52- impl fmt:: Display for ServerAudienceError {
53- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
54- match self {
55- Self :: Empty => f. write_str ( "server audience must be non-empty" ) ,
56- }
57- }
58- }
59-
60- impl std:: error:: Error for ServerAudienceError { }
61-
6243impl ServerAudience {
6344 pub fn new ( audience : impl Into < String > ) -> Result < Self , ServerAudienceError > {
6445 let s = audience. into ( ) ;
@@ -76,21 +57,12 @@ impl ServerAudience {
7657#[ derive( Debug , Clone , PartialEq , Eq ) ]
7758pub struct UserNkeySubject ( String ) ;
7859
79- #[ derive( Debug , PartialEq , Eq ) ]
60+ #[ derive( Debug , PartialEq , Eq , thiserror :: Error ) ]
8061pub enum UserNkeySubjectError {
62+ #[ error( "user nkey subject must be non-empty" ) ]
8163 Empty ,
8264}
8365
84- impl fmt:: Display for UserNkeySubjectError {
85- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
86- match self {
87- Self :: Empty => f. write_str ( "user nkey subject must be non-empty" ) ,
88- }
89- }
90- }
91-
92- impl std:: error:: Error for UserNkeySubjectError { }
93-
9466impl UserNkeySubject {
9567 pub fn new ( subject : impl Into < String > ) -> Result < Self , UserNkeySubjectError > {
9668 let s = subject. into ( ) ;
@@ -114,33 +86,16 @@ pub struct DenialClaims {
11486 pub request_jti : Option < String > ,
11587}
11688
117- #[ derive( Debug ) ]
89+ #[ derive( Debug , thiserror :: Error ) ]
11890pub enum DenialClaimsError {
119- Encode ( jsonwebtoken:: errors:: Error ) ,
120- SystemTime ( std:: time:: SystemTimeError ) ,
91+ #[ error( "denial JWT encode error: {0}" ) ]
92+ Encode ( #[ source] jsonwebtoken:: errors:: Error ) ,
93+ #[ error( "system time error: {0}" ) ]
94+ SystemTime ( #[ source] std:: time:: SystemTimeError ) ,
95+ #[ error( "issued-at timestamp out of portable range" ) ]
12196 IssuedAtOutOfRange ,
12297}
12398
124- impl fmt:: Display for DenialClaimsError {
125- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
126- match self {
127- Self :: Encode ( e) => write ! ( f, "denial JWT encode error: {e}" ) ,
128- Self :: SystemTime ( e) => write ! ( f, "system time error: {e}" ) ,
129- Self :: IssuedAtOutOfRange => f. write_str ( "issued-at timestamp out of portable range" ) ,
130- }
131- }
132- }
133-
134- impl std:: error:: Error for DenialClaimsError {
135- fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
136- match self {
137- Self :: Encode ( e) => Some ( e) ,
138- Self :: SystemTime ( e) => Some ( e) ,
139- _ => None ,
140- }
141- }
142- }
143-
14499impl From < DenialClaimsError > for AuthCalloutError {
145100 fn from ( value : DenialClaimsError ) -> Self {
146101 // Denial-claims minting failures aren't JwtError — they're this
0 commit comments