def __assure_public_key(public_key: ec) -> None: """ Check if a public key is a public key :param public_key: ec the public key to check :raises InvalidKey: if given key is invalid :return: None """ public_keys = (ec.EllipticCurvePublicKey, ec.EllipticCurvePublicNumbers, ec.EllipticCurvePublicKeyWithSerialization) if not isinstance(public_key, public_keys): raise InvalidKey("Given key is not a public key")
def __assure_public_key(public_key: rsa) -> None: """ Check if a public key is a public key :param public_key: rsa the public key to check :raises InvalidKey: if given key is invalid :return: None """ public_keys = (rsa.RSAPublicKey, rsa.RSAPublicNumbers, rsa.RSAPublicKeyWithSerialization) if not isinstance(public_key, public_keys): raise InvalidKey("Given key is not a public key")
def __assure_private_key(private_key: ec) -> None: """ Check if a private key is a private key :param private_key: ec the private key to check :raises InvalidKey: if given key is invalid :return: None """ private_keys = (ec.EllipticCurvePrivateKey, ec.EllipticCurvePrivateNumbers, ec.EllipticCurvePrivateNumbers) if not isinstance(private_key, private_keys): raise InvalidKey("Given key is not a private key")
def __assure_private_key(private_key: rsa) -> None: """ Check if a private key is a private key :param private_key: rsa the private key to check :raises InvalidKey: if given key is invalid :return: None """ private_keys = (rsa.RSAPrivateKey, rsa.RSAPrivateNumbers, rsa.RSAPrivateKeyWithSerialization) if not isinstance(private_key, private_keys): raise InvalidKey("Given key is not a private key")
def verify(self, key_material, expected_key): derived_key = self.derive(key_material) if not constant_time.bytes_eq(derived_key, expected_key): raise InvalidKey("Keys do not match.")