@@ -209,16 +209,20 @@ def read(self, b=-1):
209
209
:returns: Processed (encrypted or decrypted) bytes from source stream
210
210
:rtype: bytes
211
211
"""
212
- # NoneType value for b is interpretted as a full read for legacy compatibility
213
- if b is None :
212
+ # Any negative value for b is interpreted as a full read
213
+ # None is also accepted for legacy compatibility
214
+ if b is None or b < 0 :
214
215
b = - 1
215
216
216
217
_LOGGER .debug ("Stream read called, requesting %s bytes" , b )
217
218
output = io .BytesIO ()
219
+
218
220
if not self ._message_prepped :
219
221
self ._prep_message ()
222
+
220
223
if self .closed :
221
224
raise ValueError ("I/O operation on closed file" )
225
+
222
226
if b :
223
227
self ._read_bytes (b )
224
228
output .write (self .output_buffer [:b ])
@@ -228,6 +232,7 @@ def read(self, b=-1):
228
232
self ._read_bytes (LINE_LENGTH )
229
233
output .write (self .output_buffer )
230
234
self .output_buffer = b""
235
+
231
236
self .bytes_read += output .tell ()
232
237
_LOGGER .debug ("Returning %s bytes of %s bytes requested" , output .tell (), b )
233
238
return output .getvalue ()
@@ -511,14 +516,18 @@ def _read_bytes_to_non_framed_body(self, b):
511
516
_LOGGER .debug ("Closing encryptor after receiving only %s bytes of %s bytes requested" , plaintext , b )
512
517
self .source_stream .close ()
513
518
closing = self .encryptor .finalize ()
519
+
514
520
if self .signer is not None :
515
521
self .signer .update (closing )
522
+
516
523
closing += aws_encryption_sdk .internal .formatting .serialize .serialize_non_framed_close (
517
524
tag = self .encryptor .tag , signer = self .signer
518
525
)
526
+
519
527
if self .signer is not None :
520
528
closing += aws_encryption_sdk .internal .formatting .serialize .serialize_footer (self .signer )
521
529
return ciphertext + closing
530
+
522
531
return ciphertext
523
532
524
533
def _read_bytes_to_framed_body (self , b ):
@@ -535,9 +544,11 @@ def _read_bytes_to_framed_body(self, b):
535
544
plaintext = self .source_stream .read (b )
536
545
_LOGGER .debug ("%s bytes read from source" , len (plaintext ))
537
546
finalize = False
547
+
538
548
if len (plaintext ) < b :
539
549
_LOGGER .debug ("Final plaintext read from source" )
540
550
finalize = True
551
+
541
552
output = b""
542
553
final_frame_written = False
543
554
@@ -776,10 +787,13 @@ def _read_bytes_from_non_framed_body(self, b):
776
787
bytes_to_read = self .body_end - self .source_stream .tell ()
777
788
_LOGGER .debug ("%s bytes requested; reading %s bytes" , b , bytes_to_read )
778
789
ciphertext = self .source_stream .read (bytes_to_read )
790
+
779
791
if len (self .output_buffer ) + len (ciphertext ) < self .body_length :
780
792
raise SerializationError ("Total message body contents less than specified in body description" )
793
+
781
794
if self .verifier is not None :
782
795
self .verifier .update (ciphertext )
796
+
783
797
plaintext = self .decryptor .update (ciphertext )
784
798
plaintext += self .decryptor .finalize ()
785
799
aws_encryption_sdk .internal .formatting .deserialize .update_verifier_with_tag (
0 commit comments