diff options
| author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2020-07-18 21:11:23 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-18 22:11:23 -0400 |
| commit | 1604ea7ec0156a750c005a2d0cbddac83eebd14a (patch) | |
| tree | 3cbd26afc18b86175f1f177deca24b2e0656dcf0 /src/cryptography | |
| parent | b8656fc001c7752eafd4f064dcd994931c313eb4 (diff) | |
| download | cryptography-1604ea7ec0156a750c005a2d0cbddac83eebd14a.tar.gz | |
test exceptions and properly reject duplicate attributes in csrbuilder (#5319)
Diffstat (limited to 'src/cryptography')
| -rw-r--r-- | src/cryptography/x509/base.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/cryptography/x509/base.py b/src/cryptography/x509/base.py index 43c8305bf..526fb5d6d 100644 --- a/src/cryptography/x509/base.py +++ b/src/cryptography/x509/base.py @@ -36,6 +36,13 @@ def _reject_duplicate_extension(extension, extensions): raise ValueError('This extension has already been set.') +def _reject_duplicate_attribute(oid, attributes): + # This is quadratic in the number of attributes + for attr_oid, _ in attributes: + if attr_oid == oid: + raise ValueError('This attribute has already been set.') + + def _convert_to_naive_utc_time(time): """Normalizes a datetime to a naive datetime in UTC. @@ -448,6 +455,8 @@ class CertificateSigningRequestBuilder(object): if not isinstance(value, bytes): raise TypeError("value must be bytes") + _reject_duplicate_attribute(oid, self._attributes) + return CertificateSigningRequestBuilder( self._subject_name, self._extensions, self._attributes + [(oid, value)] |
