def test_keys_equal(self): """ Two Key instances with equal contents are equal and have equal hashes. """ key1 = pem.Key(b"test") key2 = pem.Key(b"test") assert key1 == key2 assert key2 == key1 assert hash(key1) == hash(key2)
def test_key_has_correct_str(self): """ Calling str on a Key instance returns the proper string. """ key = pem.Key(b"test") assert str(key) == "test"
def test_key_has_correct_repr(self): """ Calling repr on a Key instance returns the proper string. """ key = pem.Key(b"test") assert "<Key({0})>".format(TEST_DIGEST) == repr(key)
def test_key_unicode(self): """ Passing unicode to Key encodes the string as ASCII. """ key = pem.Key(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 _issue_cert(self, server_names): """ Issue a new cert for the list of server_names. `server_names` is already canonized. """ names = [n.strip() for n in server_names.split(',')] log.info('Requesting a certificate for {server_names!r}.', server_names=server_names) key = self._generate_key() objects = [ pem.Key( key.private_bytes( encoding=serialization.Encoding.PEM, format=serialization.PrivateFormat.TraditionalOpenSSL, encryption_algorithm=serialization.NoEncryption())) ] @defer.inlineCallbacks def answer_to_order(orderr): """ Answer the challenges associated with the order. """ for authorization in orderr.authorizations: yield answer_challenge( authorization, self._client, self._responders, clock=self._clock, ) certificate = yield get_certificate(orderr, self._client, clock=self._clock) defer.returnValue(certificate) def got_cert(certr): """ Called when we got a certificate. """ # The certificate is returned as chain. objects.extend(pem.parse(certr.body)) self.cert_store.store(','.join(names), objects) return (self._client.submit_order( key, names).addCallback(answer_to_order).addCallback(got_cert))
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