Skip to content

copy/deepcopy broken in cryptography 38 #7587

@mathiasertl

Description

@mathiasertl

Hi,

Since cryptography 38 it is no longer possible to use copy/deepcopy with some (many?) cryptography objects. I assume that this is due to them being ported to Rust (which is not at all mentioned in the changelog, btw :-(). One example I have found is ObjectIdentifier, but I assume there may be others:

>>> import copy
>>> from cryptography import x509
>>> copy.copy(x509.NameOID.COMMON_NAME)
...
TypeError: cannot pickle 'builtins.ObjectIdentifier' object
>>> copy.deepcopy(x509.NameOID.COMMON_NAME)
...
TypeError: cannot pickle 'builtins.ObjectIdentifier' object

This can easily cause problems in Python code:

>>> class Test:
...     def __init__(self, oid):
...         self.oid = oid
>>> copy.deepcopy(Test(x509.NameOID.COMMON_NAME))
...
TypeError: cannot pickle 'builtins.ObjectIdentifier' object
>>> copy.deepcopy({x509.NameOID.COMMON_NAME: 'CommonName'})
...
TypeError: cannot pickle 'builtins.ObjectIdentifier' object

This works in cryptography==37.0.4:

>>> copy.deepcopy({x509.NameOID.COMMON_NAME: 'CommonName'})
{<ObjectIdentifier(oid=2.5.4.3, name=commonName)>: 'CommonName'}

The copy module says that implementing copy/deepcopy would fix the issue (so no, no pickle required).

Can we implement this again? I'm not a Rust developer, but I'm willing to try of course.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions