'Set the reason of a Revoked object.
If :py:data:`reason` is :py:data:`None`, delete the reason instead.
:param reason: The reason string.
:type reason: :py:class:`str` or :py:class:`NoneType`
:return: None'

def set_reason(self, reason):

    if (reason is None):
        self._delete_reason()
    elif (not isinstance(reason, bytes)):
        raise TypeError('reason    must    be    None    or    a    byte    string')
    else:
        reason = reason.lower().replace('    ', '')
        reason_code = [r.lower() for r in self._crl_reasons].index(reason)
        new_reason_ext = _lib.ASN1_ENUMERATED_new()
        if (new_reason_ext == _ffi.NULL):
            _raise_current_error()
        new_reason_ext = _ffi.gc(new_reason_ext, _lib.ASN1_ENUMERATED_free)
        set_result = _lib.ASN1_ENUMERATED_set(new_reason_ext, reason_code)
        if (set_result == _ffi.NULL):
            _raise_current_error()
        self._delete_reason()
        add_result = _lib.X509_REVOKED_add1_ext_i2d(self._revoked, _lib.NID_crl_reason, new_reason_ext, 0, 0)
        if (not add_result):
            _raise_current_error()
