4 space indents; cuddle opening curlies
diff --git a/src/crypto/revoked.c b/src/crypto/revoked.c
index 1cff906..3042c4d 100644
--- a/src/crypto/revoked.c
+++ b/src/crypto/revoked.c
@@ -10,15 +10,15 @@
/* which differs from crl_reasons of crypto/x509v3/v3_enum.c that matches */
/* OCSP_crl_reason_str. We use the latter, just like the command line program. */
static const char *crl_reasons[] = {
- "unspecified",
- "keyCompromise",
- "CACompromise",
- "affiliationChanged",
- "superseded",
- "cessationOfOperation",
- "certificateHold",
- NULL,
- "removeFromCRL",
+ "unspecified",
+ "keyCompromise",
+ "CACompromise",
+ "affiliationChanged",
+ "superseded",
+ "cessationOfOperation",
+ "certificateHold",
+ NULL,
+ "removeFromCRL",
};
#define NUM_REASONS (sizeof(crl_reasons) / sizeof(char *))
@@ -29,16 +29,13 @@
@return: A list of reason strings.\n\
";
static PyObject *
-crypto_Revoked_all_reasons(crypto_RevokedObj *self, PyObject *args)
-{
+crypto_Revoked_all_reasons(crypto_RevokedObj *self, PyObject *args) {
PyObject *list, *str;
int j;
list = PyList_New(0);
- for (j = 0; j < NUM_REASONS; j++)
- {
- if( crl_reasons[j] )
- {
+ for (j = 0; j < NUM_REASONS; j++) {
+ if(crl_reasons[j]) {
str = PyString_FromString(crl_reasons[j]);
PyList_Append(list, str);
Py_DECREF(str);
@@ -48,8 +45,7 @@
}
static PyObject *
-X509_EXTENSION_value_to_PyString(X509_EXTENSION *ex)
-{
+X509_EXTENSION_value_to_PyString(X509_EXTENSION *ex) {
BIO *bio = NULL;
PyObject *str = NULL;
int str_len;
@@ -57,13 +53,16 @@
/* Create a openssl BIO buffer */
bio = BIO_new(BIO_s_mem());
- if (bio == NULL)
+ if (bio == NULL) {
goto err;
+ }
/* These are not the droids you are looking for. */
- if(!X509V3_EXT_print(bio, ex, 0, 0))
- if(M_ASN1_OCTET_STRING_print(bio, ex->value) == 0)
+ if (!X509V3_EXT_print(bio, ex, 0, 0)) {
+ if (M_ASN1_OCTET_STRING_print(bio, ex->value) == 0) {
goto err;
+ }
+ }
/* Convert to a Python string. */
str_len = BIO_get_mem_data(bio, &tmp_str);
@@ -74,24 +73,23 @@
return str;
err:
- if(bio) {
+ if (bio) {
BIO_free(bio);
}
- if(str) {
+ if (str) {
Py_DECREF(str);
}
return NULL;
}
static void
-delete_reason(STACK_OF(X509_EXTENSION) *sk)
-{
+delete_reason(STACK_OF(X509_EXTENSION) *sk) {
X509_EXTENSION * ext;
int j;
- for(j = 0; j < sk_X509_EXTENSION_num(sk); j++) {
+ for (j = 0; j < sk_X509_EXTENSION_num(sk); j++) {
ext = sk_X509_EXTENSION_value(sk, j);
- if ( OBJ_obj2nid(ext->object) == NID_crl_reason) {
+ if (OBJ_obj2nid(ext->object) == NID_crl_reason) {
X509_EXTENSION_free(ext);
(void) sk_X509_EXTENSION_delete(sk, j);
break;
@@ -100,24 +98,22 @@
}
static int
-reason_str_to_code(const char * reason_str)
-{
+reason_str_to_code(const char * reason_str) {
int reason_code = -1, j;
char *spaceless_reason, * sp;
/* Remove spaces so that the responses of
* get_reason() work in set_reason() */
- if((spaceless_reason = strdup(reason_str)) == NULL)
+ if ((spaceless_reason = strdup(reason_str)) == NULL) {
return -1;
- while((sp = strchr(spaceless_reason, ' ') ))
- {
+ }
+
+ while ((sp = strchr(spaceless_reason, ' '))) {
memmove(sp, sp+1, strlen(sp));
}
- for (j = 0; j < NUM_REASONS; j++)
- {
- if(crl_reasons[j] && !strcasecmp(spaceless_reason, crl_reasons[j]))
- {
+ for (j = 0; j < NUM_REASONS; j++) {
+ if(crl_reasons[j] && !strcasecmp(spaceless_reason, crl_reasons[j])) {
reason_code = j;
break;
}
@@ -134,36 +130,36 @@
@return: None\n\
";
static PyObject *
-crypto_Revoked_set_reason(crypto_RevokedObj *self, PyObject *args, PyObject *keywds)
-{
+crypto_Revoked_set_reason(crypto_RevokedObj *self, PyObject *args, PyObject *keywds) {
static char *kwlist[] = {"reason", NULL};
const char *reason_str = NULL;
int reason_code;
ASN1_ENUMERATED *rtmp = NULL;
if (!PyArg_ParseTupleAndKeywords(args, keywds, "z:set_reason",
- kwlist, &reason_str))
+ kwlist, &reason_str)) {
return NULL;
+ }
- if(reason_str == NULL)
- {
+ if(reason_str == NULL) {
delete_reason(self->revoked->extensions);
goto done;
}
reason_code = reason_str_to_code(reason_str);
- if(reason_code == -1)
- {
+ if (reason_code == -1) {
PyErr_SetString(PyExc_ValueError, "bad reason string");
return NULL;
}
rtmp = ASN1_ENUMERATED_new();
- if (!rtmp || !ASN1_ENUMERATED_set(rtmp, reason_code))
+ if (!rtmp || !ASN1_ENUMERATED_set(rtmp, reason_code)) {
goto err;
+ }
delete_reason(self->revoked->extensions);
- if (!X509_REVOKED_add1_ext_i2d(self->revoked, NID_crl_reason, rtmp, 0, 0))
+ if (!X509_REVOKED_add1_ext_i2d(self->revoked, NID_crl_reason, rtmp, 0, 0)) {
goto err;
+ }
done:
Py_INCREF(Py_None);
@@ -181,19 +177,19 @@
@return: The reason as a string\n\
";
static PyObject *
-crypto_Revoked_get_reason(crypto_RevokedObj *self, PyObject *args)
-{
+crypto_Revoked_get_reason(crypto_RevokedObj *self, PyObject *args) {
X509_EXTENSION * ext;
int j;
STACK_OF(X509_EXTENSION) *sk = NULL;
- if (!PyArg_ParseTuple(args, ":get_reason"))
+ if (!PyArg_ParseTuple(args, ":get_reason")) {
return NULL;
+ }
sk = self->revoked->extensions;
- for(j = 0; j < sk_X509_EXTENSION_num(sk); j++) {
+ for (j = 0; j < sk_X509_EXTENSION_num(sk); j++) {
ext = sk_X509_EXTENSION_value(sk, j);
- if ( OBJ_obj2nid(ext->object) == NID_crl_reason) {
+ if (OBJ_obj2nid(ext->object) == NID_crl_reason) {
return X509_EXTENSION_value_to_PyString(ext);
}
}
@@ -214,11 +210,10 @@
";
static PyObject*
-crypto_Revoked_get_rev_date(crypto_RevokedObj *self, PyObject *args)
-{
- /* returns a borrowed reference. */
- return _get_asn1_time(
- ":get_rev_date", self->revoked->revocationDate, args);
+crypto_Revoked_get_rev_date(crypto_RevokedObj *self, PyObject *args) {
+ /* returns a borrowed reference. */
+ return _get_asn1_time(
+ ":get_rev_date", self->revoked->revocationDate, args);
}
static char crypto_Revoked_set_rev_date_doc[] = "\n\
@@ -234,17 +229,15 @@
";
static PyObject*
-crypto_Revoked_set_rev_date(crypto_RevokedObj *self, PyObject *args)
-{
- return _set_asn1_time(
- "s:set_rev_date", self->revoked->revocationDate, args);
+crypto_Revoked_set_rev_date(crypto_RevokedObj *self, PyObject *args) {
+ return _set_asn1_time(
+ "s:set_rev_date", self->revoked->revocationDate, args);
}
/* The integer is converted to an upper-case hex string
* without a '0x' prefix. */
static PyObject *
-ASN1_INTEGER_to_PyString(ASN1_INTEGER *asn1_int)
-{
+ASN1_INTEGER_to_PyString(ASN1_INTEGER *asn1_int) {
BIO *bio = NULL;
PyObject *str = NULL;
int str_len;
@@ -252,12 +245,14 @@
/* Create a openssl BIO buffer */
bio = BIO_new(BIO_s_mem());
- if (bio == NULL)
+ if (bio == NULL) {
goto err;
+ }
/* Write the integer to the BIO as a hex string. */
- if(i2a_ASN1_INTEGER(bio, asn1_int) < 0)
+ if (i2a_ASN1_INTEGER(bio, asn1_int) < 0) {
goto err;
+ }
/* Convert to a Python string. */
str_len = BIO_get_mem_data(bio, &tmp_str);
@@ -268,10 +263,10 @@
return str;
err:
- if(bio) {
+ if (bio) {
BIO_free(bio);
}
- if(str) {
+ if (str) {
Py_DECREF(str);
}
return NULL;
@@ -284,12 +279,12 @@
@return: The serial number as a string\n\
";
static PyObject *
-crypto_Revoked_get_serial(crypto_RevokedObj *self, PyObject *args)
-{
- if (!PyArg_ParseTuple(args, ":get_serial"))
+crypto_Revoked_get_serial(crypto_RevokedObj *self, PyObject *args) {
+ if (!PyArg_ParseTuple(args, ":get_serial")) {
return NULL;
+ }
- if(self->revoked->serialNumber == NULL) {
+ if (self->revoked->serialNumber == NULL) {
/* never happens */
Py_INCREF(Py_None);
return Py_None;
@@ -306,18 +301,18 @@
@return: None\n\
";
static PyObject *
-crypto_Revoked_set_serial(crypto_RevokedObj *self, PyObject *args, PyObject *keywds)
-{
+crypto_Revoked_set_serial(crypto_RevokedObj *self, PyObject *args, PyObject *keywds) {
static char *kwlist[] = {"hex_str", NULL};
const char *hex_str = NULL;
BIGNUM *serial = NULL;
ASN1_INTEGER *tmpser = NULL;
if (!PyArg_ParseTupleAndKeywords(args, keywds, "s:set_serial",
- kwlist, &hex_str))
+ kwlist, &hex_str)) {
return NULL;
+ }
- if( ! BN_hex2bn(&serial, hex_str) ) {
+ if (!BN_hex2bn(&serial, hex_str) ) {
PyErr_SetString(PyExc_ValueError, "bad hex string");
return NULL;
}
@@ -334,13 +329,13 @@
crypto_RevokedObj *
-crypto_Revoked_New(X509_REVOKED *revoked)
-{
+crypto_Revoked_New(X509_REVOKED *revoked) {
crypto_RevokedObj *self;
self = PyObject_New(crypto_RevokedObj, &crypto_Revoked_Type);
- if (self==NULL)
- return NULL;
+ if (self == NULL) {
+ return NULL;
+ }
self->revoked = revoked;
return self;
}
@@ -354,8 +349,7 @@
{ #name, (PyCFunction)crypto_Revoked_##name, METH_VARARGS, crypto_Revoked_##name##_doc }
#define ADD_KW_METHOD(name) \
{ #name, (PyCFunction)crypto_Revoked_##name, METH_VARARGS | METH_KEYWORDS, crypto_Revoked_##name##_doc }
-static PyMethodDef crypto_Revoked_methods[] =
-{
+static PyMethodDef crypto_Revoked_methods[] = {
ADD_METHOD(all_reasons),
ADD_METHOD(get_reason),
ADD_KW_METHOD(set_reason),
@@ -369,14 +363,12 @@
static PyObject *
-crypto_Revoked_getattr(crypto_RevokedObj *self, char *name)
-{
+crypto_Revoked_getattr(crypto_RevokedObj *self, char *name) {
return Py_FindMethod(crypto_Revoked_methods, (PyObject *)self, name);
}
static void
-crypto_Revoked_dealloc(crypto_RevokedObj *self)
-{
+crypto_Revoked_dealloc(crypto_RevokedObj *self) {
X509_REVOKED_free(self->revoked);
self->revoked = NULL;
@@ -392,11 +384,11 @@
";
static PyObject* crypto_Revoked_new(PyTypeObject *subtype, PyObject *args, PyObject *kwargs) {
- if (!PyArg_ParseTuple(args, ":Revoked")) {
- return NULL;
- }
+ if (!PyArg_ParseTuple(args, ":Revoked")) {
+ return NULL;
+ }
- return (PyObject *)crypto_Revoked_New(X509_REVOKED_new());
+ return (PyObject *)crypto_Revoked_New(X509_REVOKED_new());
}
PyTypeObject crypto_Revoked_Type = {
@@ -442,12 +434,12 @@
};
int init_crypto_revoked(PyObject *module) {
- if(PyType_Ready(&crypto_Revoked_Type) < 0) {
- return 0;
- }
+ if(PyType_Ready(&crypto_Revoked_Type) < 0) {
+ return 0;
+ }
- if (PyModule_AddObject(module, "Revoked", (PyObject *)&crypto_Revoked_Type) != 0) {
- return 0;
- }
- return 1;
+ if (PyModule_AddObject(module, "Revoked", (PyObject *)&crypto_Revoked_Type) != 0) {
+ return 0;
+ }
+ return 1;
}