disallow empty string for NameAttribute (#3711)
diff --git a/src/cryptography/x509/name.py b/src/cryptography/x509/name.py
index 277128f..108b60c 100644
--- a/src/cryptography/x509/name.py
+++ b/src/cryptography/x509/name.py
@@ -27,6 +27,9 @@
"Country name must be a 2 character country code"
)
+ if len(value) == 0:
+ raise ValueError("Value cannot be an empty string")
+
self._oid = oid
self._value = value
diff --git a/tests/test_x509.py b/tests/test_x509.py
index 8410881..7a99ff3 100644
--- a/tests/test_x509.py
+++ b/tests/test_x509.py
@@ -3624,6 +3624,10 @@
u'\U0001F37A\U0001F37A'
)
+ def test_init_empty_value(self):
+ with pytest.raises(ValueError):
+ x509.NameAttribute(NameOID.ORGANIZATION_NAME, u'')
+
def test_eq(self):
assert x509.NameAttribute(
x509.ObjectIdentifier('2.999.1'), u'value'