3 * Some very limited asn.1 support.
6 /* nettle, low-level cryptographics library
8 * Copyright (C) 2005 Niels Möller
10 * The nettle library is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or (at your
13 * option) any later version.
15 * The nettle library is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with the nettle library; see the file COPYING.LIB. If not, write to
22 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
26 #ifndef NETTLE_ASN1_H_INCLUDED
27 #define NETTLE_ASN1_H_INCLUDED
29 #include "nettle-types.h"
31 /* enum asn1_type keeps the class number and the constructive in bits
32 13-14, and the constructive flag in bit 12. The remaining 14 bits
33 are the tag (although currently, only tags in the range 0-30 are
38 ASN1_TYPE_CONSTRUCTED = 1 << 12,
40 ASN1_CLASS_UNIVERSAL = 0,
41 ASN1_CLASS_APPLICATION = 1 << 13,
42 ASN1_CLASS_CONTEXT_SPECIFIC = 2 << 13,
43 ASN1_CLASS_PRIVATE = 3 << 13,
45 ASN1_CLASS_MASK = 3 << 13,
46 ASN1_CLASS_SHIFT = 13,
60 ASN1_SEQUENCE = 16 | ASN1_TYPE_CONSTRUCTED,
61 ASN1_SET = 17 | ASN1_TYPE_CONSTRUCTED,
62 ASN1_PRINTABLESTRING = 19,
63 ASN1_TELETEXSTRING = 20,
66 ASN1_UNIVERSALSTRING = 28,
70 enum asn1_iterator_result
73 ASN1_ITERATOR_PRIMITIVE,
74 ASN1_ITERATOR_CONSTRUCTED,
78 /* Parsing DER objects. */
79 struct asn1_der_iterator
81 unsigned buffer_length;
82 const uint8_t *buffer;
84 /* Next object to parse. */
89 /* Pointer to the current object */
94 /* Initializes the iterator. */
95 enum asn1_iterator_result
96 asn1_der_iterator_first(struct asn1_der_iterator *iterator,
97 unsigned length, const uint8_t *input);
99 enum asn1_iterator_result
100 asn1_der_iterator_next(struct asn1_der_iterator *iterator);
102 /* Starts parsing of a constructed object. */
103 enum asn1_iterator_result
104 asn1_der_decode_constructed(struct asn1_der_iterator *i,
105 struct asn1_der_iterator *contents);
107 /* All these functions return 1 on success, 0 on failure */
109 asn1_der_get_uint32(struct asn1_der_iterator *i,
112 #endif /* NETTLE_ASN1_H_INCLUDED */