aboutsummaryrefslogtreecommitdiffstats
path: root/src/cryptography
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2015-08-09 20:40:48 -0500
committerPaul Kehrer <paul.l.kehrer@gmail.com>2015-08-09 20:40:48 -0500
commited036d25a60e4177c4e7f8fb5961d9048cdb3802 (patch)
treec783715fce017a0794b86e8cdc99dc2a64178978 /src/cryptography
parenta1584fd8baf8d636e36321d5394b77bd0afa2529 (diff)
downloadcryptography-ed036d25a60e4177c4e7f8fb5961d9048cdb3802.tar.gz
cryptography-ed036d25a60e4177c4e7f8fb5961d9048cdb3802.tar.bz2
cryptography-ed036d25a60e4177c4e7f8fb5961d9048cdb3802.zip
split Name from x509 module
Diffstat (limited to 'src/cryptography')
-rw-r--r--src/cryptography/x509/__init__.py3
-rw-r--r--src/cryptography/x509/base.py61
-rw-r--r--src/cryptography/x509/name.py70
3 files changed, 73 insertions, 61 deletions
diff --git a/src/cryptography/x509/__init__.py b/src/cryptography/x509/__init__.py
index 1283867f..45923b31 100644
--- a/src/cryptography/x509/__init__.py
+++ b/src/cryptography/x509/__init__.py
@@ -12,7 +12,7 @@ from cryptography.x509.base import (
DistributionPoint, DuplicateExtension, ExtendedKeyUsage,
Extension, ExtensionNotFound, ExtensionType, Extensions, GeneralName,
GeneralNames, IPAddress, InhibitAnyPolicy, InvalidVersion,
- IssuerAlternativeName, KeyUsage, Name, NameAttribute, NameConstraints,
+ IssuerAlternativeName, KeyUsage, NameConstraints,
NoticeReference, OCSPNoCheck, ObjectIdentifier, OtherName,
PolicyInformation, RFC822Name, ReasonFlags, RegisteredID,
RevokedCertificate, SubjectAlternativeName, SubjectKeyIdentifier,
@@ -21,6 +21,7 @@ from cryptography.x509.base import (
load_der_x509_certificate,
load_der_x509_csr, load_pem_x509_certificate, load_pem_x509_csr,
)
+from cryptography.x509.name import Name, NameAttribute
from cryptography.x509.oid import (
OID_ANY_POLICY, OID_AUTHORITY_INFORMATION_ACCESS,
OID_AUTHORITY_KEY_IDENTIFIER, OID_BASIC_CONSTRAINTS, OID_CA_ISSUERS,
diff --git a/src/cryptography/x509/base.py b/src/cryptography/x509/base.py
index 6fdc0f57..29e6e878 100644
--- a/src/cryptography/x509/base.py
+++ b/src/cryptography/x509/base.py
@@ -23,6 +23,7 @@ from six.moves import urllib_parse
from cryptography import utils
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import dsa, ec, rsa
+from cryptography.x509.name import Name
from cryptography.x509.oid import (
OID_AUTHORITY_INFORMATION_ACCESS,
OID_AUTHORITY_KEY_IDENTIFIER, OID_BASIC_CONSTRAINTS,
@@ -128,66 +129,6 @@ class UnsupportedGeneralNameType(Exception):
self.type = type
-class NameAttribute(object):
- def __init__(self, oid, value):
- if not isinstance(oid, ObjectIdentifier):
- raise TypeError(
- "oid argument must be an ObjectIdentifier instance."
- )
-
- if not isinstance(value, six.text_type):
- raise TypeError(
- "value argument must be a text type."
- )
-
- self._oid = oid
- self._value = value
-
- oid = utils.read_only_property("_oid")
- value = utils.read_only_property("_value")
-
- def __eq__(self, other):
- if not isinstance(other, NameAttribute):
- return NotImplemented
-
- return (
- self.oid == other.oid and
- self.value == other.value
- )
-
- def __ne__(self, other):
- return not self == other
-
- def __repr__(self):
- return "<NameAttribute(oid={0.oid}, value={0.value!r})>".format(self)
-
-
-class Name(object):
- def __init__(self, attributes):
- self._attributes = attributes
-
- def get_attributes_for_oid(self, oid):
- return [i for i in self if i.oid == oid]
-
- def __eq__(self, other):
- if not isinstance(other, Name):
- return NotImplemented
-
- return self._attributes == other._attributes
-
- def __ne__(self, other):
- return not self == other
-
- def __iter__(self):
- return iter(self._attributes)
-
- def __len__(self):
- return len(self._attributes)
-
- def __repr__(self):
- return "<Name({0!r})>".format(self._attributes)
-
-
class Extensions(object):
def __init__(self, extensions):
self._extensions = extensions
diff --git a/src/cryptography/x509/name.py b/src/cryptography/x509/name.py
new file mode 100644
index 00000000..992786ef
--- /dev/null
+++ b/src/cryptography/x509/name.py
@@ -0,0 +1,70 @@
+# This file is dual licensed under the terms of the Apache License, Version
+# 2.0, and the BSD License. See the LICENSE file in the root of this repository
+# for complete details.
+
+from __future__ import absolute_import, division, print_function
+
+import six
+
+from cryptography import utils
+from cryptography.x509.oid import ObjectIdentifier
+
+
+class NameAttribute(object):
+ def __init__(self, oid, value):
+ if not isinstance(oid, ObjectIdentifier):
+ raise TypeError(
+ "oid argument must be an ObjectIdentifier instance."
+ )
+
+ if not isinstance(value, six.text_type):
+ raise TypeError(
+ "value argument must be a text type."
+ )
+
+ self._oid = oid
+ self._value = value
+
+ oid = utils.read_only_property("_oid")
+ value = utils.read_only_property("_value")
+
+ def __eq__(self, other):
+ if not isinstance(other, NameAttribute):
+ return NotImplemented
+
+ return (
+ self.oid == other.oid and
+ self.value == other.value
+ )
+
+ def __ne__(self, other):
+ return not self == other
+
+ def __repr__(self):
+ return "<NameAttribute(oid={0.oid}, value={0.value!r})>".format(self)
+
+
+class Name(object):
+ def __init__(self, attributes):
+ self._attributes = attributes
+
+ def get_attributes_for_oid(self, oid):
+ return [i for i in self if i.oid == oid]
+
+ def __eq__(self, other):
+ if not isinstance(other, Name):
+ return NotImplemented
+
+ return self._attributes == other._attributes
+
+ def __ne__(self, other):
+ return not self == other
+
+ def __iter__(self):
+ return iter(self._attributes)
+
+ def __len__(self):
+ return len(self._attributes)
+
+ def __repr__(self):
+ return "<Name({0!r})>".format(self._attributes)