"""Interface to ECC signature algorithm and key-exchange."""from__future__importannotationsimporttypingfrompyflocker.ciphers.backendsimportload_algorithmas_load_algoiftyping.TYPE_CHECKING:fromtypesimportModuleTypefrompyflocker.ciphersimportbasefrompyflocker.ciphers.backendsimportBackendsdef_load_ecc_cpr(backend:Backends|None)->ModuleType:"""Load the cipher module from the backend."""return_load_algo("ECC",backend)
[docs]defgenerate(curve:str,*,backend:Backends|None=None,)->base.BaseECCPrivateKey:""" Generate a private key with given curve ``curve``. Args: curve: The name of the curve to use. Keyword Arguments: backend: The backend to use. It must be a value from :any:`Backends`. Returns: An ECC private key. Raises: ValueError: if the curve is not supported by the backend or the name of the curve is invalid. """return_load_ecc_cpr(backend).generate(curve)
[docs]defload_public_key(data:bytes,*,curve:str|None=None,backend:Backends|None=None,)->base.BaseECCPublicKey:"""Loads the public key and returns a Key interface. Args: data: The public key (a bytes-like object) to deserialize. curve: The name of the curve. Required only for ``SEC1`` and ``Raw`` keys. Keyword Arguments: backend: The backend to use. It must be a value from :any:`Backends`. Returns: An ECC public key. """return_load_ecc_cpr(backend).load_public_key(data,curve=curve)
[docs]defload_private_key(data:bytes,passphrase:bytes|None=None,*,curve:str|None=None,backend:Backends|None=None,)->base.BaseECCPrivateKey:"""Loads the private key and returns a Key interface. If the private key was not encrypted duting the serialization, `passphrase` must be `None`, otherwise it must be a `bytes` object. Args: data: The private key (a bytes-like object) to deserialize. passphrase: The passphrase (in bytes) that was used to encrypt the private key. `None` if the key was not encrypted. curve: The name of the curve. Required only for ``Raw`` keys. Keyword Arguments: backend: The backend to use. It must be a value from `Backends`. Returns: An ECC Private key. """return_load_ecc_cpr(backend).load_private_key(data,passphrase,curve=curve,)