Python cryptography.hazmat.primitives.ciphers.algorithms.IDEA Examples

The following are 5 code examples of cryptography.hazmat.primitives.ciphers.algorithms.IDEA(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module cryptography.hazmat.primitives.ciphers.algorithms , or try the search function .
Example #1
Source File: constants.py    From PGPy with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def cipher(self):
        bs = {SymmetricKeyAlgorithm.IDEA: algorithms.IDEA,
              SymmetricKeyAlgorithm.TripleDES: algorithms.TripleDES,
              SymmetricKeyAlgorithm.CAST5: algorithms.CAST5,
              SymmetricKeyAlgorithm.Blowfish: algorithms.Blowfish,
              SymmetricKeyAlgorithm.AES128: algorithms.AES,
              SymmetricKeyAlgorithm.AES192: algorithms.AES,
              SymmetricKeyAlgorithm.AES256: algorithms.AES,
              SymmetricKeyAlgorithm.Twofish256: namedtuple('Twofish256', ['block_size'])(block_size=128),
              SymmetricKeyAlgorithm.Camellia128: algorithms.Camellia,
              SymmetricKeyAlgorithm.Camellia192: algorithms.Camellia,
              SymmetricKeyAlgorithm.Camellia256: algorithms.Camellia}

        if self in bs:
            return bs[self]

        raise NotImplementedError(repr(self)) 
Example #2
Source File: constants.py    From PGPy with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def key_size(self):
        ks = {SymmetricKeyAlgorithm.IDEA: 128,
              SymmetricKeyAlgorithm.TripleDES: 192,
              SymmetricKeyAlgorithm.CAST5: 128,
              SymmetricKeyAlgorithm.Blowfish: 128,
              SymmetricKeyAlgorithm.AES128: 128,
              SymmetricKeyAlgorithm.AES192: 192,
              SymmetricKeyAlgorithm.AES256: 256,
              SymmetricKeyAlgorithm.Twofish256: 256,
              SymmetricKeyAlgorithm.Camellia128: 128,
              SymmetricKeyAlgorithm.Camellia192: 192,
              SymmetricKeyAlgorithm.Camellia256: 256}

        if self in ks:
            return ks[self]

        raise NotImplementedError(repr(self)) 
Example #3
Source File: constants.py    From PGPy with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def is_insecure(self):
        insecure_ciphers = {SymmetricKeyAlgorithm.IDEA}
        return self in insecure_ciphers 
Example #4
Source File: test_bad_cryptography_module_attribute_use.py    From dlint with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def test_bad_cryptography_module_attribute_usage(self):
        python_node = self.get_ast_node(
            """
            import cryptography.hazmat.primitives.hashes
            import cryptography.hazmat.primitives.ciphers.modes
            import cryptography.hazmat.primitives.ciphers.algorithms
            import cryptography.hazmat.primitives.asymmetric.padding

            cryptography.hazmat.primitives.hashes.MD5
            cryptography.hazmat.primitives.hashes.SHA1
            cryptography.hazmat.primitives.ciphers.modes.ECB
            cryptography.hazmat.primitives.ciphers.algorithms.Blowfish
            cryptography.hazmat.primitives.ciphers.algorithms.ARC4
            cryptography.hazmat.primitives.ciphers.algorithms.IDEA
            cryptography.hazmat.primitives.asymmetric.padding.PKCS1v15
            """
        )

        linter = dlint.linters.BadCryptographyModuleAttributeUseLinter()
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=7,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=8,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=9,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=10,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=11,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=12,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=13,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
        ]

        assert result == expected 
Example #5
Source File: test_bad_cryptography_module_attribute_use.py    From dlint with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def test_bad_cryptography_module_attribute_usage_from_import(self):
        python_node = self.get_ast_node(
            """
            from cryptography.hazmat.primitives import hashes
            from cryptography.hazmat.primitives.ciphers import modes
            from cryptography.hazmat.primitives.ciphers import algorithms
            from cryptography.hazmat.primitives.asymmetric import padding

            hashes.MD5
            hashes.SHA1
            modes.ECB
            algorithms.Blowfish
            algorithms.ARC4
            algorithms.IDEA
            padding.PKCS1v15
            """
        )

        linter = dlint.linters.BadCryptographyModuleAttributeUseLinter()
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=7,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=8,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=9,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=10,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=11,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=12,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=13,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
        ]

        assert result == expected