Handle unset notBefore and notAfter values
diff --git a/doc/pyOpenSSL.tex b/doc/pyOpenSSL.tex
index ec8831d..5e4d531 100644
--- a/doc/pyOpenSSL.tex
+++ b/doc/pyOpenSSL.tex
@@ -297,6 +297,7 @@
YYYYMMDDhhmmss+hhmm
YYYYMMDDhhmmss-hhmm
\end{verbatim}
+If no value exists for this field, \code{None} is returned.
\end{methoddesc}
\begin{methoddesc}[X509]{get_notAfter}{}
@@ -307,6 +308,7 @@
YYYYMMDDhhmmss+hhmm
YYYYMMDDhhmmss-hhmm
\end{verbatim}
+If no value exists for this field, \code{None} is returned.
\end{methoddesc}
\begin{methoddesc}[X509]{set_notBefore}{when}
diff --git a/src/crypto/x509.c b/src/crypto/x509.c
index 68f34b7..ff1f3de 100644
--- a/src/crypto/x509.c
+++ b/src/crypto/x509.c
@@ -432,7 +432,10 @@
* There must be a way to do this without touching timestamp->data
* directly. -exarkun
*/
- if (timestamp->type == V_ASN1_GENERALIZEDTIME) {
+ if (timestamp->length == 0) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ } else if (timestamp->type == V_ASN1_GENERALIZEDTIME) {
return PyString_FromString(timestamp->data);
} else {
ASN1_TIME_to_generalizedtime(timestamp, >_timestamp);
diff --git a/test/test_crypto.py b/test/test_crypto.py
index 7bdc1c9..5935cc5 100644
--- a/test/test_crypto.py
+++ b/test/test_crypto.py
@@ -343,6 +343,9 @@
set = getattr(certificate, 'set_not' + which)
get = getattr(certificate, 'get_not' + which)
+ # Starts with no value.
+ self.assertEqual(get(), None)
+
# GMT (Or is it UTC?) -exarkun
when = "20040203040506Z"
set(when)