Reduce 80 column limit violations in the ASN1 code.
{
struct CMSAttribute const *cattr = sptr;
json_t *root;
- json_t *attrValues;
+ json_t *array;
+ json_t *tmp;
int a;
if (!cattr)
if (root == NULL)
return NULL;
- if (json_object_set_new(root, "attrType", OBJECT_IDENTIFIER_encode_json(NULL, &cattr->attrType)))
+ tmp = OBJECT_IDENTIFIER_encode_json(NULL, &cattr->attrType);
+ if (json_object_set_new(root, "attrType", tmp))
goto fail;
- if (json_object_set_new(root, "attrValues", attrValues = json_array()))
+ if (json_object_set_new(root, "attrValues", array = json_array()))
goto fail;
if (OBJECT_IDENTIFIER_is_ContentType(&cattr->attrType))
else
td = &asn_DEF_ANY;
- for (a = 0; a < cattr->attrValues.list.count; a++)
- if (json_array_append_new(attrValues, attr2json(td, cattr->attrValues.list.array[a])))
+ for (a = 0; a < cattr->attrValues.list.count; a++) {
+ tmp = attr2json(td, cattr->attrValues.list.array[a]);
+ if (json_array_append_new(array, tmp))
goto fail;
+ }
return root;
revokedCerts2json(X509_CRL *crl)
{
STACK_OF(X509_REVOKED) *revokeds = X509_CRL_get_REVOKED(crl);
- json_t *root, *child;
+ json_t *root;
+ json_t *parent;
+ json_t *child;
X509_REVOKED *rv;
int r;
for (r = 0; r < sk_X509_REVOKED_num(revokeds); r++) {
rv = sk_X509_REVOKED_value(revokeds, r);
- if (json_array_append_new(root, child = json_object()) < 0)
+
+ if (json_array_append_new(root, parent = json_object()))
goto fail;
- if (json_object_set_new(child, "userCertificate", asn1int2json(X509_REVOKED_get0_serialNumber(rv))) < 0)
+
+ child = asn1int2json(X509_REVOKED_get0_serialNumber(rv));
+ if (json_object_set_new(parent, "userCertificate", child))
goto fail;
- if (json_object_set_new(child, "revocationDate", asn1time2json(X509_REVOKED_get0_revocationDate(rv))) < 0)
+ child = asn1time2json(X509_REVOKED_get0_revocationDate(rv));
+ if (json_object_set_new(parent, "revocationDate", child))
goto fail;
- if (json_object_set_new(child, "crlEntryExtensions", exts2json(X509_REVOKED_get0_extensions(rv))) < 0)
+ child = exts2json(X509_REVOKED_get0_extensions(rv));
+ if (json_object_set_new(parent, "crlEntryExtensions", child))
goto fail;
}
static json_t *
tbsCertList2json(X509_CRL *crl)
{
- json_t *root;
+ json_t *parent;
+ json_t *child;
- root = json_object();
- if (root == NULL)
+ parent = json_object();
+ if (parent == NULL)
return NULL;
- if (json_object_set_new(root, "version", json_integer(X509_CRL_get_version(crl))) < 0)
+ child = json_integer(X509_CRL_get_version(crl));
+ if (json_object_set_new(parent, "version", child))
goto fail;
- if (json_object_set_new(root, "signature", json_string(OBJ_nid2sn(X509_CRL_get_signature_nid(crl)))) < 0)
+ child = json_string(OBJ_nid2sn(X509_CRL_get_signature_nid(crl)));
+ if (json_object_set_new(parent, "signature", child))
goto fail;
- if (json_object_set_new(root, "issuer", name2json(X509_CRL_get_issuer(crl))) < 0)
+ child = name2json(X509_CRL_get_issuer(crl));
+ if (json_object_set_new(parent, "issuer", child))
goto fail;
- if (json_object_set_new(root, "thisUpdate", asn1time2json(X509_CRL_get0_lastUpdate(crl))) < 0)
+ child = asn1time2json(X509_CRL_get0_lastUpdate(crl));
+ if (json_object_set_new(parent, "thisUpdate", child))
goto fail;
- if (json_object_set_new(root, "nextUpdate", asn1time2json(X509_CRL_get0_nextUpdate(crl))) < 0)
+ child = asn1time2json(X509_CRL_get0_nextUpdate(crl));
+ if (json_object_set_new(parent, "nextUpdate", child))
goto fail;
- if (json_object_set_new(root, "revokedCertificates", revokedCerts2json(crl)) < 0)
+ child = revokedCerts2json(crl);
+ if (json_object_set_new(parent, "revokedCertificates", child))
goto fail;
- if (json_object_set_new(root, "crlExtensions", exts2json(X509_CRL_get0_extensions(crl))) < 0)
+ child = exts2json(X509_CRL_get0_extensions(crl));
+ if (json_object_set_new(parent, "crlExtensions", child))
goto fail;
- return root;
+ return parent;
-fail: json_decref(root);
+fail: json_decref(parent);
return NULL;
}
static json_t *
crl2json(X509_CRL *crl)
{
- json_t *root;
+ json_t *parent;
+ json_t *child;
- root = json_object();
- if (root == NULL)
+ parent = json_object();
+ if (parent == NULL)
return NULL;
- if (json_object_set_new(root, "tbsCertList", tbsCertList2json(crl)) < 0)
+ child = tbsCertList2json(crl);
+ if (json_object_set_new(parent, "tbsCertList", child))
goto fail;
- if (json_object_set_new(root, "signatureAlgorithm", sigAlgorithm2json(crl)) < 0)
+ child = sigAlgorithm2json(crl);
+ if (json_object_set_new(parent, "signatureAlgorithm", child))
goto fail;
- if (json_object_set_new(root, "signatureValue", sigValue2json(crl)) < 0)
+ child = sigValue2json(crl);
+ if (json_object_set_new(parent, "signatureValue", child))
goto fail;
- return root;
+ return parent;
-fail: json_decref(root);
+fail: json_decref(parent);
return NULL;
}
CRL_bio2json(BIO *bio)
{
X509_CRL *crl;
- json_t *root;
+ json_t *json;
crl = d2i_X509_CRL_bio(bio, NULL);
if (crl == NULL)
return NULL;
- root = crl2json(crl);
+ json = crl2json(crl);
X509_CRL_free(crl);
- return root;
+ return json;
}
static json_t *
validity2json(X509 *x)
{
- json_t *root;
+ json_t *parent;
+ json_t *child;
- root = json_object();
- if (root == NULL)
+ parent = json_object();
+ if (parent == NULL)
return NULL;
- if (json_object_set_new(root, "notBefore", asn1time2json(X509_get0_notBefore(x))) < 0)
+ child = asn1time2json(X509_get0_notBefore(x));
+ if (json_object_set_new(parent, "notBefore", child))
goto fail;
- if (json_object_set_new(root, "notAfter", asn1time2json(X509_get0_notAfter(x))) < 0)
+ child = asn1time2json(X509_get0_notAfter(x));
+ if (json_object_set_new(parent, "notAfter", child))
goto fail;
- return root;
+ return parent;
-fail: json_decref(root);
+fail: json_decref(parent);
return NULL;
}
static json_t *
tbsCert2json(X509 *x)
{
- json_t *tbsCert;
+ json_t *parent;
+ json_t *child;
- tbsCert = json_object();
- if (tbsCert == NULL)
+ parent = json_object();
+ if (parent == NULL)
return NULL;
- if (json_object_set_new(tbsCert, "version", json_integer(X509_get_version(x))) < 0)
+ child = json_integer(X509_get_version(x));
+ if (json_object_set_new(parent, "version", child))
goto fail;
- if (json_object_set_new(tbsCert, "serialNumber", asn1int2json(X509_get0_serialNumber(x))) < 0)
+ child = asn1int2json(X509_get0_serialNumber(x));
+ if (json_object_set_new(parent, "serialNumber", child))
goto fail;
- if (json_object_set_new(tbsCert, "signature", json_string(OBJ_nid2sn(X509_get_signature_nid(x)))) < 0)
+ child = json_string(OBJ_nid2sn(X509_get_signature_nid(x)));
+ if (json_object_set_new(parent, "signature", child))
goto fail;
- if (json_object_set_new(tbsCert, "issuer", name2json(X509_get_issuer_name(x))) < 0)
+ child = name2json(X509_get_issuer_name(x));
+ if (json_object_set_new(parent, "issuer", child))
goto fail;
- if (json_object_set_new(tbsCert, "validity", validity2json(x)) < 0)
+ child = validity2json(x);
+ if (json_object_set_new(parent, "validity", child))
goto fail;
- if (json_object_set_new(tbsCert, "subject", name2json(X509_get_subject_name(x))) < 0)
+ child = name2json(X509_get_subject_name(x));
+ if (json_object_set_new(parent, "subject", child))
goto fail;
- if (json_object_set_new(tbsCert, "subjectPublicKeyInfo", pk2json(x)) < 0)
+ child = pk2json(x);
+ if (json_object_set_new(parent, "subjectPublicKeyInfo", child))
goto fail;
- if (json_object_set_new(tbsCert, "issuerUniqueID", iuid2json(x)) < 0)
+ child = iuid2json(x);
+ if (json_object_set_new(parent, "issuerUniqueID", child))
goto fail;
- if (json_object_set_new(tbsCert, "subjectUniqueID", suid2json(x)) < 0)
+ child = suid2json(x);
+ if (json_object_set_new(parent, "subjectUniqueID", child))
goto fail;
- if (json_object_set_new(tbsCert, "extensions", exts2json(X509_get0_extensions(x))) < 0)
+ child = exts2json(X509_get0_extensions(x));
+ if (json_object_set_new(parent, "extensions", child))
goto fail;
- return tbsCert;
+ return parent;
-fail: json_decref(tbsCert);
+fail: json_decref(parent);
return NULL;
}
static json_t *
x509_to_json(X509 *x)
{
- json_t *root;
+ json_t *parent;
+ json_t *child;
- root = json_object();
- if (root == NULL)
+ parent = json_object();
+ if (parent == NULL)
return NULL;
- if (json_object_set_new(root, "tbsCertificate", tbsCert2json(x)) < 0)
+ child = tbsCert2json(x);
+ if (json_object_set_new(parent, "tbsCertificate", child))
goto fail;
- if (json_object_set_new(root, "signatureAlgorithm", sigAlgorithm2json(x)) < 0)
+ child = sigAlgorithm2json(x);
+ if (json_object_set_new(parent, "signatureAlgorithm", child))
goto fail;
- if (json_object_set_new(root, "signatureValue", sigValue2json(x)) < 0)
+ child = sigValue2json(x);
+ if (json_object_set_new(parent, "signatureValue", child))
goto fail;
- return root;
+ return parent;
-fail: json_decref(root);
+fail: json_decref(parent);
return NULL;
}
{
const unsigned char *tmp;
X509 *cert;
- json_t *root;
+ json_t *json;
/*
* "If the call is successful *in is incremented to the byte following
if (cert == NULL)
return NULL;
- root = x509_to_json(cert);
+ json = x509_to_json(cert);
X509_free(cert);
- return root;
+ return json;
}
json_t *
Certificate_bio2json(BIO *bio)
{
X509 *cert;
- json_t *root;
+ json_t *json;
cert = d2i_X509_bio(bio, NULL);
if (cert == NULL)
return NULL;
- root = x509_to_json(cert);
+ json = x509_to_json(cert);
X509_free(cert);
- return root;
+ return json;
}
CertificateSet_encode_json(const struct asn_TYPE_descriptor_s *td,
const void *sptr)
{
- json_t *result;
+ json_t *parent;
+ json_t *child;
const asn_anonymous_set_ *list;
int i;
if (!sptr)
return json_null();
- result = json_array();
- if (result == NULL)
+ parent = json_array();
+ if (parent == NULL)
return NULL;
list = _A_CSET_FROM_VOID(sptr);
for (i = 0; i < list->count; i++) {
- json_t *node = Certificate_any2json(list->array[i]);
- if (node == NULL)
- goto fail;
- if (json_array_append_new(result, node) < 0)
+ child = Certificate_any2json(list->array[i]);
+ if (json_array_append_new(parent, child))
goto fail;
}
- return result;
+ return parent;
-fail: json_decref(result);
+fail: json_decref(parent);
return NULL;
}
{
struct ContentInfo const *ci = sptr;
json_t *parent;
- json_t *content_type;
- json_t *content;
+ json_t *child;
if (!ci)
return json_null();
return NULL;
td = &asn_DEF_ContentType;
- content_type = td->op->json_encoder(td, &ci->contentType);
- if (json_object_set_new(parent, "contentType", content_type))
+ child = td->op->json_encoder(td, &ci->contentType);
+ if (json_object_set_new(parent, "contentType", child))
goto fail;
if (OBJECT_IDENTIFIER_is_SignedData(&ci->contentType)) {
td = &asn_DEF_SignedData;
- content = content2json(td, &ci->content);
-
+ child = content2json(td, &ci->content);
} else {
-// printf("===========================\n");
-// for (ret = 0; ret < ci->contentType.size; ret++)
-// printf("%u ", ci->contentType.buf[ret]);
-// printf("\n==========================\n");
-
td = &asn_DEF_ANY;
- content = td->op->json_encoder(td, &ci->content);
+ child = td->op->json_encoder(td, &ci->content);
}
-
- if (content == NULL)
- goto fail;
- if (json_object_set_new(parent, "content", content))
+ if (json_object_set_new(parent, "content", child))
goto fail;
return parent;
{
struct EncapsulatedContentInfo const *eci = sptr;
json_t *parent;
- json_t *content_type;
- json_t *content;
+ json_t *child;
if (!eci)
return json_null();
return NULL;
td = &asn_DEF_ContentType;
- content_type = td->op->json_encoder(td, &eci->eContentType);
- if (content_type == NULL)
- goto fail;
- if (json_object_set_new(parent, "eContentType", content_type))
+ child = td->op->json_encoder(td, &eci->eContentType);
+ if (json_object_set_new(parent, "eContentType", child))
goto fail;
if (OBJECT_IDENTIFIER_is_mft(&eci->eContentType)) {
td = &asn_DEF_Manifest;
- content = econtent2json(td, eci->eContent);
-
+ child = econtent2json(td, eci->eContent);
} else if (OBJECT_IDENTIFIER_is_roa(&eci->eContentType)) {
td = &asn_DEF_RouteOriginAttestation;
- content = econtent2json(td, eci->eContent);
-
+ child = econtent2json(td, eci->eContent);
} else if (OBJECT_IDENTIFIER_is_gbr(&eci->eContentType)) {
td = &asn_DEF_OCTET_STRING;
- content = OCTET_STRING_encode_json_utf8(td, eci->eContent);
-
+ child = OCTET_STRING_encode_json_utf8(td, eci->eContent);
} else {
-// printf("===========================\n");
-// for (ret = 0; ret < eci->eContentType.size; ret++)
-// printf("%u ", eci->eContentType.buf[ret]);
-// printf("\n==========================\n");
-
td = &asn_DEF_OCTET_STRING;
- content = td->op->json_encoder(td, eci->eContent);
+ child = td->op->json_encoder(td, eci->eContent);
}
-
- if (content == NULL)
- goto fail;
- if (json_object_set_new(parent, "eContent", content))
+ if (json_object_set_new(parent, "eContent", child))
goto fail;
return parent;
root = json_object();
if (root == NULL)
return NULL;
- if (json_object_set_new(root, "prefix", json_string(prefix)) < 0)
+ if (json_object_set_new(root, "prefix", json_string(prefix)))
goto fail;
- if (json_object_set_new(root, "length", json_integer(length)) < 0)
+ if (json_object_set_new(root, "length", json_integer(length)))
goto fail;
return root;
AddrBlock2json(struct ROAIPAddressFamily const *riaf, char const *ipname,
json_t *(*pref2json)(struct ROAIPAddress *))
{
- json_t *root;
- json_t *addrs;
+ json_t *root, *addrs;
+ json_t *pfx, *maxlen;
+ struct ROAIPAddress *src;
int i;
root = json_object();
if (root == NULL)
return NULL;
- if (json_object_set_new(root, "addressFamily", json_string(ipname)) < 0)
+ if (json_object_set_new(root, "addressFamily", json_string(ipname)))
goto fail;
- if (json_object_set_new(root, "addresses", addrs = json_array()) < 0)
+ if (json_object_set_new(root, "addresses", addrs = json_array()))
goto fail;
for (i = 0; i < riaf->addresses.list.count; i++) {
- struct ROAIPAddress *src = riaf->addresses.list.array[i];
- json_t *prefix, *maxlen;
+ src = riaf->addresses.list.array[i];
- prefix = pref2json(src);
- if (json_array_append_new(addrs, prefix))
+ pfx = pref2json(src);
+ if (json_array_append_new(addrs, pfx))
goto fail;
- maxlen = asn_DEF_INTEGER.op->json_encoder(&asn_DEF_INTEGER, src->maxLength);
- if (json_object_set_new(prefix, "maxLength", maxlen))
+ maxlen = asn_DEF_INTEGER.op->json_encoder(&asn_DEF_INTEGER,
+ src->maxLength);
+ if (json_object_set_new(pfx, "maxLength", maxlen))
goto fail;
}
json_t *
SEQUENCE_encode_json(const struct asn_TYPE_descriptor_s *td, const void *sptr)
{
- json_t *parent, *child;
+ json_t *parent;
+ json_t *child;
size_t c;
if (!sptr)
}
child = elm->type->op->json_encoder(elm->type, memb_ptr);
- if (child == NULL)
- goto fail;
if (json_object_set_new(parent, elm->name, child))
goto fail;
}
json_t *
SET_OF_encode_json(const struct asn_TYPE_descriptor_s *td, const void *sptr)
{
- json_t *result;
+ json_t *parent;
+ json_t *child;
const asn_anonymous_set_ *list;
asn_TYPE_descriptor_t *type;
int i;
if (!sptr)
return json_null();
- result = json_array();
- if (result == NULL)
+ parent = json_array();
+ if (parent == NULL)
return NULL;
list = _A_CSET_FROM_VOID(sptr);
type = td->elements->type;
for (i = 0; i < list->count; i++) {
- json_t *node = type->op->json_encoder(type, list->array[i]);
- if (node == NULL)
- goto fail;
- if (json_array_append_new(result, node) < 0)
+ child = type->op->json_encoder(type, list->array[i]);
+ if (json_array_append_new(parent, child))
goto fail;
}
- return result;
+ return parent;
-fail: json_decref(result);
+fail: json_decref(parent);
return NULL;
}
HASH_ITER(hh, cache->ht, node, tmp) {
child = node2json(node);
- if (child == NULL)
- continue;
if (json_array_append_new(root, child)) {
pr_op_err("Cannot push %s json node into json root; unknown cause.",
uri_op_get_printable(node->url));
bc2json(void const *ext)
{
BASIC_CONSTRAINTS const *bc = ext;
- json_t *root;
+ json_t *parent;
+ json_t *child;
- root = json_object();
- if (root == NULL)
+ parent = json_object();
+ if (parent == NULL)
return NULL;
- if (json_object_set_new(root, "cA", json_boolean(bc->ca)) < 0)
+ child = json_boolean(bc->ca);
+ if (json_object_set_new(parent, "cA", child))
goto fail;
- if (json_object_set_new(root, "pathLenConstraint", asn1int2json(bc->pathlen)) < 0)
+ child = asn1int2json(bc->pathlen);
+ if (json_object_set_new(parent, "pathLenConstraint", child))
goto fail;
- return root;
+ return parent;
-fail: json_decref(root);
+fail: json_decref(parent);
return NULL;
}
aki2json(void const *ext)
{
AUTHORITY_KEYID const *aki = ext;
- json_t *root;
+ json_t *parent;
+ json_t *child;
- root = json_object();
- if (root == NULL)
+ parent = json_object();
+ if (parent == NULL)
return NULL;
- if (json_object_set_new(root, "keyIdentifier", asn1str2json(aki->keyid)) < 0)
+ child = asn1str2json(aki->keyid);
+ if (json_object_set_new(parent, "keyIdentifier", child))
goto fail;
- if (json_object_set_new(root, "authorityCertIssuer", unimplemented(aki->issuer)) < 0)
+ child = unimplemented(aki->issuer);
+ if (json_object_set_new(parent, "authorityCertIssuer", child))
goto fail;
- if (json_object_set_new(root, "authorityCertSerialNumber", asn1int2json(aki->serial)) < 0)
+ child = asn1int2json(aki->serial);
+ if (json_object_set_new(parent, "authorityCertSerialNumber", child))
goto fail;
- return root;
+ return parent;
-fail: json_decref(root);
+fail: json_decref(parent);
return NULL;
}
{
ASN1_BIT_STRING const *ku = ext;
unsigned char data[2];
- json_t *root;
+ json_t *parent;
+ json_t *child;
if (ku->length < 1 || 2 < ku->length)
return NULL;
memset(data, 0, sizeof(data));
memcpy(data, ku->data, ku->length);
- root = json_object();
- if (root == NULL)
+ parent = json_object();
+ if (parent == NULL)
return NULL;
- if (json_object_set_new(root, "digitalSignature", json_boolean(data[0] & 0x80u)) < 0)
+ child = json_boolean(data[0] & 0x80u);
+ if (json_object_set_new(parent, "digitalSignature", child))
goto fail;
- if (json_object_set_new(root, "contentCommitment", json_boolean(data[0] & 0x40u)) < 0)
+ child = json_boolean(data[0] & 0x40u);
+ if (json_object_set_new(parent, "contentCommitment", child))
goto fail;
- if (json_object_set_new(root, "keyEncipherment", json_boolean(data[0] & 0x20u)) < 0)
+ child = json_boolean(data[0] & 0x20u);
+ if (json_object_set_new(parent, "keyEncipherment", child))
goto fail;
- if (json_object_set_new(root, "dataEncipherment", json_boolean(data[0] & 0x10u)) < 0)
+ child = json_boolean(data[0] & 0x10u);
+ if (json_object_set_new(parent, "dataEncipherment", child))
goto fail;
- if (json_object_set_new(root, "keyAgreement", json_boolean(data[0] & 0x08u)) < 0)
+ child = json_boolean(data[0] & 0x08u);
+ if (json_object_set_new(parent, "keyAgreement", child))
goto fail;
- if (json_object_set_new(root, "keyCertSign", json_boolean(data[0] & 0x04u)) < 0)
+ child = json_boolean(data[0] & 0x04u);
+ if (json_object_set_new(parent, "keyCertSign", child))
goto fail;
- if (json_object_set_new(root, "cRLSign", json_boolean(data[0] & 0x02u)) < 0)
+ child = json_boolean(data[0] & 0x02u);
+ if (json_object_set_new(parent, "cRLSign", child))
goto fail;
- if (json_object_set_new(root, "encipherOnly", json_boolean(data[0] & 0x01u)) < 0)
+ child = json_boolean(data[0] & 0x01u);
+ if (json_object_set_new(parent, "encipherOnly", child))
goto fail;
- if (json_object_set_new(root, "decipherOnly", json_boolean(data[1] & 0x80u)) < 0)
+ child = json_boolean(data[1] & 0x80u);
+ if (json_object_set_new(parent, "decipherOnly", child))
goto fail;
- return root;
+ return parent;
-fail: json_decref(root);
+fail: json_decref(parent);
return NULL;
}
rdn2json(STACK_OF(X509_NAME_ENTRY) *rdn)
{
json_t *root;
+ json_t *parent;
json_t *child;
X509_NAME_ENTRY *name;
int n;
return NULL;
for (n = 0; n < sk_X509_NAME_ENTRY_num(rdn); n++) {
- if (json_array_append_new(root, child = json_object()))
+ name = sk_X509_NAME_ENTRY_value(rdn, n);
+
+ if (json_array_append_new(root, parent = json_object()))
goto fail;
- name = sk_X509_NAME_ENTRY_value(rdn, n);
- if (json_object_set_new(child, "type", oid2json(X509_NAME_ENTRY_get_object(name))))
+ child = oid2json(X509_NAME_ENTRY_get_object(name));
+ if (json_object_set_new(parent, "type", child))
goto fail;
- if (json_object_set_new(child, "value", asn1str2json(X509_NAME_ENTRY_get_data(name))))
+ child = asn1str2json(X509_NAME_ENTRY_get_data(name));
+ if (json_object_set_new(parent, "value", child))
goto fail;
}
cdp2json(void const *ext)
{
STACK_OF(DIST_POINT) const *crldp = ext;
- json_t *root, *child;
+ json_t *root;
+ json_t *parent;
+ json_t *child;
DIST_POINT *dp;
int d;
for (d = 0; d < sk_DIST_POINT_num(crldp); d++) {
dp = sk_DIST_POINT_value(crldp, d);
- if (json_array_append_new(root, child = json_object()) < 0)
+
+ if (json_array_append_new(root, parent = json_object()))
goto fail;
- if (json_object_set_new(child, "distributionPoint", dpname2json(dp->distpoint)) < 0)
+
+ child = dpname2json(dp->distpoint);
+ if (json_object_set_new(parent, "distributionPoint", child))
goto fail;
- if (json_object_set_new(child, "reasons", unimplemented(dp->reasons)) < 0)
+ child = unimplemented(dp->reasons);
+ if (json_object_set_new(parent, "reasons", child))
goto fail;
- if (json_object_set_new(child, "cRLIssuer", gns2json(dp->CRLissuer)) < 0)
+ child = gns2json(dp->CRLissuer);
+ if (json_object_set_new(parent, "cRLIssuer", child))
goto fail;
}
{
AUTHORITY_INFO_ACCESS const *ia = ext;
ACCESS_DESCRIPTION *ad;
- json_t *root, *child;
+ json_t *root;
+ json_t *parent;
+ json_t *child;
int i;
root = json_array();
for (i = 0; i < sk_ACCESS_DESCRIPTION_num(ia); i++) {
ad = sk_ACCESS_DESCRIPTION_value(ia, i);
- if (json_array_append_new(root, child = json_object()) < 0)
+
+ if (json_array_append_new(root, parent = json_object()))
goto fail;
- if (json_object_set_new(child, "accessMethod", oid2json(ad->method)) < 0)
+
+ child = oid2json(ad->method);
+ if (json_object_set_new(parent, "accessMethod", child))
goto fail;
- if (json_object_set_new(child, "accessLocation", gn2json(ad->location)) < 0)
+ child = gn2json(ad->location);
+ if (json_object_set_new(parent, "accessLocation", child))
goto fail;
}
static json_t *
pq2json(POLICYQUALINFO const *pqi)
{
- json_t *root;
+ json_t *parent;
+ json_t *child;
if (pqi == NULL)
return json_null();
- root = json_object();
- if (root == NULL)
+ parent = json_object();
+ if (parent == NULL)
return NULL;
- if (json_object_set_new(root, "policyQualifierId", oid2json(pqi->pqualid)) < 0)
+ child = oid2json(pqi->pqualid);
+ if (json_object_set_new(parent, "policyQualifierId", child))
goto fail;
- if (json_object_set_new(root, "qualifier", unimplemented(&pqi->d)) < 0)
+ child = unimplemented(&pqi->d);
+ if (json_object_set_new(parent, "qualifier", child))
goto fail;
return NULL;
-fail: json_decref(root);
+fail: json_decref(parent);
return NULL;
}
static json_t *
pqs2json(STACK_OF(POLICYQUALINFO) const *pqs)
{
- json_t *root;
+ json_t *parent;
+ json_t *child;
int i;
if (pqs == NULL)
return json_null();
- root = json_array();
- if (root == NULL)
+ parent = json_array();
+ if (parent == NULL)
return NULL;
- for (i = 0; i < sk_POLICYQUALINFO_num(pqs); i++)
- if (json_array_append_new(root, pq2json(sk_POLICYQUALINFO_value(pqs, i))) < 0)
+ for (i = 0; i < sk_POLICYQUALINFO_num(pqs); i++) {
+ child = pq2json(sk_POLICYQUALINFO_value(pqs, i));
+ if (json_array_append_new(parent, child))
goto fail;
+ }
- return root;
+ return parent;
-fail: json_decref(root);
+fail: json_decref(parent);
return NULL;
}
static json_t *
pi2json(POLICYINFO const *pi)
{
- json_t *root;
+ json_t *parent;
+ json_t *child;
if (pi == NULL)
return json_null();
- root = json_object();
- if (root == NULL)
+ parent = json_object();
+ if (parent == NULL)
return NULL;
- if (json_object_set_new(root, "policyIdentifier", oid2json(pi->policyid)) < 0)
+ child = oid2json(pi->policyid);
+ if (json_object_set_new(parent, "policyIdentifier", child))
goto fail;
- if (json_object_set_new(root, "policyQualifiers", pqs2json(pi->qualifiers)) < 0)
+ child = pqs2json(pi->qualifiers);
+ if (json_object_set_new(parent, "policyQualifiers", child))
goto fail;
- return root;
+ return parent;
-fail: json_decref(root);
+fail: json_decref(parent);
return NULL;
}
cp2json(void const *ext)
{
CERTIFICATEPOLICIES const *cp = ext;
- json_t *root;
+ json_t *parent;
+ json_t *child;
int i;
- root = json_array();
- if (root == NULL)
+ parent = json_array();
+ if (parent == NULL)
return NULL;
- for (i = 0; i < sk_POLICYINFO_num(cp); i++)
- if (json_array_append_new(root, pi2json(sk_POLICYINFO_value(cp, i))))
+ for (i = 0; i < sk_POLICYINFO_num(cp); i++) {
+ child = pi2json(sk_POLICYINFO_value(cp, i));
+ if (json_array_append_new(parent, child))
goto fail;
+ }
- return root;
+ return parent;
-fail: json_decref(root);
+fail: json_decref(parent);
return NULL;
}
static json_t *
iaor2json(IPAddressOrRange const *iaor, int af)
{
- json_t *root;
-
if (iaor == NULL)
return json_null();
return unimplemented(iaor->u.addressRange);
}
- json_decref(root);
return NULL;
}
static json_t *
-iac2json(IPAddressChoice const *iac, int af)
+iaors2json(IPAddressOrRanges *iaor, int af)
{
- json_t *root;
- IPAddressOrRanges *iaor;
+ json_t *parent;
+ json_t *child;
int i;
+ if (iaor == NULL)
+ return json_null();
+
+ parent = json_array();
+ if (parent == NULL)
+ return NULL;
+
+ for (i = 0; i < sk_IPAddressOrRange_num(iaor); i++) {
+ child = iaor2json(sk_IPAddressOrRange_value(iaor, i), af);
+ if (json_array_append_new(parent, child))
+ goto fail;
+ }
+
+ return parent;
+
+fail: json_decref(parent);
+ return NULL;
+}
+
+static json_t *
+iac2json(IPAddressChoice const *iac, int af)
+{
if (iac == NULL)
return json_null();
switch (iac->type) {
case IPAddressChoice_inherit:
return json_string("inherit");
-
case IPAddressChoice_addressesOrRanges:
- iaor = iac->u.addressesOrRanges;
- if (iaor == NULL)
- return json_null();
- root = json_array();
- if (root == NULL)
- goto fail;
- for (i = 0; i < sk_IPAddressOrRange_num(iaor); i++)
- if (json_array_append_new(root, iaor2json(sk_IPAddressOrRange_value(iaor, i), af)))
- goto fail;
- return root;
+ return iaors2json(iac->u.addressesOrRanges, af);
}
return NULL;
-
-fail: json_decref(root);
- return NULL;
}
static json_t *
iaf2json(IPAddressFamily const *iaf)
{
- json_t *root;
+ json_t *parent;
+ json_t *child;
ASN1_OCTET_STRING *af;
char const *family;
int afid;
if (iaf == NULL)
return json_null();
- root = json_object();
- if (root == NULL)
+ parent = json_object();
+ if (parent == NULL)
return NULL;
af = iaf->addressFamily;
goto fail;
}
- if (json_object_set_new(root, "addressFamily", json_string(family)) < 0)
+ child = json_string(family);
+ if (json_object_set_new(parent, "addressFamily", child))
goto fail;
- if (json_object_set_new(root, "ipAddressChoice", iac2json(iaf->ipAddressChoice, afid)) < 0)
+ child = iac2json(iaf->ipAddressChoice, afid);
+ if (json_object_set_new(parent, "ipAddressChoice", child))
goto fail;
- return root;
+ return parent;
-fail: json_decref(root);
+fail: json_decref(parent);
return NULL;
}
ir2json(void const *ext)
{
STACK_OF(IPAddressFamily) const *iafs = ext;
- json_t *root;
+ json_t *parent;
+ json_t *child;
int i;
- root = json_array();
- if (root == NULL)
+ parent = json_array();
+ if (parent == NULL)
return NULL;
- for (i = 0; i < sk_IPAddressFamily_num(iafs); i++)
- if (json_array_append_new(root, iaf2json(sk_IPAddressFamily_value(iafs, i))))
+ for (i = 0; i < sk_IPAddressFamily_num(iafs); i++) {
+ child = iaf2json(sk_IPAddressFamily_value(iafs, i));
+ if (json_array_append_new(parent, child))
goto fail;
+ }
- return root;
+ return parent;
-fail: json_decref(root);
+fail: json_decref(parent);
return NULL;
}
root = json_object();
if (root == NULL)
return NULL;
- if (json_object_set_new(root, "min", asn1int2json(range->min)) < 0)
+ if (json_object_set_new(root, "min", asn1int2json(range->min)))
goto fail;
- if (json_object_set_new(root, "max", asn1int2json(range->max)) < 0)
+ if (json_object_set_new(root, "max", asn1int2json(range->max)))
goto fail;
return root;
static json_t *
aor2json(ASIdOrRange const *aor)
{
- json_t *root;
-
if (aor == NULL)
return json_null();
return asr2json(aor->u.range);
}
- json_decref(root);
return NULL;
}
static json_t *
-asidc2json(ASIdentifierChoice const *asidc)
+aior2json(ASIdOrRanges *aior)
{
- json_t *root;
- ASIdOrRanges *iaor;
+ json_t *parent;
+ json_t *child;
int i;
+ if (aior == NULL)
+ return json_null();
+
+ parent = json_array();
+ if (parent == NULL)
+ return NULL;
+
+ for (i = 0; i < sk_ASIdOrRange_num(aior); i++) {
+ child = aor2json(sk_ASIdOrRange_value(aior, i));
+ if (json_array_append_new(parent, child))
+ goto fail;
+ }
+ return parent;
+
+fail: json_decref(parent);
+ return NULL;
+}
+
+static json_t *
+asidc2json(ASIdentifierChoice const *asidc)
+{
if (asidc == NULL)
return json_null();
switch (asidc->type) {
case ASIdentifierChoice_inherit:
return json_string("inherit");
-
case ASIdentifierChoice_asIdsOrRanges:
- iaor = asidc->u.asIdsOrRanges;
- if (iaor == NULL)
- return json_null();
- root = json_array();
- if (root == NULL)
- goto fail;
- for (i = 0; i < sk_ASIdOrRange_num(iaor); i++)
- if (json_array_append_new(root, aor2json(sk_ASIdOrRange_value(iaor, i))) < 0)
- goto fail;
- return root;
+ return aior2json(asidc->u.asIdsOrRanges);
}
return NULL;
-
-fail: json_decref(root);
- return NULL;
}
static json_t *
root = json_object();
if (root == NULL)
return NULL;
- if (json_object_set_new(root, "asnum", asidc2json(asid->asnum)) < 0)
+ if (json_object_set_new(root, "asnum", asidc2json(asid->asnum)))
goto fail;
- if (json_object_set_new(root, "rdi", asidc2json(asid->rdi)) < 0)
+ if (json_object_set_new(root, "rdi", asidc2json(asid->rdi)))
goto fail;
return root;
eku2json(void const *ext)
{
EXTENDED_KEY_USAGE const *eku = ext;
- json_t *root;
+ json_t *parent;
+ json_t *child;
int i;
- root = json_array();
- if (root == NULL)
- return root;
+ parent = json_array();
+ if (parent == NULL)
+ return parent;
- for (i = 0; i < sk_ASN1_OBJECT_num(eku); i++)
- if (json_array_append_new(root, oid2json(sk_ASN1_OBJECT_value(eku, i))) < 0)
+ for (i = 0; i < sk_ASN1_OBJECT_num(eku); i++) {
+ child = oid2json(sk_ASN1_OBJECT_value(eku, i));
+ if (json_array_append_new(parent, child))
goto fail;
+ }
- return root;
+ return parent;
-fail: json_decref(root);
+fail: json_decref(parent);
return NULL;
}
json_t *
name2json(X509_NAME const *name)
{
- json_t *root;
- json_t *rdnSequence;
- json_t *typeval;
+ json_t *root, *rdnSeq;
+ json_t *typeval, *child;
+ X509_NAME_ENTRY *entry;
+ int nid;
+ const ASN1_STRING *data;
int i;
if (name == NULL)
root = json_object();
if (root == NULL)
return NULL;
- if (json_object_set_new(root, "rdnSequence", rdnSequence = json_array()))
+ if (json_object_set_new(root, "rdnSequence", rdnSeq = json_array()))
goto fail;
for (i = 0; i < X509_NAME_entry_count(name); i++) {
- X509_NAME_ENTRY *entry = X509_NAME_get_entry(name, i);
- int nid;
- const ASN1_STRING *data;
-
- if (json_array_append_new(rdnSequence, typeval = json_object()))
+ if (json_array_append_new(rdnSeq, typeval = json_object()))
goto fail;
+ entry = X509_NAME_get_entry(name, i);
nid = OBJ_obj2nid(X509_NAME_ENTRY_get_object(entry));
- if (json_object_set_new(typeval, "type", json_string(OBJ_nid2ln(nid))))
+ data = X509_NAME_ENTRY_get_data(entry);
+
+ child = json_string(OBJ_nid2ln(nid));
+ if (json_object_set_new(typeval, "type", child))
goto fail;
- data = X509_NAME_ENTRY_get_data(entry);
- if (json_object_set_new(typeval, "value", json_stringn((char *)data->data, data->length)))
+ child = json_stringn((char *)data->data, data->length);
+ if (json_object_set_new(typeval, "value", child))
goto fail;
}
json_t *
gns2json(GENERAL_NAMES const *gns)
{
- json_t *root;
+ json_t *parent;
+ json_t *child;
int n;
if (gns == NULL)
return json_null();
- root = json_array();
- if (root == NULL)
+ parent = json_array();
+ if (parent == NULL)
return NULL;
- for (n = 0; n < sk_GENERAL_NAME_num(gns); n++)
- if (json_array_append_new(root, gn2json(sk_GENERAL_NAME_value(gns, n))))
+ for (n = 0; n < sk_GENERAL_NAME_num(gns); n++) {
+ child = gn2json(sk_GENERAL_NAME_value(gns, n));
+ if (json_array_append_new(parent, child))
goto fail;
+ }
- return root;
+ return parent;
-fail: json_decref(root);
+fail: json_decref(parent);
return NULL;
}
exts2json(const STACK_OF(X509_EXTENSION) *exts)
{
json_t *root;
+ json_t *parent;
json_t *child;
+ X509_EXTENSION *ex;
BIO *bio;
char *name;
int i;
- int ret;
if (sk_X509_EXTENSION_num(exts) <= 0)
return json_null();
return NULL;
for (i = 0; i < sk_X509_EXTENSION_num(exts); i++) {
- X509_EXTENSION *ex;
-
- if (json_array_append_new(root, child = json_object()))
+ if (json_array_append_new(root, parent = json_object()))
goto fail;
ex = sk_X509_EXTENSION_value(exts, i);
}
name = bio2str(bio);
- ret = json_object_set_new(child, "extnID", json_string(name));
+ child = json_string(name);
free(name);
- if (ret)
- goto fail;
- if (json_object_set_new(child, "critical", json_boolean(X509_EXTENSION_get_critical(ex))))
+ if (json_object_set_new(parent, "extnID", child))
+ goto fail;
+ child = json_boolean(X509_EXTENSION_get_critical(ex));
+ if (json_object_set_new(parent, "critical", child))
goto fail;
- if (json_object_set_new(child, "extnValue", ext2json(ex)))
+ child = ext2json(ex);
+ if (json_object_set_new(parent, "extnValue", child))
goto fail;
}