]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
ASN.1: Add a helper for parsing SEQUENCE
authorJouni Malinen <jouni@codeaurora.org>
Thu, 30 Jan 2020 10:11:51 +0000 (12:11 +0200)
committerJouni Malinen <j@w1.fi>
Thu, 30 Jan 2020 10:12:26 +0000 (12:12 +0200)
Signed-off-by: Jouni Malinen <jouni@codeaurora.org>
src/tls/asn1.c
src/tls/asn1.h

index 06bbd6f939c80280ee5ac59f565620a16a72842a..13b7fe1a5ae255fed1b4191a87c1eb95f4adc427 100644 (file)
@@ -307,3 +307,21 @@ int asn1_get_integer(const u8 *buf, size_t len, int *integer, const u8 **next)
        *integer = value;
        return 0;
 }
        *integer = value;
        return 0;
 }
+
+
+int asn1_get_sequence(const u8 *buf, size_t len, struct asn1_hdr *hdr,
+                     const u8 **next)
+{
+       if (asn1_get_next(buf, len, hdr) < 0 ||
+           hdr->class != ASN1_CLASS_UNIVERSAL ||
+           hdr->tag != ASN1_TAG_SEQUENCE) {
+               wpa_printf(MSG_DEBUG,
+                          "ASN.1: Expected SEQUENCE - found class %d tag 0x%x",
+                          hdr->class, hdr->tag);
+               return -1;
+       }
+
+       if (next)
+               *next = hdr->payload + hdr->length;
+       return 0;
+}
index 45b981260ca808c5c3af76f9e8c5c8c4b1d21f94..d769a4e9bb48df7ceec84a5e11af760f12df71c4 100644 (file)
@@ -66,6 +66,8 @@ void asn1_oid_to_str(const struct asn1_oid *oid, char *buf, size_t len);
 unsigned long asn1_bit_string_to_long(const u8 *buf, size_t len);
 int asn1_oid_equal(const struct asn1_oid *a, const struct asn1_oid *b);
 int asn1_get_integer(const u8 *buf, size_t len, int *integer, const u8 **next);
 unsigned long asn1_bit_string_to_long(const u8 *buf, size_t len);
 int asn1_oid_equal(const struct asn1_oid *a, const struct asn1_oid *b);
 int asn1_get_integer(const u8 *buf, size_t len, int *integer, const u8 **next);
+int asn1_get_sequence(const u8 *buf, size_t len, struct asn1_hdr *hdr,
+                     const u8 **next);
 
 extern struct asn1_oid asn1_sha1_oid;
 extern struct asn1_oid asn1_sha256_oid;
 
 extern struct asn1_oid asn1_sha1_oid;
 extern struct asn1_oid asn1_sha256_oid;