diff --git a/src/libopensc/asn1.c b/src/libopensc/asn1.c index 75a25d50..85319fea 100644 --- a/src/libopensc/asn1.c +++ b/src/libopensc/asn1.c @@ -1659,3 +1659,23 @@ sc_der_copy(sc_pkcs15_der_t *dst, const sc_pkcs15_der_t *src) return SC_SUCCESS; } +int +sc_encode_oid (struct sc_context *ctx, struct sc_object_id *id, + unsigned char **out, size_t *size) +{ + static const struct sc_asn1_entry c_asn1_object_id[2] = { + { "oid", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, SC_ASN1_ALLOC, NULL, NULL }, + { NULL, 0, 0, 0, NULL, NULL } + }; + struct sc_asn1_entry asn1_object_id[2]; + int rv; + + sc_copy_asn1_entry(c_asn1_object_id, asn1_object_id); + sc_format_asn1_entry(asn1_object_id + 0, id, NULL, 1); + + rv = _sc_asn1_encode(ctx, asn1_object_id, out, size, 1); + LOG_TEST_RET(ctx, rv, "Cannot encode object ID"); + + return SC_SUCCESS; +} + diff --git a/src/libopensc/libopensc.exports b/src/libopensc/libopensc.exports index e75160bd..da90dfc4 100644 --- a/src/libopensc/libopensc.exports +++ b/src/libopensc/libopensc.exports @@ -82,6 +82,7 @@ sc_disconnect_card sc_do_log _sc_debug sc_enum_apps +sc_encode_oid sc_parse_ef_atr sc_establish_context sc_file_add_acl_entry diff --git a/src/libopensc/pkcs15.h b/src/libopensc/pkcs15.h index e1748dec..3829272b 100644 --- a/src/libopensc/pkcs15.h +++ b/src/libopensc/pkcs15.h @@ -777,6 +777,8 @@ int sc_der_copy(sc_pkcs15_der_t *, const sc_pkcs15_der_t *); int sc_pkcs15_get_object_id(const struct sc_pkcs15_object *, struct sc_pkcs15_id *); int sc_pkcs15_get_guid(struct sc_pkcs15_card *, const struct sc_pkcs15_object *, char *, size_t); +int sc_encode_oid (struct sc_context *, struct sc_object_id *, + unsigned char **, size_t *); /* Prepend 'parent' to 'child' in case 'child' is a relative path */ int sc_pkcs15_make_absolute_path(const sc_path_t *parent, sc_path_t *child);