def test_non_hashlib_oid(self): invalid = DigestAlgorithmIdentifier() invalid['algorithm'] = (1, 2, 840, 113549, 1, 9, 3) self.assertRaises(ParseError, _get_digest_algorithm, invalid, location="test")
def test_unknown_oid(self): invalid = DigestAlgorithmIdentifier() invalid['algorithm'] = (1, 2) self.assertRaises(ParseError, _get_digest_algorithm, invalid, location="test")
def test_non_null_parameters(self): sha1 = DigestAlgorithmIdentifier() sha1['algorithm'] = (1, 3, 14, 3, 2, 26) sha1['parameters'] = "\x01\x01\xff" # TRUE boolean self.assertRaises(ParseError, _get_digest_algorithm, sha1, location="test")
def test_unacceptable_oid(self): sha1 = DigestAlgorithmIdentifier() sha1['algorithm'] = (1, 3, 14, 3, 2, 26) self.assertRaises(ParseError, _get_digest_algorithm, sha1, location="test", acceptable=[hashlib.md5])
def test_null_parameters(self): sha1 = DigestAlgorithmIdentifier() sha1['algorithm'] = (1, 3, 14, 3, 2, 26) sha1['parameters'] = "\x05\0" # null value self.assertEqual(_get_digest_algorithm(sha1, location="test"), hashlib.sha1)
def test_acceptable_oid(self): sha1 = DigestAlgorithmIdentifier() sha1['algorithm'] = (1, 3, 14, 3, 2, 26) self.assertEqual(_get_digest_algorithm(sha1, location="test"), hashlib.sha1)
id_contentType = univ.ObjectIdentifier("1.2.840.113549.1.9.3") id_counterSignature = univ.ObjectIdentifier("1.2.840.113549.1.9.6") id_individualCodeSigning = univ.ObjectIdentifier("1.3.6.1.4.1.311.2.1.21") id_messageDigest = univ.ObjectIdentifier("1.2.840.113549.1.9.4") id_rsaEncryption = univ.ObjectIdentifier("1.2.840.113549.1.1.1") id_sha1 = univ.ObjectIdentifier("1.3.14.3.2.26") id_sha256 = univ.ObjectIdentifier("2.16.840.1.101.3.4.2.1") id_signedData = univ.ObjectIdentifier("1.2.840.113549.1.7.2") id_signingTime = univ.ObjectIdentifier("1.2.840.113549.1.9.5") id_spcIndirectDataContext = univ.ObjectIdentifier("1.3.6.1.4.1.311.2.1.4") id_spcSpOpusInfo = univ.ObjectIdentifier("1.3.6.1.4.1.311.2.1.12") id_spcStatementType = univ.ObjectIdentifier("1.3.6.1.4.1.311.2.1.11") id_timestampSignature = univ.ObjectIdentifier("1.3.6.1.4.1.311.3.3.1") algo_sha1 = (DigestAlgorithmIdentifier().setComponentByName( "algorithm", id_sha1).setComponentByName("parameters", univ.Null(""))) algo_sha256 = (DigestAlgorithmIdentifier().setComponentByName( "algorithm", id_sha256).setComponentByName("parameters", univ.Null(""))) ASN_DIGEST_ALGO_MAP = {"sha1": algo_sha1, "sha256": algo_sha256} class SpcString(univ.Choice): """SPC String class represetning unicode or ascii strings.""" componentType = namedtype.NamedTypes( namedtype.NamedType( "unicode", char.BMPString(encoding="utf-16-be").subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatSimple, 0)),