Skip to content

Commit 8b8a141

Browse files
author
Shubham Chaturvedi
committed
fix: ec isinstance fix
1 parent 01cde29 commit 8b8a141

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/aws_encryption_sdk/internal/crypto/authentication.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ def __init__(self, algorithm, key):
3636

3737
def _set_signature_type(self):
3838
"""Ensures that the algorithm signature type is a known type and sets a reference value."""
39-
if not isinstance(self.algorithm.signing_algorithm_info, type(ec.EllipticCurve)):
39+
try:
40+
if not issubclass(self.algorithm.signing_algorithm_info, ec.EllipticCurve):
41+
raise NotSupportedError("Unsupported signing algorithm info")
42+
except TypeError:
4043
raise NotSupportedError("Unsupported signing algorithm info")
4144
return ec.EllipticCurve
4245

test/unit/test_crypto_prehashing_authenticator.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pytest
55
from mock import MagicMock, sentinel
66
from pytest_mock import mocker # noqa pylint: disable=unused-import
7+
from cryptography.hazmat.primitives.asymmetric import ec
78

89
import aws_encryption_sdk.internal.crypto.authentication
910
from aws_encryption_sdk.exceptions import NotSupportedError
@@ -56,12 +57,19 @@ def test_init(patch_set_signature_type, patch_build_hasher):
5657
def test_set_signature_type_elliptic_curve(
5758
patch_build_hasher, patch_cryptography_ec
5859
):
59-
mock_algorithm_info = MagicMock(return_value=sentinel.algorithm_info, spec=patch_cryptography_ec.EllipticCurve)
60-
mock_algorithm = MagicMock(signing_algorithm_info=mock_algorithm_info)
60+
patch_cryptography_ec.EllipticCurve = ec.EllipticCurve
61+
mock_algorithm = MagicMock(signing_algorithm_info=ec.SECP256R1)
6162
test = _PrehashingAuthenticator(algorithm=mock_algorithm, key=sentinel.key)
6263

6364
assert test._signature_type is patch_cryptography_ec.EllipticCurve
6465

66+
def test_set_signature_type_elliptic_curve_known_value(patch_build_hasher):
67+
from cryptography.hazmat.primitives.asymmetric import ec as real_ec
68+
69+
mock_algorithm = MagicMock(signing_algorithm_info=real_ec.SECP384R1)
70+
test = _PrehashingAuthenticator(algorithm=mock_algorithm, key=sentinel.key)
71+
72+
assert test._signature_type is real_ec.EllipticCurve
6573

6674
def test_set_signature_type_unknown(
6775
patch_build_hasher, patch_cryptography_ec

0 commit comments

Comments
 (0)