summaryrefslogtreecommitdiff
path: root/lib/util/asn1.c
diff options
context:
space:
mode:
authorKouhei Sutou <kou@clear-code.com>2009-08-13 15:12:01 +0900
committerGünther Deschner <gd@samba.org>2009-09-17 20:10:54 +0200
commitf8dae40fc8e40f747a4571a2500bba9f1a790fa5 (patch)
tree778ee30d1a61903a9a4abe617777be6a48dfc3fa /lib/util/asn1.c
parentc2055de162b154efb1aef0d2977f860a01ffdbbc (diff)
downloadsamba-f8dae40fc8e40f747a4571a2500bba9f1a790fa5.tar.gz
samba-f8dae40fc8e40f747a4571a2500bba9f1a790fa5.tar.bz2
samba-f8dae40fc8e40f747a4571a2500bba9f1a790fa5.zip
spnego: Support ASN.1 BIT STRING and use it in SPNEGO.
Signed-off-by: Günther Deschner <gd@samba.org>
Diffstat (limited to 'lib/util/asn1.c')
-rw-r--r--lib/util/asn1.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/util/asn1.c b/lib/util/asn1.c
index 317ee1314c..70c2c57450 100644
--- a/lib/util/asn1.c
+++ b/lib/util/asn1.c
@@ -205,6 +205,15 @@ bool asn1_write_Integer(struct asn1_data *data, int i)
return asn1_pop_tag(data);
}
+/* write a BIT STRING */
+bool asn1_write_BitString(struct asn1_data *data, const void *p, size_t length, uint8_t padding)
+{
+ if (!asn1_push_tag(data, ASN1_BIT_STRING)) return false;
+ if (!asn1_write_uint8(data, padding)) return false;
+ if (!asn1_write(data, p, length)) return false;
+ return asn1_pop_tag(data);
+}
+
bool ber_write_OID_String(DATA_BLOB *blob, const char *OID)
{
uint_t v, v2;
@@ -727,6 +736,39 @@ bool asn1_read_Integer(struct asn1_data *data, int *i)
return asn1_end_tag(data);
}
+/* read a BIT STRING */
+bool asn1_read_BitString(struct asn1_data *data, TALLOC_CTX *mem_ctx, DATA_BLOB *blob, uint8_t *padding)
+{
+ int len;
+ ZERO_STRUCTP(blob);
+ if (!asn1_start_tag(data, ASN1_BIT_STRING)) return false;
+ len = asn1_tag_remaining(data);
+ if (len < 0) {
+ data->has_error = true;
+ return false;
+ }
+ if (!asn1_read_uint8(data, padding)) return false;
+
+ *blob = data_blob_talloc(mem_ctx, NULL, len);
+ if (!blob->data) {
+ data->has_error = true;
+ return false;
+ }
+ if (asn1_read(data, blob->data, len - 1)) {
+ blob->length--;
+ blob->data[len] = 0;
+ asn1_end_tag(data);
+ }
+
+ if (data->has_error) {
+ data_blob_free(blob);
+ *blob = data_blob_null;
+ *padding = 0;
+ return false;
+ }
+ return true;
+}
+
/* read an integer */
bool asn1_read_enumerated(struct asn1_data *data, int *v)
{