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):
235235 b'\xd3 V\xbe o\xf7 \x1d ' )
236236 self .check_decode_type_errors (base64 .urlsafe_b64decode )
237237
238- # TODO: RUSTPYTHON
239- @unittest .expectedFailure
240238 def test_b64decode_padding_error (self ):
241239 self .assertRaises (binascii .Error , base64 .b64decode , b'abc' )
242240 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;
55#[ pymodule( name = "binascii" ) ]
66mod decl {
77 use crate :: vm:: {
8- builtins:: { PyIntRef , PyTypeRef } ,
8+ builtins:: { PyBaseExceptionRef , PyIntRef , PyTypeRef } ,
99 function:: { ArgAsciiBuffer , ArgBytesLike , OptionalArg } ,
1010 PyResult , VirtualMachine ,
1111 } ;
@@ -93,6 +93,10 @@ mod decl {
9393 newline : bool ,
9494 }
9595
96+ fn new_binascii_error ( msg : String , vm : & VirtualMachine ) -> PyBaseExceptionRef {
97+ vm. new_exception_msg ( error_type ( vm) , msg)
98+ }
99+
96100 #[ pyfunction]
97101 fn a2b_base64 ( s : ArgAsciiBuffer , vm : & VirtualMachine ) -> PyResult < Vec < u8 > > {
98102 s. with_ref ( |b| {
@@ -104,9 +108,12 @@ mod decl {
104108 } else {
105109 b
106110 } ;
111+ if b. len ( ) % 4 != 0 {
112+ return Err ( base64:: DecodeError :: InvalidLength ) ;
113+ }
107114 base64:: decode ( b)
108115 } )
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 ) )
110117 }
111118
112119 #[ pyfunction]
You can’t perform that action at this time.
0 commit comments