[docs]classChaCha20(NonAEADCipherTemplate):"""ChaCha20 Cipher class. This class alone does not provide any authentication. For AEAD purposes, wrap ``ChaCha20`` object with a class that implements ``BaseAEADCipher`` or use ``ChaCha20Poly1305``. """def__init__(self,encrypting:bool,key:bytes,nonce:bytes)->None:self._cipher=_ChaCha20.new(key=key,nonce=nonce)self._encrypting=encryptingself._update_func=(self._cipher.encryptifencryptingelseself._cipher.decrypt)
[docs]defnew(encrypting:bool,key:bytes,nonce:bytes,*,use_poly1305:bool=True,file:io.BufferedIOBase|None=None,)->ChaCha20|ChaCha20Poly1305|FileCipherWrapper:"""Instantiate a new ChaCha20-Poly1305 cipher wrapper object. Args: encrypting: True is encryption and False is decryption. key: The key for the cipher. nonce: The Nonce for the cipher. It must not be repeated with the same key. Keyword Arguments: use_poly1305: Whether to use Poly1305 MAC with ChaCha20 cipher. file: The source file to read from. Returns: ChaCha20(-Poly1305) cipher wrapper object. Note: Any other error that is raised is from the backend itself. """crp:typing.AnyiffileisnotNone:use_poly1305=Trueifuse_poly1305:crp=ChaCha20Poly1305(encrypting,key,nonce)else:crp=ChaCha20(encrypting,key,nonce)iffile:crp=FileCipherWrapper(crp,file)returncrp