}
}
-/* FIXME use this more. */
int
ANY_to_type(ANY_t *st, asn_TYPE_descriptor_t *td, void **struct_ptr) {
asn_dec_rval_t rval;
return 0;
}
+
+json_t *
+ANY_to_json(const asn_TYPE_descriptor_t *td, ANY_t const *ber)
+{
+ return ber2json(td, ber->buf, ber->size);
+}
#define ANY_new_fromBuf(buf, size) OCTET_STRING_new_fromBuf( \
&asn_DEF_ANY, (buf), (size))
+json_t *ANY_to_json(const asn_TYPE_descriptor_t *, ANY_t const *);
+
#endif /* ASN_TYPE_ANY_H */
#include "asn1/asn1c/MessageDigest.h"
#include "asn1/asn1c/SigningTime.h"
-static json_t *
-attr2json(asn_TYPE_descriptor_t const *td, CMSAttributeValue_t const *ber)
-{
- void *attr;
- asn_dec_rval_t rval;
- json_t *json;
-
- attr = NULL;
- rval = ber_decode(td, &attr, ber->buf, ber->size);
-
- json = (rval.code == RC_OK) ? td->op->json_encoder(td, attr) : NULL;
-
- ASN_STRUCT_FREE(*td, attr);
- return json;
-}
-
json_t *
CMSAttribute_encode_json(const asn_TYPE_descriptor_t *td, const void *sptr)
{
}
for (a = 0; a < cattr->attrValues.list.count; a++) {
- tmp = attr2json(td, cattr->attrValues.list.array[a]);
+ tmp = ANY_to_json(td, cattr->attrValues.list.array[a]);
if (json_array_add(array, tmp))
goto fail;
}
#include "json_util.h"
#include "asn1/asn1c/SignedData.h"
-json_t *
-content2json(const asn_TYPE_descriptor_t *td, ANY_t const *ber)
-{
- void *decoded;
- asn_dec_rval_t rval;
- json_t *json;
-
- decoded = NULL;
- rval = ber_decode(td, &decoded, ber->buf, ber->size);
-
- json = (rval.code == RC_OK) ? td->op->json_encoder(td, decoded) : NULL;
-
- ASN_STRUCT_FREE(*td, decoded);
- return json;
-}
-
json_t *
ContentInfo_encode_json(const asn_TYPE_descriptor_t *td, const void *sptr)
{
if (OBJECT_IDENTIFIER_to_nid(&ci->contentType) == NID_pkcs7_signed) {
td = &asn_DEF_SignedData;
- child = content2json(td, &ci->content);
+ child = ANY_to_json(td, &ci->content);
} else {
td = &asn_DEF_ANY;
child = td->op->json_encoder(td, &ci->content);
#include "asn1/asn1c/Manifest.h"
#include "asn1/asn1c/RouteOriginAttestation.h"
-static json_t *
-econtent2json(asn_TYPE_descriptor_t const *td, OCTET_STRING_t *eContent)
-{
- void *decoded;
- asn_dec_rval_t rval;
- json_t *json;
-
- decoded = NULL;
- rval = ber_decode(td, &decoded, eContent->buf, eContent->size);
-
- json = (rval.code == RC_OK) ? td->op->json_encoder(td, decoded) : NULL;
-
- ASN_STRUCT_FREE(*td, decoded);
- return json;
-}
-
json_t *
EncapsulatedContentInfo_encode_json(const asn_TYPE_descriptor_t *td,
const void *sptr)
nid = OBJECT_IDENTIFIER_to_nid(&eci->eContentType);
if (nid == nid_ct_mft()) {
td = &asn_DEF_Manifest;
- child = econtent2json(td, eci->eContent);
+ child = OCTET_STRING_to_json(td, eci->eContent);
} else if (nid == nid_ct_roa()) {
td = &asn_DEF_RouteOriginAttestation;
- child = econtent2json(td, eci->eContent);
+ child = OCTET_STRING_to_json(td, eci->eContent);
} else if (nid == nid_ct_gbr()) {
td = &asn_DEF_OCTET_STRING;
child = OCTET_STRING_encode_json_utf8(td, eci->eContent);
return st;
}
+json_t *
+OCTET_STRING_to_json(const asn_TYPE_descriptor_t *td, OCTET_STRING_t const *ber)
+{
+ return ber2json(td, ber->buf, ber->size);
+}
+
/*
* Lexicographically compare the common prefix of both strings,
* and if it is the same return -1 for the smallest string.
OCTET_STRING_t *OCTET_STRING_new_fromBuf(const asn_TYPE_descriptor_t *td,
const char *str, int size);
+json_t *OCTET_STRING_to_json(const asn_TYPE_descriptor_t *,
+ OCTET_STRING_t const *);
+
/****************************
* Internally useful stuff. *
****************************/
return td->op->json_encoder(td, sptr);
}
+
+json_t *
+ber2json(struct asn_TYPE_descriptor_s const *td, uint8_t *buf, size_t size)
+{
+ void *decoded;
+ asn_dec_rval_t rval;
+ json_t *json;
+
+ decoded = NULL;
+ rval = ber_decode(td, &decoded, buf, size);
+
+ json = (rval.code == RC_OK) ? td->op->json_encoder(td, decoded) : NULL;
+
+ ASN_STRUCT_FREE(*td, decoded);
+ return json;
+}
#define SRC_ASN1_ASN1C_JSON_ENCODER_H_
#include <jansson.h>
+#include <stdint.h>
struct asn_TYPE_descriptor_s; /* Forward declaration */
const void *struct_ptr /* Structure to be encoded */
);
+json_t *ber2json(struct asn_TYPE_descriptor_s const *, uint8_t *, size_t);
+
/*
* Type of the generic JSON encoder.
*/