1# coding: utf-8 2from __future__ import unicode_literals, division, absolute_import, print_function 3 4import unittest 5import sys 6import os 7 8from asn1crypto import algos, core 9from ._unittest_compat import patch 10 11patch() 12 13if sys.version_info < (3,): 14 byte_cls = str 15 num_cls = long # noqa 16else: 17 byte_cls = bytes 18 num_cls = int 19 20 21tests_root = os.path.dirname(__file__) 22fixtures_dir = os.path.join(tests_root, 'fixtures') 23 24 25class AlgoTests(unittest.TestCase): 26 27 def test_signed_digest_parameters(self): 28 sha256_rsa = algos.SignedDigestAlgorithm({'algorithm': 'sha256_rsa'}) 29 self.assertEqual(core.Null, sha256_rsa['parameters'].__class__) 30 31 def test_digest_parameters(self): 32 sha1 = algos.DigestAlgorithm({'algorithm': 'sha1'}) 33 self.assertEqual(core.Null, sha1['parameters'].__class__) 34 35 def test_ccm_parameters(self): 36 with open(os.path.join(fixtures_dir, 'aesccm_algo.der'), 'rb') as f: 37 # PBES2 AlgorithmIdentifier 38 algo = algos.EncryptionAlgorithm().load(f.read()) 39 scheme = algo['parameters']['encryption_scheme'] 40 self.assertEqual(scheme['parameters'].__class__, algos.CcmParams) 41 self.assertEqual(scheme['parameters']['aes_nonce'].__class__, core.OctetString) 42 self.assertEqual(scheme['parameters']['aes_nonce'].native, b'z\xb7\xbd\xb7\xe1\xc6\xc0\x11\xc1?\xf00') 43 self.assertEqual(scheme['parameters']['aes_icvlen'].__class__, core.Integer) 44 self.assertEqual(scheme['parameters']['aes_icvlen'].native, 8) 45