Example #1
0
 def _set_signature_type(self):
     """Ensures that the algorithm signature type is a known type and sets a reference value."""
     try:
         verify_interface(ec.EllipticCurve,
                          self.algorithm.signing_algorithm_info)
         return ec.EllipticCurve
     except InterfaceNotImplemented:
         raise NotSupportedError("Unsupported signing algorithm info")
    def test_verify_missing_method(self):
        class SimpleInterface(metaclass=abc.ABCMeta):
            @abc.abstractmethod
            def method(self):
                """A simple method"""

        class NonImplementer(object):
            pass

        with pytest.raises(InterfaceNotImplemented):
            verify_interface(SimpleInterface, NonImplementer)
Example #3
0
    def test_verify_missing_method(self):
        @six.add_metaclass(abc.ABCMeta)
        class SimpleInterface(object):
            @abc.abstractmethod
            def method(self):
                """A simple method"""

        class NonImplementer(object):
            pass

        with pytest.raises(InterfaceNotImplemented):
            verify_interface(SimpleInterface, NonImplementer)
    def test_handles_abstract_property(self):
        @six.add_metaclass(abc.ABCMeta)
        class SimpleInterface(object):
            @abc.abstractproperty
            def property(self):
                """An abstract property"""

        class NonImplementer(object):
            @property
            def property(self):
                """A concrete property"""

        verify_interface(SimpleInterface, NonImplementer)
    def test_different_arguments(self):
        @six.add_metaclass(abc.ABCMeta)
        class SimpleInterface(object):
            @abc.abstractmethod
            def method(self, a):
                """Method with one argument"""

        class NonImplementer(object):
            def method(self):
                """Method with no arguments"""

        with pytest.raises(InterfaceNotImplemented):
            verify_interface(SimpleInterface, NonImplementer)
Example #6
0
def generate_ecc_signing_key(algorithm):
    """Returns an ECC signing key.

    :param algorithm: Algorithm object which determines what signature to generate
    :type algorithm: aws_encryption_sdk.identifiers.Algorithm
    :returns: Generated signing key
    :raises NotSupportedError: if signing algorithm is not supported on this platform
    """
    try:
        verify_interface(ec.EllipticCurve, algorithm.signing_algorithm_info)
        return ec.generate_private_key(curve=algorithm.signing_algorithm_info(), backend=default_backend())
    except InterfaceNotImplemented:
        raise NotSupportedError("Unsupported signing algorithm info")
    def test_handles_abstract_property(self):
        class SimpleInterface(metaclass=abc.ABCMeta):
            @abc.abstractproperty
            def property(self):
                """An abstract property"""

        class NonImplementer(object):
            @property
            def property(self):
                """A concrete property"""

        # Invoke this to ensure the line is covered
        NonImplementer().property
        verify_interface(SimpleInterface, NonImplementer)
    def test_different_arguments(self):
        class SimpleInterface(metaclass=abc.ABCMeta):
            @abc.abstractmethod
            def method(self, a):
                """Method with one argument"""

        class NonImplementer(object):
            def method(self):
                """Method with no arguments"""

        # Invoke this to ensure the line is covered
        NonImplementer().method()
        with pytest.raises(InterfaceNotImplemented):
            verify_interface(SimpleInterface, NonImplementer)
Example #9
0
    def test_handles_abstract_property(self):
        @six.add_metaclass(abc.ABCMeta)
        class SimpleInterface(object):
            @abc.abstractproperty
            def property(self):
                """An abstract property"""

        class NonImplementer(object):
            @property
            def property(self):
                """A concrete property"""

        # Invoke this to ensure the line is covered
        NonImplementer().property
        verify_interface(SimpleInterface, NonImplementer)
    def test_signature_mismatch(self):
        class SimpleInterface(metaclass=abc.ABCMeta):
            @abc.abstractmethod
            def method(self, other: object) -> int:
                """Method with signature"""

        class ClassWithoutSignature:
            def method(self, other):
                """Method without signature"""

        class ClassWithSignature:
            def method(self, other: object) -> int:
                """Method with signature"""

        verify_interface(SimpleInterface, ClassWithoutSignature)
        verify_interface(SimpleInterface, ClassWithSignature)
        with pytest.raises(InterfaceNotImplemented):
            verify_interface(SimpleInterface,
                             ClassWithoutSignature,
                             check_annotations=True)
        verify_interface(SimpleInterface,
                         ClassWithSignature,
                         check_annotations=True)