added asn1 functions for handling booleans in a simple context
authorAndrew Tridgell <tridge@samba.org>
Wed, 10 Jun 2009 01:44:47 +0000 (11:44 +1000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 10 Jun 2009 01:45:53 +0000 (11:45 +1000)
lib/util/asn1.c
lib/util/asn1.h

index c687f8dc9a1d43ff0e0fec51dc385719f2cf4314..aadaf8643a04d31376ca5f7013fedca881fdb23e 100644 (file)
@@ -332,6 +332,29 @@ bool asn1_read_BOOLEAN(struct asn1_data *data, bool *v)
        return !data->has_error;
 }
 
+/* write a BOOLEAN in a simple context */
+bool asn1_write_BOOLEAN_context(struct asn1_data *data, bool v, int context)
+{
+       asn1_push_tag(data, ASN1_CONTEXT_SIMPLE(context));
+       asn1_write_uint8(data, v ? 0xFF : 0);
+       asn1_pop_tag(data);
+       return !data->has_error;
+}
+
+bool asn1_read_BOOLEAN_context(struct asn1_data *data, bool *v, int context)
+{
+       uint8_t tmp = 0;
+       asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(context));
+       asn1_read_uint8(data, &tmp);
+       if (tmp == 0xFF) {
+               *v = true;
+       } else {
+               *v = false;
+       }
+       asn1_end_tag(data);
+       return !data->has_error;
+}
+
 /* check a BOOLEAN */
 bool asn1_check_BOOLEAN(struct asn1_data *data, bool v)
 {
index 8ecb85cb81298c97e48c2fb9ebfcd4ac1d46ac00..0f41ae33e57a5dcaf3441e36c1126eab890d9d39 100644 (file)
@@ -70,6 +70,8 @@ bool asn1_write_ContextSimple(struct asn1_data *data, uint8_t num, DATA_BLOB *bl
 bool asn1_write_BOOLEAN(struct asn1_data *data, bool v);
 bool asn1_read_BOOLEAN(struct asn1_data *data, bool *v);
 bool asn1_check_BOOLEAN(struct asn1_data *data, bool v);
+bool asn1_write_BOOLEAN_context(struct asn1_data *data, bool v, int context);
+bool asn1_read_BOOLEAN_context(struct asn1_data *data, bool *v, int context);
 bool asn1_load(struct asn1_data *data, DATA_BLOB blob);
 bool asn1_peek(struct asn1_data *data, void *p, int len);
 bool asn1_read(struct asn1_data *data, void *p, int len);