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., 51 Franklin Street, Fifth Floor, Boston,
26 #ifndef NETTLE_ASN1_H_INCLUDED
27 #define NETTLE_ASN1_H_INCLUDED
29 #include "nettle-types.h"
36 #define asn1_der_iterator_first nettle_asn1_der_iterator_first
37 #define asn1_der_iterator_next nettle_asn1_der_iterator_next
38 #define asn1_der_decode_constructed nettle_asn1_der_decode_constructed
39 #define asn1_der_decode_constructed_last nettle_asn1_der_decode_constructed_last
40 #define asn1_der_decode_bitstring nettle_asn1_der_decode_bitstring
41 #define asn1_der_decode_bitstring_last nettle_asn1_der_decode_bitstring_last
42 #define asn1_der_get_uint32 nettle_asn1_der_get_uint32
43 #define asn1_der_get_bignum nettle_asn1_der_get_bignum
46 /* enum asn1_type keeps the class number and the constructive in bits
47 13-14, and the constructive flag in bit 12. The remaining 14 bits
48 are the tag (although currently, only tags in the range 0-30 are
53 ASN1_TYPE_CONSTRUCTED = 1 << 12,
55 ASN1_CLASS_UNIVERSAL = 0,
56 ASN1_CLASS_APPLICATION = 1 << 13,
57 ASN1_CLASS_CONTEXT_SPECIFIC = 2 << 13,
58 ASN1_CLASS_PRIVATE = 3 << 13,
60 ASN1_CLASS_MASK = 3 << 13,
61 ASN1_CLASS_SHIFT = 13,
75 ASN1_SEQUENCE = 16 | ASN1_TYPE_CONSTRUCTED,
76 ASN1_SET = 17 | ASN1_TYPE_CONSTRUCTED,
77 ASN1_PRINTABLESTRING = 19,
78 ASN1_TELETEXSTRING = 20,
81 ASN1_UNIVERSALSTRING = 28,
85 enum asn1_iterator_result
88 ASN1_ITERATOR_PRIMITIVE,
89 ASN1_ITERATOR_CONSTRUCTED,
93 /* Parsing DER objects. */
94 struct asn1_der_iterator
96 unsigned buffer_length;
97 const uint8_t *buffer;
99 /* Next object to parse. */
104 /* Pointer to the current object */
109 /* Initializes the iterator. */
110 enum asn1_iterator_result
111 asn1_der_iterator_first(struct asn1_der_iterator *iterator,
112 unsigned length, const uint8_t *input);
114 enum asn1_iterator_result
115 asn1_der_iterator_next(struct asn1_der_iterator *iterator);
117 /* Starts parsing of a constructed object. */
118 enum asn1_iterator_result
119 asn1_der_decode_constructed(struct asn1_der_iterator *i,
120 struct asn1_der_iterator *contents);
122 /* For the common case that we have a sequence at the end of the
123 object. Checks that the current object is the final one, and then
124 reinitializes the iterator to parse its ontents. */
125 enum asn1_iterator_result
126 asn1_der_decode_constructed_last(struct asn1_der_iterator *i);
128 enum asn1_iterator_result
129 asn1_der_decode_bitstring(struct asn1_der_iterator *i,
130 struct asn1_der_iterator *contents);
132 enum asn1_iterator_result
133 asn1_der_decode_bitstring_last(struct asn1_der_iterator *i);
135 /* All these functions return 1 on success, 0 on failure */
137 asn1_der_get_uint32(struct asn1_der_iterator *i,
144 #endif /* NETTLE_ASN1_H_INCLUDED */