From 715c790600477b9b1ebdae7aa98779fc06be3bd1 Mon Sep 17 00:00:00 2001 From: Kamen Mazdrashki Date: Fri, 25 Sep 2009 16:38:54 +0300 Subject: s4/drsuapi: ber_write_partial_OID_String() implementation --- lib/util/asn1.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'lib/util/asn1.c') diff --git a/lib/util/asn1.c b/lib/util/asn1.c index 70c2c57450c..61fb9555a77 100644 --- a/lib/util/asn1.c +++ b/lib/util/asn1.c @@ -258,6 +258,41 @@ bool ber_write_OID_String(DATA_BLOB *blob, const char *OID) return true; } +/** + * Serialize partial OID string. + * Partial OIDs are in the form: + * 1:2.5.6:0x81 + * 1:2.5.6:0x8182 + */ +bool ber_write_partial_OID_String(DATA_BLOB *blob, const char *partial_oid) +{ + TALLOC_CTX *mem_ctx = talloc_new(NULL); + char *oid = talloc_strdup(mem_ctx, partial_oid); + char *p; + + /* truncate partial part so ber_write_OID_String() works */ + p = strchr(oid, ':'); + if (p) { + *p = '\0'; + p++; + } + + if (!ber_write_OID_String(blob, oid)) { + talloc_free(mem_ctx); + return false; + } + + /* Add partially endcoded subidentifier */ + if (p) { + DATA_BLOB tmp_blob = strhex_to_data_blob(mem_ctx, p); + data_blob_append(NULL, blob, tmp_blob.data, tmp_blob.length); + } + + talloc_free(mem_ctx); + + return true; +} + /* write an object ID to a ASN1 buffer */ bool asn1_write_OID(struct asn1_data *data, const char *OID) { -- cgit