'Generate a key of a given type, with a given number of a bits
:param type: The key type (TYPE_RSA or TYPE_DSA)
:param bits: The number of bits
:return: None'

def generate_key(self, type, bits):

    if (not isinstance(type, int)):
        raise TypeError('type    must    be    an    integer')
    if (not isinstance(bits, int)):
        raise TypeError('bits    must    be    an    integer')
    exponent = _lib.BN_new()
    exponent = _ffi.gc(exponent, _lib.BN_free)
    _lib.BN_set_word(exponent, _lib.RSA_F4)
    if (type == TYPE_RSA):
        if (bits <= 0):
            raise ValueError('Invalid    number    of    bits')
        rsa = _lib.RSA_new()
        result = _lib.RSA_generate_key_ex(rsa, bits, exponent, _ffi.NULL)
        if (result == 0):
            _raise_current_error()
        result = _lib.EVP_PKEY_assign_RSA(self._pkey, rsa)
        if (not result):
            _raise_current_error()
    elif (type == TYPE_DSA):
        dsa = _lib.DSA_generate_parameters(bits, _ffi.NULL, 0, _ffi.NULL, _ffi.NULL, _ffi.NULL, _ffi.NULL)
        if (dsa == _ffi.NULL):
            _raise_current_error()
        if (not _lib.DSA_generate_key(dsa)):
            _raise_current_error()
        if (not _lib.EVP_PKEY_assign_DSA(self._pkey, dsa)):
            _raise_current_error()
    else:
        raise Error('No    such    key    type')
    self._initialized = True
