def test_bad_ctx(self): s = signature.sign(SHORT, KEY_1[0]) new_ctx = signature.evp.EVP_MD_CTX_create signature.evp.EVP_MD_CTX_create = lambda: None self.assertRaises(signature.SignatureError, signature.sign, SHORT, KEY_1[0]) self.assertRaises(signature.SignatureError, signature.verify, SHORT, s, KEY_1[1]) signature.evp.EVP_MD_CTX_create = new_ctx
def test_bad_digest_init(self): s = signature.sign(SHORT, KEY_1[0]) init = signature.evp.EVP_DigestInit signature.evp.EVP_DigestInit = lambda a,b: None self.assertRaises(signature.SignatureError, signature.sign, SHORT, KEY_1[0]) self.assertRaises(signature.SignatureError, signature.verify, SHORT, s, KEY_1[1]) signature.evp.EVP_DigestInit = init
def test_bad_hash(self): s = signature.sign(SHORT, KEY_1[0]) new_hash = signature.evp.EVP_get_digestbyname signature.evp.EVP_get_digestbyname = lambda a: None self.assertRaises(signature.SignatureError, signature.sign, SHORT, KEY_1[0]) self.assertRaises(signature.SignatureError, signature.verify, SHORT, s, KEY_1[1]) signature.evp.EVP_get_digestbyname = new_hash
def test_bad_verify_final(self): s = signature.sign(SHORT, KEY_1[0]) final = signature.evp.EVP_VerifyFinal signature.evp.EVP_VerifyFinal = lambda a, b, c, d: None self.assertRaises(signature.SignatureError, signature.verify, SHORT, s, KEY_1[1]) signature.evp.EVP_VerifyFinal = final
def test_bad_read_publickey(self): s = signature.sign(SHORT, KEY_1[0]) read_public_key = signature.evp.PEM_read_PUBKEY signature.evp.PEM_read_PUBKEY = lambda a, b, c, d: None self.assertRaises(signature.SignatureError, signature.verify, SHORT, s, KEY_1[1]) signature.evp.PEM_read_PUBKEY = read_public_key
def test_bad_digest_update(self): s = signature.sign(SHORT, KEY_1[0]) update = signature.evp.EVP_DigestUpdate signature.evp.EVP_DigestUpdate = lambda a,b,c: None self.assertRaises(signature.SignatureError, signature.sign, SHORT, KEY_1[0]) self.assertRaises(signature.SignatureError, signature.verify, SHORT, s, KEY_1[1]) signature.evp.EVP_DigestUpdate = update
def test_bad_fopen(self): s = signature.sign(SHORT, KEY_1[0]) file_open = signature.evp.fopen signature.evp.fopen = lambda a,b: None self.assertRaises(signature.SignatureError, signature.sign, SHORT, KEY_1[1]) self.assertRaises(signature.SignatureError, signature.verify, SHORT, s, KEY_1[0]) signature.evp.fopen = file_open
def test_arguments(self): text = SHORT keys = KEY_1 self.failUnlessRaises(signature.SignatureError, signature.sign, text, key=open(keys[0], 'rb').read(), keyfile=keys[0]) self.failUnlessRaises(signature.SignatureError, signature.sign, text) s = signature.sign(text, keyfile=keys[0]) self.failUnlessRaises(signature.SignatureError, signature.verify, text, s, key=open(keys[1], 'rb').read(), keyfile=keys[1]) self.failUnlessRaises(signature.SignatureError, signature.verify, text, s)
def test_bad_digest_update(self): s = signature.sign(SHORT, KEY_1[0]) update = signature.evp.EVP_DigestUpdate signature.evp.EVP_DigestUpdate = lambda a, b, c: None self.assertRaises(signature.SignatureError, signature.sign, SHORT, KEY_1[0]) self.assertRaises(signature.SignatureError, signature.verify, SHORT, s, KEY_1[1]) signature.evp.EVP_DigestUpdate = update
def test_bad_digest_init(self): s = signature.sign(SHORT, KEY_1[0]) init = signature.evp.EVP_DigestInit signature.evp.EVP_DigestInit = lambda a, b: None self.assertRaises(signature.SignatureError, signature.sign, SHORT, KEY_1[0]) self.assertRaises(signature.SignatureError, signature.verify, SHORT, s, KEY_1[1]) signature.evp.EVP_DigestInit = init
def test_bad_fopen(self): s = signature.sign(SHORT, KEY_1[0]) file_open = signature.evp.fopen signature.evp.fopen = lambda a, b: None self.assertRaises(signature.SignatureError, signature.sign, SHORT, KEY_1[1]) self.assertRaises(signature.SignatureError, signature.verify, SHORT, s, KEY_1[0]) signature.evp.fopen = file_open
def test_bad_verify_final(self): s = signature.sign(SHORT, KEY_1[0]) final = signature.evp.EVP_VerifyFinal signature.evp.EVP_VerifyFinal = lambda a,b,c,d: None self.assertRaises(signature.SignatureError, signature.verify, SHORT, s, KEY_1[1]) signature.evp.EVP_VerifyFinal = final
def round_trip_strings(self, keys, text): s = signature.sign(text, key=open(keys[0], 'rb').read()) v = signature.verify(text, s, key=open(keys[1], 'rb').read()) return v
def test_bad_read_bio_publickey(self): s = signature.sign(SHORT, KEY_1[0]) read_public_key = signature.evp.PEM_read_bio_PUBKEY signature.evp.PEM_read_bio_PUBKEY = lambda a,b,c,d: None self.assertRaises(signature.SignatureError, signature.verify, SHORT, s, key=open(KEY_1[1], 'rb').read()) signature.evp.PEM_read_bio_PUBKEY = read_public_key
def round_trip(self, keys, text): s = signature.sign(text, keys[0]) return signature.verify(text, s, keys[1])