]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Reindent
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Thu, 9 May 2024 23:44:03 +0000 (17:44 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Thu, 9 May 2024 23:47:53 +0000 (17:47 -0600)
Reduce 80 column limit violations in the ASN1 code.

12 files changed:
src/asn1/asn1c/CMSAttribute.c
src/asn1/asn1c/CRL.c
src/asn1/asn1c/Certificate.c
src/asn1/asn1c/CertificateSet.c
src/asn1/asn1c/ContentInfo.c
src/asn1/asn1c/EncapsulatedContentInfo.c
src/asn1/asn1c/ROAIPAddressFamily.c
src/asn1/asn1c/constr_SEQUENCE.c
src/asn1/asn1c/constr_SET_OF.c
src/cache/local_cache.c
src/extension.c
src/libcrypto_util.c

index fb09a614d492435251a488f84d3d6e612e8eb60d..b016cb657e4ca3c19d16f8304b0f38cb2a9a0066 100644 (file)
@@ -34,7 +34,8 @@ CMSAttribute_encode_json(const asn_TYPE_descriptor_t *td, const void *sptr)
 {
        struct CMSAttribute const *cattr = sptr;
        json_t *root;
-       json_t *attrValues;
+       json_t *array;
+       json_t *tmp;
        int a;
 
        if (!cattr)
@@ -44,9 +45,10 @@ CMSAttribute_encode_json(const asn_TYPE_descriptor_t *td, const void *sptr)
        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))
@@ -58,9 +60,11 @@ CMSAttribute_encode_json(const asn_TYPE_descriptor_t *td, const void *sptr)
        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;
 
index e381540991d335cf904695f2a8145aff8a26d255..6b8afce4bb0f57a24d823be35bd6f8108e4fc2ad 100644 (file)
@@ -9,7 +9,9 @@ static json_t *
 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;
 
@@ -19,13 +21,18 @@ revokedCerts2json(X509_CRL *crl)
 
        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;
        }
 
@@ -38,30 +45,38 @@ fail:       json_decref(root);
 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;
 }
 
@@ -88,22 +103,26 @@ sigValue2json(X509_CRL *crl)
 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;
 }
 
@@ -111,14 +130,14 @@ json_t *
 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;
 }
index 571f487d15a97ee9a775b7f9d9a81e3f89b629dd..c00d079709a63ad11a62c837abbea38113e74cee 100644 (file)
@@ -8,20 +8,23 @@
 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;
 }
 
@@ -89,36 +92,47 @@ suid2json(X509 const *x)
 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;
 }
 
@@ -145,22 +159,26 @@ sigValue2json(X509 *cert)
 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;
 }
 
