def test_rsa_keys_equal(self): """ Two RSAPrivateKey instances with equal contents are equal and have equal hashes. """ key1 = pem.RSAPrivateKey(b"test") key2 = pem.RSAPrivateKey(b"test") assert key1 == key2 assert key2 == key1 assert hash(key1) == hash(key2)
def test_rsa_key_has_correct_str(self): """ Calling str on a RSAPrivateKey instance returns the proper string. """ key = pem.RSAPrivateKey(b"test") assert str(key) == "test"
def test_rsa_private_key_has_correct_repr(self): """ Calling repr on a RSAPrivateKey instance returns the proper string. """ key = pem.RSAPrivateKey(b"test") assert "<RSAPrivateKey({0})>".format(TEST_DIGEST) == repr(key)
def test_rsa_key_unicode(self): """ Passing unicode to RSAPrivateKey encodes the string as ASCII. """ key = pem.RSAPrivateKey(u'a string') assert key.as_bytes() == b'a string' assert str(key) == 'a string'
def test_different_objects_unequal(self): """ Two PEM objects of different types but with equal contents are not equal. """ cert = pem.Certificate(b"test") key = pem.Key(b"test") rsa_key = pem.RSAPrivateKey(b"test") assert cert != key assert key != cert assert key != rsa_key assert rsa_key != key
def test_different_objects_unequal(self): """ Two PEM objects of different types but with equal contents are not equal. """ c = b"test" pems = [ pem.Certificate(c), pem.CertificateRequest(c), pem.Key(c), pem.RSAPrivateKey(c), pem.CertificateRevocationList(c), ] for pem1, pem2 in combinations(pems, 2): assert not pem1 == pem2 assert pem1 != pem2
import tempfile import shutil import pem from twisted.internet import defer from twisted.python.compat import unicode from twisted.python.filepath import FilePath from twisted.trial.unittest import TestCase from txacme.store import DirectoryStore from txacme.testing import MemoryStore EXAMPLE_PEM_OBJECTS = [ pem.RSAPrivateKey( b'-----BEGIN RSA PRIVATE KEY-----\n' b'iq63EP+H3w==\n' b'-----END RSA PRIVATE KEY-----\n'), pem.Certificate( b'-----BEGIN CERTIFICATE-----\n' b'yns=\n' b'-----END CERTIFICATE-----\n'), pem.Certificate( b'-----BEGIN CERTIFICATE-----\n' b'pNaiqhAT\n' b'-----END CERTIFICATE-----\n'), ] EXAMPLE_PEM_OBJECTS2 = [ pem.RSAPrivateKey( b'-----BEGIN RSA PRIVATE KEY-----\n' b'fQ==\n'
def test_rsa_key_has_correct_repr(self): """ Calling repr on a RSAPrivateKey instance returns the proper string. """ key = pem.RSAPrivateKey('test') assert "<RSAPrivateKey(pem_str='test')>" == repr(key)