X509.sign handles ungenerated keys properly now
diff --git a/OpenSSL/crypto.py b/OpenSSL/crypto.py
index e42dca9..b0e5897 100644
--- a/OpenSSL/crypto.py
+++ b/OpenSSL/crypto.py
@@ -47,9 +47,11 @@
class PKey(object):
_only_public = False
+ _initialized = True
def __init__(self):
self._pkey = _api.EVP_PKEY_new()
+ self._initialized = False
def generate_key(self, type, bits):
@@ -92,6 +94,7 @@
else:
raise Error("No such key type")
+ self._initialized = True
def check(self):
@@ -188,6 +191,9 @@
if pkey._only_public:
raise ValueError("Key only has public part")
+ if not pkey._initialized:
+ raise ValueError("Key is uninitialized")
+
evp_md = _api.EVP_get_digestbyname(digest)
if evp_md == _api.NULL:
raise ValueError("No such digest method")