Blame SOURCES/0003-asn1-remove-some-usused-functions.patch

4c3126
From e877c21f5e2394c8325955c645f214b8868317c8 Mon Sep 17 00:00:00 2001
4c3126
From: Jeff Layton <jlayton@samba.org>
4c3126
Date: Wed, 9 Oct 2013 08:17:49 -0400
4c3126
Subject: [PATCH] asn1: remove some usused functions
4c3126
4c3126
This cuts 30k out of the cifs.upcall binary on my x86_64 box.
4c3126
4c3126
Signed-off-by: Jeff Layton <jlayton@samba.org>
4c3126
---
4c3126
 asn1.c | 638 -----------------------------------------------------------------
4c3126
 asn1.h |  37 ----
4c3126
 2 files changed, 675 deletions(-)
4c3126
4c3126
diff --git a/asn1.c b/asn1.c
4c3126
index a00c474..ea50a23 100644
4c3126
--- a/asn1.c
4c3126
+++ b/asn1.c
4c3126
@@ -140,83 +140,6 @@ bool asn1_pop_tag(struct asn1_data *data)
4c3126
 	return true;
4c3126
 }
4c3126
 
4c3126
-/* "i" is the one's complement representation, as is the normal result of an
4c3126
- * implicit signed->unsigned conversion */
4c3126
-
4c3126
-static bool push_int_bigendian(struct asn1_data *data, unsigned int i, bool negative)
4c3126
-{
4c3126
-	uint8_t lowest = i & 0xFF;
4c3126
-
4c3126
-	i = i >> 8;
4c3126
-	if (i != 0)
4c3126
-		if (!push_int_bigendian(data, i, negative))
4c3126
-			return false;
4c3126
-
4c3126
-	if (data->nesting->start+1 == data->ofs) {
4c3126
-
4c3126
-		/* We did not write anything yet, looking at the highest
4c3126
-		 * valued byte */
4c3126
-
4c3126
-		if (negative) {
4c3126
-			/* Don't write leading 0xff's */
4c3126
-			if (lowest == 0xFF)
4c3126
-				return true;
4c3126
-
4c3126
-			if ((lowest & 0x80) == 0) {
4c3126
-				/* The only exception for a leading 0xff is if
4c3126
-				 * the highest bit is 0, which would indicate
4c3126
-				 * a positive value */
4c3126
-				if (!asn1_write_uint8(data, 0xff))
4c3126
-					return false;
4c3126
-			}
4c3126
-		} else {
4c3126
-			if (lowest & 0x80) {
4c3126
-				/* The highest bit of a positive integer is 1,
4c3126
-				 * this would indicate a negative number. Push
4c3126
-				 * a 0 to indicate a positive one */
4c3126
-				if (!asn1_write_uint8(data, 0))
4c3126
-					return false;
4c3126
-			}
4c3126
-		}
4c3126
-	}
4c3126
-
4c3126
-	return asn1_write_uint8(data, lowest);
4c3126
-}
4c3126
-
4c3126
-/* write an Integer without the tag framing. Needed for example for the LDAP
4c3126
- * Abandon Operation */
4c3126
-
4c3126
-bool asn1_write_implicit_Integer(struct asn1_data *data, int i)
4c3126
-{
4c3126
-	if (i == -1) {
4c3126
-		/* -1 is special as it consists of all-0xff bytes. In
4c3126
-                    push_int_bigendian this is the only case that is not
4c3126
-                    properly handled, as all 0xff bytes would be handled as
4c3126
-                    leading ones to be ignored. */
4c3126
-		return asn1_write_uint8(data, 0xff);
4c3126
-	} else {
4c3126
-		return push_int_bigendian(data, i, i<0);
4c3126
-	}
4c3126
-}
4c3126
-
4c3126
-
4c3126
-/* write an integer */
4c3126
-bool asn1_write_Integer(struct asn1_data *data, int i)
4c3126
-{
4c3126
-	if (!asn1_push_tag(data, ASN1_INTEGER)) return false;
4c3126
-	if (!asn1_write_implicit_Integer(data, i)) return false;
4c3126
-	return asn1_pop_tag(data);
4c3126
-}
4c3126
-
4c3126
-/* write a BIT STRING */
4c3126
-bool asn1_write_BitString(struct asn1_data *data, const void *p, size_t length, uint8_t padding)
4c3126
-{
4c3126
-	if (!asn1_push_tag(data, ASN1_BIT_STRING)) return false;
4c3126
-	if (!asn1_write_uint8(data, padding)) return false;
4c3126
-	if (!asn1_write(data, p, length)) return false;
4c3126
-	return asn1_pop_tag(data);
4c3126
-}
4c3126
-
4c3126
 bool ber_write_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *OID)
