File tree Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -235,8 +235,6 @@ def test_b64decode(self):
235
235
b'\xd3 V\xbe o\xf7 \x1d ' )
236
236
self .check_decode_type_errors (base64 .urlsafe_b64decode )
237
237
238
- # TODO: RUSTPYTHON
239
- @unittest .expectedFailure
240
238
def test_b64decode_padding_error (self ):
241
239
self .assertRaises (binascii .Error , base64 .b64decode , b'abc' )
242
240
self .assertRaises (binascii .Error , base64 .b64decode , 'abc' )
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ pub(super) use decl::crc32;
5
5
#[ pymodule( name = "binascii" ) ]
6
6
mod decl {
7
7
use crate :: vm:: {
8
- builtins:: { PyIntRef , PyTypeRef } ,
8
+ builtins:: { PyBaseExceptionRef , PyIntRef , PyTypeRef } ,
9
9
function:: { ArgAsciiBuffer , ArgBytesLike , OptionalArg } ,
10
10
PyResult , VirtualMachine ,
11
11
} ;
@@ -93,6 +93,10 @@ mod decl {
93
93
newline : bool ,
94
94
}
95
95
96
+ fn new_binascii_error ( msg : String , vm : & VirtualMachine ) -> PyBaseExceptionRef {
97
+ vm. new_exception_msg ( error_type ( vm) , msg)
98
+ }
99
+
96
100
#[ pyfunction]
97
101
fn a2b_base64 ( s : ArgAsciiBuffer , vm : & VirtualMachine ) -> PyResult < Vec < u8 > > {
98
102
s. with_ref ( |b| {
@@ -104,9 +108,12 @@ mod decl {
104
108
} else {
105
109
b
106
110
} ;
111
+ if b. len ( ) % 4 != 0 {
112
+ return Err ( base64:: DecodeError :: InvalidLength ) ;
113
+ }
107
114
base64:: decode ( b)
108
115
} )
109
- . map_err ( |err| vm . new_value_error ( format ! ( "error decoding base64: {}" , err) ) )
116
+ . map_err ( |err| new_binascii_error ( format ! ( "error decoding base64: {}" , err) , vm ) )
110
117
}
111
118
112
119
#[ pyfunction]
You can’t perform that action at this time.
0 commit comments