12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
- use base64:: write:: EncoderWriter ;
16
- use base64:: { DecodeError , URL_SAFE } ;
15
+ use base64:: { engine:: general_purpose:: URL_SAFE , write:: EncoderWriter , DecodeError , Engine } ;
17
16
use core:: fmt;
18
17
use std:: borrow:: { Borrow , BorrowMut } ;
19
18
use std:: fmt:: { Display , Formatter } ;
@@ -41,17 +40,17 @@ impl Blob {
41
40
42
41
/// Attempts to encode this blob's data into the provided writer.
43
42
pub fn encode_to_writer < W : Write > ( & self , mut writer : W ) -> io:: Result < ( ) > {
44
- EncoderWriter :: new ( & mut writer, URL_SAFE ) . write_all ( & self . data )
43
+ EncoderWriter :: new ( & mut writer, & URL_SAFE ) . write_all ( & self . data )
45
44
}
46
45
47
46
/// Consumes this BLOB and returns the decoded data.
48
47
pub fn into_decoded ( self ) -> Result < Vec < u8 > , DecodeError > {
49
- base64 :: decode_config ( self . data , URL_SAFE )
48
+ URL_SAFE . decode ( self . data )
50
49
}
51
50
52
51
/// Clone the underlying data and decode it.
53
52
pub fn as_decoded ( & self ) -> Result < Vec < u8 > , DecodeError > {
54
- base64 :: decode_config ( self . data . clone ( ) , URL_SAFE )
53
+ URL_SAFE . decode ( self . data . clone ( ) )
55
54
}
56
55
57
56
/// Attempts to decode the provided data. Returning a result containing either the decoded data
@@ -60,12 +59,12 @@ impl Blob {
60
59
where
61
60
T : AsRef < [ u8 ] > ,
62
61
{
63
- base64 :: decode_config ( encoded . as_ref ( ) , URL_SAFE ) . map ( Blob :: from_vec)
62
+ URL_SAFE . decode ( encoded ) . map ( Blob :: from_vec)
64
63
}
65
64
66
65
/// Encodes the provided data into a [`Blob`].
67
66
pub fn encode < T : AsRef < [ u8 ] > > ( input : T ) -> Blob {
68
- let encoded = base64 :: encode_config ( input, URL_SAFE ) ;
67
+ let encoded = URL_SAFE . encode ( input) ;
69
68
Blob {
70
69
data : Vec :: from ( encoded. as_bytes ( ) ) ,
71
70
}
@@ -114,8 +113,8 @@ mod tests {
114
113
115
114
#[ test]
116
115
fn from_encoded ( ) {
117
- let encoded = base64 :: encode_config ( "swimming" , URL_SAFE ) ;
118
- let decoded = base64 :: decode_config ( encoded. as_bytes ( ) , URL_SAFE ) . unwrap ( ) ;
116
+ let encoded = URL_SAFE . encode ( "swimming" ) ;
117
+ let decoded = URL_SAFE . decode ( encoded. as_bytes ( ) ) . unwrap ( ) ;
119
118
let blob = Blob :: from_encoded ( Vec :: from ( encoded. as_bytes ( ) ) ) ;
120
119
121
120
assert_eq ! ( decoded, blob. into_decoded( ) . unwrap( ) )
0 commit comments