From 55dfc116f47b7c7242567f596c82bfd8f81d7b98 Mon Sep 17 00:00:00 2001 From: Kamen Mazdrashki Date: Fri, 25 Sep 2009 17:28:33 +0300 Subject: s4/drsuapi: Internal implementation for ber_read_OID_String Modified implementation _ber_read_OID_String_impl() returns how much bytes are converted. The intentation is to use this implementation both for reading OIDs and partial-OIDs in the future --- lib/util/asn1.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'lib/util') diff --git a/lib/util/asn1.c b/lib/util/asn1.c index 61fb9555a7..0d08027a07 100644 --- a/lib/util/asn1.c +++ b/lib/util/asn1.c @@ -578,6 +578,46 @@ int asn1_tag_remaining(struct asn1_data *data) return remaining; } +/** + * Internal implementation for reading binary OIDs + * Reading is done as far in the buffer as valid OID + * till buffer ends or not valid sub-identifier is found. + */ +static bool _ber_read_OID_String_impl(TALLOC_CTX *mem_ctx, DATA_BLOB blob, + const char **OID, size_t *bytes_eaten) +{ + int i; + uint8_t *b; + uint_t v; + char *tmp_oid = NULL; + + if (blob.length < 2) return false; + + b = blob.data; + + tmp_oid = talloc_asprintf(mem_ctx, "%u", b[0]/40); + if (!tmp_oid) goto nomem; + tmp_oid = talloc_asprintf_append_buffer(tmp_oid, ".%u", b[0]%40); + if (!tmp_oid) goto nomem; + + for(i = 1, v = 0; i < blob.length; i++) { + v = (v<<7) | (b[i]&0x7f); + if ( ! (b[i] & 0x80)) { + tmp_oid = talloc_asprintf_append_buffer(tmp_oid, ".%u", v); + v = 0; + if (bytes_eaten) + *bytes_eaten = i+1; + } + if (!tmp_oid) goto nomem; + } + + *OID = tmp_oid; + return true; + +nomem: + return false; +} + /* read an object ID from a data blob */ bool ber_read_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB blob, const char **OID) { -- cgit