def _load_verification_key_from_encryption_context(self, algorithm, encryption_context): """Loads the verification key from the encryption context if used by algorithm suite. :param algorithm: Algorithm for which to generate signing key :type algorithm: aws_encryption_sdk.identifiers.Algorithm :param dict encryption_context: Encryption context from request :returns: Raw verification key :rtype: bytes :raises SerializationError: if algorithm suite requires message signing and no verification key is found """ encoded_verification_key = encryption_context.get( ENCODED_SIGNER_KEY, None) if algorithm.signing_algorithm_info is not None and encoded_verification_key is None: raise SerializationError( "No signature verification key found in header for signed algorithm." ) if algorithm.signing_algorithm_info is None: if encoded_verification_key is not None: raise SerializationError( "Signature verification key found in header for non-signed algorithm." ) return None verifier = Verifier.from_encoded_point( algorithm=algorithm, encoded_point=encoded_verification_key) return verifier.key_bytes()
def test_verifier_from_encoded_point( patch_default_backend, patch_serialization, patch_ecc_public_numbers_from_compressed_point, patch_base64, patch_build_hasher): mock_point_instance = MagicMock() mock_point_instance.public_key.return_value = sentinel.public_key patch_ecc_public_numbers_from_compressed_point.return_value = mock_point_instance patch_base64.b64decode.return_value = sentinel.compressed_point algorithm = MagicMock() verifier = Verifier.from_encoded_point( algorithm=algorithm, encoded_point=sentinel.encoded_point) patch_base64.b64decode.assert_called_once_with(sentinel.encoded_point) algorithm.signing_algorithm_info.assert_called_once_with() patch_ecc_public_numbers_from_compressed_point.assert_called_once_with( curve=algorithm.signing_algorithm_info.return_value, compressed_point=sentinel.compressed_point) mock_point_instance.public_key.assert_called_once_with( patch_default_backend.return_value) assert isinstance(verifier, Verifier)