@@ -169,7 +187,7 @@ Certificate_any2json(ANY_t *ber)
 {
        const unsigned char *tmp;
        X509 *cert;
-       json_t *root;
+       json_t *json;
 
        /*
         * "If the call is successful *in is incremented to the byte following
@@ -183,24 +201,24 @@ Certificate_any2json(ANY_t *ber)
        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;
 }
index 012ef3b04026547757520579487f0afec1e7a1ce..ff566f178b864e265173141d2a2ab79ceb78d2c6 100644 (file)
@@ -12,30 +12,29 @@ static json_t *
 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;
 }
 
index e5d4bdd5be9993d2622da50da22df5d64db0804d..8522f913fad2382b9f5121f1dd60d426c334cd6a 100644 (file)
@@ -32,8 +32,7 @@ ContentInfo_encode_json(const asn_TYPE_descriptor_t *td, const void *sptr)
 {
        struct ContentInfo const *ci = sptr;
        json_t *parent;
-       json_t *content_type;
-       json_t *content;
+       json_t *child;
 
        if (!ci)
                return json_null();
@@ -43,27 +42,18 @@ ContentInfo_encode_json(const asn_TYPE_descriptor_t *td, const void *sptr)
                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;
index e2470f19a489a340cff87fafb4d60bb743f172b8..e181787fb1850cc2ad68806b12b19b7e937f0500 100644 (file)
@@ -34,8 +34,7 @@ EncapsulatedContentInfo_encode_json(const asn_TYPE_descriptor_t *td,
 {
        struct EncapsulatedContentInfo const *eci = sptr;
        json_t *parent;
-       json_t *content_type;
-       json_t *content;
+       json_t *child;
 
        if (!eci)
                return json_null();
@@ -45,37 +44,24 @@ EncapsulatedContentInfo_encode_json(const asn_TYPE_descriptor_t *td,
                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;
index c62ae1e0d0046ad01c72928058fd74f9361147b0..a509f1299964fc454279e3266c44bce9edfe8512 100644 (file)
@@ -17,9 +17,9 @@ prefix2json(char const *prefix, uint8_t length)
        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;
@@ -60,29 +60,30 @@ static json_t *
 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;
        }
 
index c4d177dfdc93e35bd92e214969a0d4b83f7f22e6..72a73b9fb08937e34cced8cb1033f38e0e01d02b 100644 (file)
@@ -614,7 +614,8 @@ SEQUENCE_encode_der(const asn_TYPE_descriptor_t *td, const void *sptr,
 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)
@@ -636,8 +637,6 @@ SEQUENCE_encode_json(const struct asn_TYPE_descriptor_s *td, const void *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;
        }
index e2162e134a8f3b04420ef316398eb480e0887bc4..72067ca2f2fd822c43e6c57d66a62b78594f80b8 100644 (file)
@@ -492,7 +492,8 @@ SET_OF_encode_der(const asn_TYPE_descriptor_t *td, const void *sptr,
 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;
@@ -500,24 +501,22 @@ SET_OF_encode_json(const struct asn_TYPE_descriptor_s *td, const void *sptr)
        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;
 }
 
index 6670c3d94d545bf2456d2d347e9e8a86f38c846e..86e981b0df5ed72b9bf4d04bbc9585bede218c85 100644 (file)
@@ -419,8 +419,6 @@ build_tal_json(struct rpki_cache *cache)
 
        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));
index 4786b9a128df3060f9b82647a32d127d5a4ef0d6..8e1888ba9c2b51c89a29f95242a4097e8ebbe4c7 100644 (file)
@@ -21,20 +21,23 @@ static json_t *
 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;
 }
 
@@ -76,22 +79,26 @@ static json_t *
 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;
 }
 
@@ -114,39 +121,49 @@ ku2json(void const *ext)
 {
        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;
 }
 
@@ -168,6 +185,7 @@ static json_t *
 rdn2json(STACK_OF(X509_NAME_ENTRY) *rdn)
 {
        json_t *root;
+       json_t *parent;
        json_t *child;
        X509_NAME_ENTRY *name;
        int n;
@@ -177,13 +195,16 @@ rdn2json(STACK_OF(X509_NAME_ENTRY) *rdn)
                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;
        }
 
@@ -207,7 +228,9 @@ static json_t *
 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;
 
@@ -217,13 +240,18 @@ cdp2json(void const *ext)
 
        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;
        }
 
@@ -252,7 +280,9 @@ aia2json(void const *ext)
 {
        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();
@@ -261,11 +291,15 @@ aia2json(void const *ext)
 
        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;
        }
 
@@ -300,69 +334,78 @@ static const struct extension_metadata SIA = {
 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;
 }
 
@@ -370,20 +413,23 @@ static json_t *
 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;
 }
 
@@ -429,8 +475,6 @@ p2json(ASN1_BIT_STRING const *ap, int af)
 static json_t *
 iaor2json(IPAddressOrRange const *iaor, int af)
 {
-       json_t *root;
-
        if (iaor == NULL)
                return json_null();
 
@@ -441,47 +485,56 @@ iaor2json(IPAddressOrRange const *iaor, int af)
                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;
@@ -489,8 +542,8 @@ iaf2json(IPAddressFamily const *iaf)
        if (iaf == NULL)
                return json_null();
 
-       root = json_object();
-       if (root == NULL)
+       parent = json_object();
+       if (parent == NULL)
                return NULL;
 
        af = iaf->addressFamily;
@@ -507,14 +560,16 @@ iaf2json(IPAddressFamily const *iaf)
                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;
 }
 
@@ -522,20 +577,23 @@ static json_t *
 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;
 }
 
@@ -564,9 +622,9 @@ asr2json(ASRange const *range)
        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;
@@ -578,8 +636,6 @@ fail:       json_decref(root);
 static json_t *
 aor2json(ASIdOrRange const *aor)
 {
-       json_t *root;
-
        if (aor == NULL)
                return json_null();
 
@@ -590,41 +646,48 @@ aor2json(ASIdOrRange const *aor)
                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 *
@@ -639,9 +702,9 @@ ar2json(void const *ext)
        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;
@@ -704,20 +767,23 @@ static json_t *
 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;
 }
 
index 35a0b9db585a62a7856b4c5125674e1d798aede9..61d665d0059403bcb21475027ca455ce31744cd9 100644 (file)
@@ -116,9 +116,11 @@ asn1time2json(ASN1_TIME const *time)
 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)
@@ -127,23 +129,23 @@ name2json(X509_NAME const *name)
        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;
        }
 
@@ -171,23 +173,26 @@ gn2json(GENERAL_NAME const *gn)
 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;
 }
 
@@ -248,11 +253,12 @@ json_t *
 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();
@@ -262,9 +268,7 @@ exts2json(const STACK_OF(X509_EXTENSION) *exts)
                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);
@@ -279,14 +283,16 @@ exts2json(const STACK_OF(X509_EXTENSION) *exts)
                }
 
                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;
        }