1
1
use crate :: net:: { Endpoint , GenericTunnelOptions , TransportProtocol } ;
2
+ use base64:: { engine:: general_purpose:: STANDARD , Engine } ;
2
3
use ipnetwork:: IpNetwork ;
3
4
use serde:: { Deserialize , Deserializer , Serialize , Serializer } ;
4
5
use std:: {
@@ -105,7 +106,7 @@ impl PrivateKey {
105
106
}
106
107
107
108
pub fn to_base64 ( & self ) -> String {
108
- base64 :: encode ( self . 0 . to_bytes ( ) )
109
+ STANDARD . encode ( self . 0 . to_bytes ( ) )
109
110
}
110
111
111
112
pub fn from_base64 ( key : & str ) -> Result < Self , InvalidKey > {
@@ -135,7 +136,7 @@ impl fmt::Debug for PrivateKey {
135
136
136
137
impl fmt:: Display for PrivateKey {
137
138
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
138
- write ! ( f, "{}" , & base64 :: encode( ( self . 0 ) . to_bytes( ) ) )
139
+ write ! ( f, "{}" , & STANDARD . encode( ( self . 0 ) . to_bytes( ) ) )
139
140
}
140
141
}
141
142
@@ -177,7 +178,7 @@ impl PublicKey {
177
178
}
178
179
179
180
pub fn to_base64 ( & self ) -> String {
180
- base64 :: encode ( self . as_bytes ( ) )
181
+ STANDARD . encode ( self . as_bytes ( ) )
181
182
}
182
183
183
184
pub fn from_base64 ( key : & str ) -> Result < Self , InvalidKey > {
@@ -272,15 +273,15 @@ impl From<Box<[u8; 32]>> for PresharedKey {
272
273
273
274
impl fmt:: Debug for PresharedKey {
274
275
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
275
- write ! ( f, "{}" , & base64 :: encode( self . as_bytes( ) ) )
276
+ write ! ( f, "{}" , & STANDARD . encode( self . as_bytes( ) ) )
276
277
}
277
278
}
278
279
279
280
fn serialize_key < S > ( key : & [ u8 ; 32 ] , serializer : S ) -> Result < S :: Ok , S :: Error >
280
281
where
281
282
S : Serializer ,
282
283
{
283
- serializer. serialize_str ( & base64 :: encode ( key) )
284
+ serializer. serialize_str ( & STANDARD . encode ( key) )
284
285
}
285
286
286
287
fn deserialize_key < ' de , D , K > ( deserializer : D ) -> Result < K , D :: Error >
@@ -295,7 +296,7 @@ where
295
296
}
296
297
297
298
fn key_from_base64 < K : From < [ u8 ; 32 ] > > ( key : & str ) -> Result < K , InvalidKey > {
298
- let bytes = base64 :: decode ( key) . map_err ( InvalidKey :: Format ) ?;
299
+ let bytes = STANDARD . decode ( key) . map_err ( InvalidKey :: Format ) ?;
299
300
if bytes. len ( ) != 32 {
300
301
return Err ( InvalidKey :: Length ( bytes. len ( ) ) ) ;
301
302
}
0 commit comments