4c3126
 {
4c3126
 	unsigned int v, v2;
4c3126
@@ -291,564 +214,3 @@ bool asn1_write_OctetString(struct asn1_data *data, const void *p, size_t length
4c3126
 	return !data->has_error;
4c3126
 }
4c3126
 
4c3126
-/* write a LDAP string */
4c3126
-bool asn1_write_LDAPString(struct asn1_data *data, const char *s)
4c3126
-{
4c3126
-	asn1_write(data, s, strlen(s));
4c3126
-	return !data->has_error;
4c3126
-}
4c3126
-
4c3126
-/* write a LDAP string from a DATA_BLOB */
4c3126
-bool asn1_write_DATA_BLOB_LDAPString(struct asn1_data *data, const DATA_BLOB *s)
4c3126
-{
4c3126
-	asn1_write(data, s->data, s->length);
4c3126
-	return !data->has_error;
4c3126
-}
4c3126
-
4c3126
-/* write a general string */
4c3126
-bool asn1_write_GeneralString(struct asn1_data *data, const char *s)
4c3126
-{
4c3126
-	asn1_push_tag(data, ASN1_GENERAL_STRING);
4c3126
-	asn1_write_LDAPString(data, s);
4c3126
-	asn1_pop_tag(data);
4c3126
-	return !data->has_error;
4c3126
-}
4c3126
-
4c3126
-bool asn1_write_ContextSimple(struct asn1_data *data, uint8_t num, DATA_BLOB *blob)
4c3126
-{
4c3126
-	asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(num));
4c3126
-	asn1_write(data, blob->data, blob->length);
4c3126
-	asn1_pop_tag(data);
4c3126
-	return !data->has_error;
4c3126
-}
4c3126
-
4c3126
-/* write a BOOLEAN */
4c3126
-bool asn1_write_BOOLEAN(struct asn1_data *data, bool v)
4c3126
-{
4c3126
-	asn1_push_tag(data, ASN1_BOOLEAN);
4c3126
-	asn1_write_uint8(data, v ? 0xFF : 0);
4c3126
-	asn1_pop_tag(data);
4c3126
-	return !data->has_error;
4c3126
-}
4c3126
-
4c3126
-bool asn1_read_BOOLEAN(struct asn1_data *data, bool *v)
4c3126
-{
4c3126
-	uint8_t tmp = 0;
4c3126
-	asn1_start_tag(data, ASN1_BOOLEAN);
4c3126
-	asn1_read_uint8(data, &tmp);
4c3126
-	if (tmp == 0xFF) {
4c3126
-		*v = true;
4c3126
-	} else {
4c3126
-		*v = false;
4c3126
-	}
4c3126
-	asn1_end_tag(data);
4c3126
-	return !data->has_error;
4c3126
-}
4c3126
-
4c3126
-/* write a BOOLEAN in a simple context */
4c3126
-bool asn1_write_BOOLEAN_context(struct asn1_data *data, bool v, int context)
4c3126
-{
4c3126
-	asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(context));
4c3126
-	asn1_write_uint8(data, v ? 0xFF : 0);
4c3126
-	asn1_pop_tag(data);
4c3126
-	return !data->has_error;
4c3126
-}
4c3126
-
4c3126
-bool asn1_read_BOOLEAN_context(struct asn1_data *data, bool *v, int context)
4c3126
-{
4c3126
-	uint8_t tmp = 0;
4c3126
-	asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(context));
4c3126
-	asn1_read_uint8(data, &tmp);
4c3126
-	if (tmp == 0xFF) {
4c3126
-		*v = true;
4c3126
-	} else {
4c3126
-		*v = false;
4c3126
-	}
4c3126
-	asn1_end_tag(data);
4c3126
-	return !data->has_error;
4c3126
-}
4c3126
-
4c3126
-/* check a BOOLEAN */
4c3126
-bool asn1_check_BOOLEAN(struct asn1_data *data, bool v)
4c3126
-{
4c3126
-	uint8_t b = 0;
4c3126
-
4c3126
-	asn1_read_uint8(data, &b);
4c3126
-	if (b != ASN1_BOOLEAN) {
4c3126
-		data->has_error = true;
4c3126
-		return false;
4c3126
-	}
4c3126
-	asn1_read_uint8(data, &b);
4c3126
-	if (b != v) {
4c3126
-		data->has_error = true;
4c3126
-		return false;
4c3126
-	}
4c3126
-	return !data->has_error;
4c3126
-}
4c3126
-
4c3126
-
4c3126
-/* load a struct asn1_data structure with a lump of data, ready to be parsed */
4c3126
-bool asn1_load(struct asn1_data *data, DATA_BLOB blob)
4c3126
-{
4c3126
-	ZERO_STRUCTP(data);
4c3126
-	data->data = (uint8_t *)talloc_memdup(data, blob.data, blob.length);
4c3126
-	if (!data->data) {
4c3126
-		data->has_error = true;
4c3126
-		return false;
4c3126
-	}
4c3126
-	data->length = blob.length;
4c3126
-	return true;
4c3126
-}
4c3126
-
4c3126
-/* Peek into an ASN1 buffer, not advancing the pointer */
4c3126
-bool asn1_peek(struct asn1_data *data, void *p, int len)
4c3126
-{
4c3126
-	if (data->has_error)
4c3126
-		return false;
4c3126
-
4c3126
-	if (len < 0 || data->ofs + len < data->ofs || data->ofs + len < len)
4c3126
-		return false;
4c3126
-
4c3126
-	if ((size_t)data->ofs + len > data->length) {
4c3126
-		/* we need to mark the buffer as consumed, so the caller knows
4c3126
-		   this was an out of data error, and not a decode error */
4c3126
-		data->ofs = data->length;
4c3126
-		return false;
4c3126
-	}
4c3126
-
4c3126
-	memcpy(p, data->data + data->ofs, len);
4c3126
-	return true;
4c3126
-}
4c3126
-
4c3126
-/* read from a ASN1 buffer, advancing the buffer pointer */
4c3126
-bool asn1_read(struct asn1_data *data, void *p, int len)
4c3126
-{
4c3126
-	if (!asn1_peek(data, p, len)) {
4c3126
-		data->has_error = true;
4c3126
-		return false;
4c3126
-	}
4c3126
-
4c3126
-	data->ofs += len;
4c3126
-	return true;
4c3126
-}
4c3126
-
4c3126
-/* read a uint8_t from a ASN1 buffer */
4c3126
-bool asn1_read_uint8(struct asn1_data *data, uint8_t *v)
4c3126
-{
4c3126
-	return asn1_read(data, v, 1);
4c3126
-}
4c3126
-
4c3126
-bool asn1_peek_uint8(struct asn1_data *data, uint8_t *v)
4c3126
-{
4c3126
-	return asn1_peek(data, v, 1);
4c3126
-}
4c3126
-
4c3126
-bool asn1_peek_tag(struct asn1_data *data, uint8_t tag)
4c3126
-{
4c3126
-	uint8_t b;
4c3126
-
4c3126
-	if (asn1_tag_remaining(data) <= 0) {
4c3126
-		return false;
4c3126
-	}
4c3126
-
4c3126
-	if (!asn1_peek_uint8(data, &b))
4c3126
-		return false;
4c3126
-
4c3126
-	return (b == tag);
4c3126
-}
4c3126
-
4c3126
-/* start reading a nested asn1 structure */
4c3126
-bool asn1_start_tag(struct asn1_data *data, uint8_t tag)
4c3126
-{
4c3126
-	uint8_t b;
4c3126
-	struct nesting *nesting;
4c3126
-	
4c3126
-	if (!asn1_read_uint8(data, &b))
4c3126
-		return false;
4c3126
-
4c3126
-	if (b != tag) {
4c3126
-		data->has_error = true;
4c3126
-		return false;
4c3126
-	}
4c3126
-	nesting = talloc(data, struct nesting);
4c3126
-	if (!nesting) {
4c3126
-		data->has_error = true;
4c3126
-		return false;
4c3126
-	}
4c3126
-
4c3126
-	if (!asn1_read_uint8(data, &b)) {
4c3126
-		return false;
4c3126
-	}
4c3126
-
4c3126
-	if (b & 0x80) {
4c3126
-		int n = b & 0x7f;
4c3126
-		if (!asn1_read_uint8(data, &b))
4c3126
-			return false;
4c3126
-		nesting->taglen = b;
4c3126
-		while (n > 1) {
4c3126
-			if (!asn1_read_uint8(data, &b)) 
4c3126
-				return false;
4c3126
-			nesting->taglen = (nesting->taglen << 8) | b;
4c3126
-			n--;
4c3126
-		}
4c3126
-	} else {
4c3126
-		nesting->taglen = b;
4c3126
-	}
4c3126
-	nesting->start = data->ofs;
4c3126
-	nesting->next = data->nesting;
4c3126
-	data->nesting = nesting;
4c3126
-	if (asn1_tag_remaining(data) == -1) {
4c3126
-		return false;
4c3126
-	}
4c3126
-	return !data->has_error;
4c3126
-}
4c3126
-
4c3126
-/* stop reading a tag */
4c3126
-bool asn1_end_tag(struct asn1_data *data)
4c3126
-{
4c3126
-	struct nesting *nesting;
4c3126
-
4c3126
-	/* make sure we read it all */
4c3126
-	if (asn1_tag_remaining(data) != 0) {
4c3126
-		data->has_error = true;
4c3126
-		return false;
4c3126
-	}
4c3126
-
4c3126
-	nesting = data->nesting;
4c3126
-
4c3126
-	if (!nesting) {
4c3126
-		data->has_error = true;
4c3126
-		return false;
4c3126
-	}
4c3126
-
4c3126
-	data->nesting = nesting->next;
4c3126
-	talloc_free(nesting);
4c3126
-	return true;
4c3126
-}
4c3126
-
4c3126
-/* work out how many bytes are left in this nested tag */
4c3126
-int asn1_tag_remaining(struct asn1_data *data)
4c3126
-{
4c3126
-	int remaining;
4c3126
-	if (data->has_error) {
4c3126
-		return -1;
4c3126
-	}
4c3126
-
4c3126
-	if (!data->nesting) {
4c3126
-		data->has_error = true;
4c3126
-		return -1;
4c3126
-	}
4c3126
-	remaining = data->nesting->taglen - (data->ofs - data->nesting->start);
4c3126
-	if (remaining < 0) {
4c3126
-		data->has_error = true;
4c3126
-		return -1;
4c3126
-	}
4c3126
-	if ((size_t)remaining > data->length - data->ofs) {
4c3126
-		data->has_error = true;
4c3126
-		return -1;
4c3126
-	}
4c3126
-	return remaining;
4c3126
-}
4c3126
-
4c3126
-/**
4c3126
- * Internal implementation for reading binary OIDs
4c3126
- * Reading is done as far in the buffer as valid OID
4c3126
- * till buffer ends or not valid sub-identifier is found.
4c3126
- */
4c3126
-static bool _ber_read_OID_String_impl(TALLOC_CTX *mem_ctx, DATA_BLOB blob,
4c3126
-					const char **OID, size_t *bytes_eaten)
4c3126
-{
4c3126
-	unsigned int i;
4c3126
-	uint8_t *b;
4c3126
-	unsigned int v;
4c3126
-	char *tmp_oid = NULL;
4c3126
-
4c3126
-	if (blob.length < 2) return false;
4c3126
-
4c3126
-	b = blob.data;
4c3126
-
4c3126
-	tmp_oid = talloc_asprintf(mem_ctx, "%u",  b[0]/40);
4c3126
-	if (!tmp_oid) goto nomem;
4c3126
-	tmp_oid = talloc_asprintf_append_buffer(tmp_oid, ".%u",  b[0]%40);
4c3126
-	if (!tmp_oid) goto nomem;
4c3126
-
4c3126
-	for(i = 1, v = 0; i < blob.length; i++) {
4c3126
-		v = (v<<7) | (b[i]&0x7f);
4c3126
-		if ( ! (b[i] & 0x80)) {
4c3126
-			tmp_oid = talloc_asprintf_append_buffer(tmp_oid, ".%u",  v);
4c3126
-			v = 0;
4c3126
-			if (bytes_eaten)
4c3126
-				*bytes_eaten = i+1;
4c3126
-		}
4c3126
-		if (!tmp_oid) goto nomem;
4c3126
-	}
4c3126
-
4c3126
-	*OID = tmp_oid;
4c3126
-	return true;
4c3126
-
4c3126
-nomem:
4c3126
-	return false;
4c3126
-}
4c3126
-
4c3126
-/* read an object ID from a data blob */
4c3126
-bool ber_read_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB blob, const char **OID)
4c3126
-{
4c3126
-	size_t bytes_eaten = 0;
4c3126
-
4c3126
-	if (!_ber_read_OID_String_impl(mem_ctx, blob, OID, &bytes_eaten))
4c3126
-		return false;
4c3126
-
4c3126
-	return (bytes_eaten == blob.length);
4c3126
-}
4c3126
-
4c3126
-/* read an object ID from a ASN1 buffer */
4c3126
-bool asn1_read_OID(struct asn1_data *data, TALLOC_CTX *mem_ctx, const char **OID)
4c3126
-{
4c3126
-	DATA_BLOB blob;
4c3126
-	int len;
4c3126
-
4c3126
-	if (!asn1_start_tag(data, ASN1_OID)) return false;
4c3126
-
4c3126
-	len = asn1_tag_remaining(data);
4c3126
-	if (len < 0) {
4c3126
-		data->has_error = true;
4c3126
-		return false;
4c3126
-	}
4c3126
-
4c3126
-	blob = data_blob(NULL, len);
4c3126
-	if (!blob.data) {
4c3126
-		data->has_error = true;
4c3126
-		return false;
4c3126
-	}
4c3126
-
4c3126
-	asn1_read(data, blob.data, len);
4c3126
-	asn1_end_tag(data);
4c3126
-	if (data->has_error) {
4c3126
-		data_blob_free(&blob;;
4c3126
-		return false;
4c3126
-	}
4c3126
-
4c3126
-	if (!ber_read_OID_String(mem_ctx, blob, OID)) {
4c3126
-		data->has_error = true;
4c3126
-		data_blob_free(&blob;;
4c3126
-		return false;
4c3126
-	}
4c3126
-
4c3126
-	data_blob_free(&blob;;
4c3126
-	return true;
4c3126
-}
4c3126
-
4c3126
-/* check that the next object ID is correct */
4c3126
-bool asn1_check_OID(struct asn1_data *data, const char *OID)
4c3126
-{
4c3126
-	const char *id;
4c3126
-
4c3126
-	if (!asn1_read_OID(data, data, &id)) return false;
4c3126
-
4c3126
-	if (strcmp(id, OID) != 0) {
4c3126
-		talloc_free(discard_const(id));
4c3126
-		data->has_error = true;
4c3126
-		return false;
4c3126
-	}
4c3126
-	talloc_free(discard_const(id));
4c3126
-	return true;
4c3126
-}
4c3126
-
4c3126
-/* read a LDAPString from a ASN1 buffer */
4c3126
-bool asn1_read_LDAPString(struct asn1_data *data, TALLOC_CTX *mem_ctx, char **s)
4c3126
-{
4c3126
-	int len;
4c3126
-	len = asn1_tag_remaining(data);
4c3126
-	if (len < 0) {
4c3126
-		data->has_error = true;
4c3126
-		return false;
4c3126
-	}
4c3126
-	*s = talloc_array(mem_ctx, char, len+1);
4c3126
-	if (! *s) {
4c3126
-		data->has_error = true;
4c3126
-		return false;
4c3126
-	}
4c3126
-	asn1_read(data, *s, len);
4c3126
-	(*s)[len] = 0;
4c3126
-	return !data->has_error;
4c3126
-}
4c3126
-
4c3126
-
4c3126
-/* read a GeneralString from a ASN1 buffer */
4c3126
-bool asn1_read_GeneralString(struct asn1_data *data, TALLOC_CTX *mem_ctx, char **s)
4c3126
-{
4c3126
-	if (!asn1_start_tag(data, ASN1_GENERAL_STRING)) return false;
4c3126
-	if (!asn1_read_LDAPString(data, mem_ctx, s)) return false;
4c3126
-	return asn1_end_tag(data);
4c3126
-}
4c3126
-
4c3126
-
4c3126
-/* read a octet string blob */
4c3126
-bool asn1_read_OctetString(struct asn1_data *data, TALLOC_CTX *mem_ctx, DATA_BLOB *blob)
4c3126
-{
4c3126
-	int len;
4c3126
-	ZERO_STRUCTP(blob);
4c3126
-	if (!asn1_start_tag(data, ASN1_OCTET_STRING)) return false;
4c3126
-	len = asn1_tag_remaining(data);
4c3126
-	if (len < 0) {
4c3126
-		data->has_error = true;
4c3126
-		return false;
4c3126
-	}
4c3126
-	*blob = data_blob_talloc(mem_ctx, NULL, len+1);
4c3126
-	if (!blob->data) {
4c3126
-		data->has_error = true;
4c3126
-		return false;
4c3126
-	}
4c3126
-	asn1_read(data, blob->data, len);
4c3126
-	asn1_end_tag(data);
4c3126
-	blob->length--;
4c3126
-	blob->data[len] = 0;
4c3126
-	
4c3126
-	if (data->has_error) {
4c3126
-		data_blob_free(blob);
4c3126
-		*blob = data_blob_null;
4c3126
-		return false;
4c3126
-	}
4c3126
-	return true;
4c3126
-}
4c3126
-
4c3126
-bool asn1_read_ContextSimple(struct asn1_data *data, uint8_t num, DATA_BLOB *blob)
4c3126
-{
4c3126
-	int len;
4c3126
-	ZERO_STRUCTP(blob);
4c3126
-	if (!asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(num))) return false;
4c3126
-	len = asn1_tag_remaining(data);
4c3126
-	if (len < 0) {
4c3126
-		data->has_error = true;
4c3126
-		return false;
4c3126
-	}
4c3126
-	*blob = data_blob(NULL, len);
4c3126
-	if ((len != 0) && (!blob->data)) {
4c3126
-		data->has_error = true;
4c3126
-		return false;
4c3126
-	}
4c3126
-	asn1_read(data, blob->data, len);
4c3126
-	asn1_end_tag(data);
4c3126
-	return !data->has_error;
4c3126
-}
4c3126
-
4c3126
-/* read an integer without tag*/
4c3126
-bool asn1_read_implicit_Integer(struct asn1_data *data, int *i)
4c3126
-{
4c3126
-	uint8_t b;
4c3126
-	*i = 0;
4c3126
-
4c3126
-	while (!data->has_error && asn1_tag_remaining(data)>0) {
4c3126
-		if (!asn1_read_uint8(data, &b)) return false;
4c3126
-		*i = (*i << 8) + b;
4c3126
-	}
4c3126
-	return !data->has_error;	
4c3126
-	
4c3126
-}
4c3126
-
4c3126
-/* read an integer */
4c3126
-bool asn1_read_Integer(struct asn1_data *data, int *i)
4c3126
-{
4c3126
-	*i = 0;
4c3126
-
4c3126
-	if (!asn1_start_tag(data, ASN1_INTEGER)) return false;
4c3126
-	if (!asn1_read_implicit_Integer(data, i)) return false;
4c3126
-	return asn1_end_tag(data);	
4c3126
-}
4c3126
-
4c3126
-/* read a BIT STRING */
4c3126
-bool asn1_read_BitString(struct asn1_data *data, TALLOC_CTX *mem_ctx, DATA_BLOB *blob, uint8_t *padding)
4c3126
-{
4c3126
-	int len;
4c3126
-	ZERO_STRUCTP(blob);
4c3126
-	if (!asn1_start_tag(data, ASN1_BIT_STRING)) return false;
4c3126
-	len = asn1_tag_remaining(data);
4c3126
-	if (len < 0) {
4c3126
-		data->has_error = true;
4c3126
-		return false;
4c3126
-	}
4c3126
-	if (!asn1_read_uint8(data, padding)) return false;
4c3126
-
4c3126
-	*blob = data_blob_talloc(mem_ctx, NULL, len);
4c3126
-	if (!blob->data) {
4c3126
-		data->has_error = true;
4c3126
-		return false;
4c3126
-	}
4c3126
-	if (asn1_read(data, blob->data, len - 1)) {
4c3126
-		blob->length--;
4c3126
-		blob->data[len] = 0;
4c3126
-		asn1_end_tag(data);
4c3126
-	}
4c3126
-
4c3126
-	if (data->has_error) {
4c3126
-		data_blob_free(blob);
4c3126
-		*blob = data_blob_null;
4c3126
-		*padding = 0;
4c3126
-		return false;
4c3126
-	}
4c3126
-	return true;
4c3126
-}
4c3126
-
4c3126
-/* read an integer */
4c3126
-bool asn1_read_enumerated(struct asn1_data *data, int *v)
4c3126
-{
4c3126
-	*v = 0;
4c3126
-	
4c3126
-	if (!asn1_start_tag(data, ASN1_ENUMERATED)) return false;
4c3126
-	while (!data->has_error && asn1_tag_remaining(data)>0) {
4c3126
-		uint8_t b;
4c3126
-		asn1_read_uint8(data, &b);
4c3126
-		*v = (*v << 8) + b;
4c3126
-	}
4c3126
-	return asn1_end_tag(data);	
4c3126
-}
4c3126
-
4c3126
-/* check a enumerated value is correct */
4c3126
-bool asn1_check_enumerated(struct asn1_data *data, int v)
4c3126
-{
4c3126
-	uint8_t b;
4c3126
-	if (!asn1_start_tag(data, ASN1_ENUMERATED)) return false;
4c3126
-	asn1_read_uint8(data, &b);
4c3126
-	asn1_end_tag(data);
4c3126
-
4c3126
-	if (v != b)
4c3126
-		data->has_error = false;
4c3126
-
4c3126
-	return !data->has_error;
4c3126
-}
4c3126
-
4c3126
-/* write an enumerated value to the stream */
4c3126
-bool asn1_write_enumerated(struct asn1_data *data, uint8_t v)
4c3126
-{
4c3126
-	if (!asn1_push_tag(data, ASN1_ENUMERATED)) return false;
4c3126
-	asn1_write_uint8(data, v);
4c3126
-	asn1_pop_tag(data);
4c3126
-	return !data->has_error;
4c3126
-}
4c3126
-
4c3126
-/*
4c3126
-  Get us the data just written without copying
4c3126
-*/
4c3126
-bool asn1_blob(const struct asn1_data *asn1, DATA_BLOB *blob)
4c3126
-{
4c3126
-	if (asn1->has_error) {
4c3126
-		return false;
4c3126
-	}
4c3126
-	if (asn1->nesting != NULL) {
4c3126
-		return false;
4c3126
-	}
4c3126
-	blob->data = asn1->data;
4c3126
-	blob->length = asn1->length;
4c3126
-	return true;
4c3126
-}
4c3126
-
4c3126
-/*
4c3126
-  Fill in an asn1 struct without making a copy
4c3126
-*/
4c3126
-void asn1_load_nocopy(struct asn1_data *data, uint8_t *buf, size_t len)
4c3126
-{
4c3126
-	ZERO_STRUCTP(data);
4c3126
-	data->data = buf;
4c3126
-	data->length = len;
4c3126
-}
4c3126
-
4c3126
diff --git a/asn1.h b/asn1.h
4c3126
index 615041f..a773885 100644
4c3126
--- a/asn1.h
4c3126
+++ b/asn1.h
4c3126
@@ -58,44 +58,7 @@ bool asn1_write(struct asn1_data *data, const void *p, int len);
4c3126
 bool asn1_write_uint8(struct asn1_data *data, uint8_t v);
4c3126
 bool asn1_push_tag(struct asn1_data *data, uint8_t tag);
4c3126
 bool asn1_pop_tag(struct asn1_data *data);
4c3126
-bool asn1_write_implicit_Integer(struct asn1_data *data, int i);
4c3126
-bool asn1_write_Integer(struct asn1_data *data, int i);
4c3126
-bool asn1_write_BitString(struct asn1_data *data, const void *p, size_t length, uint8_t padding);
4c3126
 bool ber_write_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *OID);
4c3126
 bool asn1_write_OID(struct asn1_data *data, const char *OID);
4c3126
 bool asn1_write_OctetString(struct asn1_data *data, const void *p, size_t length);
4c3126
-bool asn1_write_LDAPString(struct asn1_data *data, const char *s);
4c3126
-bool asn1_write_DATA_BLOB_LDAPString(struct asn1_data *data, const DATA_BLOB *s);
4c3126
-bool asn1_write_GeneralString(struct asn1_data *data, const char *s);
4c3126
-bool asn1_write_ContextSimple(struct asn1_data *data, uint8_t num, DATA_BLOB *blob);
4c3126
-bool asn1_write_BOOLEAN(struct asn1_data *data, bool v);
4c3126
-bool asn1_read_BOOLEAN(struct asn1_data *data, bool *v);
4c3126
-bool asn1_check_BOOLEAN(struct asn1_data *data, bool v);
4c3126
-bool asn1_write_BOOLEAN_context(struct asn1_data *data, bool v, int context);
4c3126
-bool asn1_read_BOOLEAN_context(struct asn1_data *data, bool *v, int context);
4c3126
-bool asn1_load(struct asn1_data *data, DATA_BLOB blob);
4c3126
-bool asn1_peek(struct asn1_data *data, void *p, int len);
4c3126
-bool asn1_read(struct asn1_data *data, void *p, int len);
4c3126
-bool asn1_read_uint8(struct asn1_data *data, uint8_t *v);
4c3126
-bool asn1_peek_uint8(struct asn1_data *data, uint8_t *v);
4c3126
-bool asn1_peek_tag(struct asn1_data *data, uint8_t tag);
4c3126
-bool asn1_start_tag(struct asn1_data *data, uint8_t tag);
4c3126
-bool asn1_end_tag(struct asn1_data *data);
4c3126
-int asn1_tag_remaining(struct asn1_data *data);
4c3126
-bool ber_read_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB blob, const char **OID);
4c3126
-bool asn1_read_OID(struct asn1_data *data, TALLOC_CTX *mem_ctx, const char **OID);
4c3126
-bool asn1_check_OID(struct asn1_data *data, const char *OID);
4c3126
-bool asn1_read_LDAPString(struct asn1_data *data, TALLOC_CTX *mem_ctx, char **s);
4c3126
-bool asn1_read_GeneralString(struct asn1_data *data, TALLOC_CTX *mem_ctx, char **s);
4c3126
-bool asn1_read_OctetString(struct asn1_data *data, TALLOC_CTX *mem_ctx, DATA_BLOB *blob);
4c3126
-bool asn1_read_ContextSimple(struct asn1_data *data, uint8_t num, DATA_BLOB *blob);
4c3126
-bool asn1_read_implicit_Integer(struct asn1_data *data, int *i);
4c3126
-bool asn1_read_Integer(struct asn1_data *data, int *i);
4c3126
-bool asn1_read_BitString(struct asn1_data *data, TALLOC_CTX *mem_ctx, DATA_BLOB *blob, uint8_t *padding);
4c3126
-bool asn1_read_enumerated(struct asn1_data *data, int *v);
4c3126
-bool asn1_check_enumerated(struct asn1_data *data, int v);
4c3126
-bool asn1_write_enumerated(struct asn1_data *data, uint8_t v);
4c3126
-bool asn1_blob(const struct asn1_data *asn1, DATA_BLOB *blob);
4c3126
-void asn1_load_nocopy(struct asn1_data *data, uint8_t *buf, size_t len);
4c3126
-
4c3126
 #endif /* _ASN_1_H */
4c3126
-- 
4c3126
1.8.3.1
4c3126