File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2020)
2121from .identity import Identity
2222from .kdf import derive_key_confirmation , derive_message_key , derive_session_root
23- from .protocol import MAX_MESSAGE_SEQUENCE , PROTOCOL_VERSION , validate_message_sequence
23+ from .protocol import (
24+ MAX_MESSAGE_SEQUENCE ,
25+ MAX_PLAINTEXT_BYTES ,
26+ PROTOCOL_VERSION ,
27+ validate_message_sequence ,
28+ )
2429from .replay import ReplayWindow
2530from .wire import MessageEnvelope
2631
@@ -49,6 +54,10 @@ def _build_aead(self, key: bytes):
4954 raise ValueError (f"unsupported suite: { self .suite } " )
5055
5156 def encrypt (self , plaintext : bytes ) -> bytes :
57+ if type (plaintext ) is not bytes :
58+ raise TypeError ("plaintext must be bytes" )
59+ if len (plaintext ) > MAX_PLAINTEXT_BYTES :
60+ raise ValueError ("plaintext exceeds the maximum message size" )
5261 if self .send_sequence > MAX_MESSAGE_SEQUENCE :
5362 raise OverflowError ("message sequence exhausted" )
5463 validate_message_sequence (self .send_sequence )
You can’t perform that action at this time.
0 commit comments