@@ -34,7 +34,7 @@ macro_rules! expect_two {
34
34
#[ derive( Debug , Clone , PartialEq ) ]
35
35
pub ( crate ) enum DecodingKeyKind < ' a > {
36
36
SecretOrDer ( Cow < ' a , [ u8 ] > ) ,
37
- RsaModulusExponent { n : & ' a str , e : & ' a str } ,
37
+ RsaModulusExponent { n : Cow < ' a , str > , e : Cow < ' a , str > } ,
38
38
}
39
39
40
40
/// All the different kind of keys we can use to decode a JWT
@@ -77,7 +77,10 @@ impl<'a> DecodingKey<'a> {
77
77
pub fn from_rsa_components ( modulus : & ' a str , exponent : & ' a str ) -> Self {
78
78
DecodingKey {
79
79
family : AlgorithmFamily :: Rsa ,
80
- kind : DecodingKeyKind :: RsaModulusExponent { n : modulus, e : exponent } ,
80
+ kind : DecodingKeyKind :: RsaModulusExponent {
81
+ n : Cow :: Borrowed ( modulus) ,
82
+ e : Cow :: Borrowed ( exponent) ,
83
+ } ,
81
84
}
82
85
}
83
86
@@ -107,6 +110,19 @@ impl<'a> DecodingKey<'a> {
107
110
}
108
111
}
109
112
113
+ /// Convert self to `DecodingKey<'static>`.
114
+ pub fn into_static ( self ) -> DecodingKey < ' static > {
115
+ use DecodingKeyKind :: * ;
116
+ let DecodingKey { family, kind } = self ;
117
+ let static_kind = match kind {
118
+ SecretOrDer ( key) => SecretOrDer ( Cow :: Owned ( key. into_owned ( ) ) ) ,
119
+ RsaModulusExponent { n, e } => {
120
+ RsaModulusExponent { n : Cow :: Owned ( n. into_owned ( ) ) , e : Cow :: Owned ( e. into_owned ( ) ) }
121
+ }
122
+ } ;
123
+ DecodingKey { family, kind : static_kind }
124
+ }
125
+
110
126
pub ( crate ) fn as_bytes ( & self ) -> & [ u8 ] {
111
127
match & self . kind {
112
128
DecodingKeyKind :: SecretOrDer ( b) => & b,
0 commit comments