Skip to content

Commit

Permalink
Implement __deepcopy__ for x509 certificates (#5318)
Browse files Browse the repository at this point in the history
fixes #5129
  • Loading branch information
alex authored Jul 19, 2020
1 parent c51f795 commit b8656fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cryptography/hazmat/backends/openssl/x509.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def __ne__(self, other):
def __hash__(self):
return hash(self.public_bytes(serialization.Encoding.DER))

def __deepcopy__(self, memo):
return self

def fingerprint(self, algorithm):
h = hashes.Hash(algorithm, self._backend)
h.update(self.public_bytes(serialization.Encoding.DER))
Expand Down
9 changes: 9 additions & 0 deletions tests/x509/test_x509.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import binascii
import collections
import copy
import datetime
import ipaddress
import os
Expand Down Expand Up @@ -4807,6 +4808,14 @@ def test_load_pem_cert(self, backend):
assert cert.signature_hash_algorithm is None
assert cert.signature_algorithm_oid == SignatureAlgorithmOID.ED25519

def test_deepcopy(self, backend):
cert = _load_cert(
os.path.join("x509", "ed25519", "root-ed25519.pem"),
x509.load_pem_x509_certificate,
backend
)
assert copy.deepcopy(cert) is cert


@pytest.mark.supported(
only_if=lambda backend: backend.ed448_supported(),
Expand Down

0 comments on commit b8656fc

Please sign in to comment.