nettle  3.7.3
About: Nettle is a low-level cryptographic library.
  Fossies Dox: nettle-3.7.3.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

asn1.h
Go to the documentation of this file.
1 /* asn1.h
2 
3  Limited support for ASN.1 DER decoding.
4 
5  Copyright (C) 2005 Niels Möller
6 
7  This file is part of GNU Nettle.
8 
9  GNU Nettle is free software: you can redistribute it and/or
10  modify it under the terms of either:
11 
12  * the GNU Lesser General Public License as published by the Free
13  Software Foundation; either version 3 of the License, or (at your
14  option) any later version.
15 
16  or
17 
18  * the GNU General Public License as published by the Free
19  Software Foundation; either version 2 of the License, or (at your
20  option) any later version.
21 
22  or both in parallel, as here.
23 
24  GNU Nettle is distributed in the hope that it will be useful,
25  but WITHOUT ANY WARRANTY; without even the implied warranty of
26  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27  General Public License for more details.
28 
29  You should have received copies of the GNU General Public License and
30  the GNU Lesser General Public License along with this program. If
31  not, see http://www.gnu.org/licenses/.
32 */
33 
34 #ifndef NETTLE_ASN1_H_INCLUDED
35 #define NETTLE_ASN1_H_INCLUDED
36 
37 #include "nettle-types.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 /* Name mangling */
44 #define asn1_der_iterator_first nettle_asn1_der_iterator_first
45 #define asn1_der_iterator_next nettle_asn1_der_iterator_next
46 #define asn1_der_decode_constructed nettle_asn1_der_decode_constructed
47 #define asn1_der_decode_constructed_last nettle_asn1_der_decode_constructed_last
48 #define asn1_der_decode_bitstring nettle_asn1_der_decode_bitstring
49 #define asn1_der_decode_bitstring_last nettle_asn1_der_decode_bitstring_last
50 #define asn1_der_get_uint32 nettle_asn1_der_get_uint32
51 #define asn1_der_get_bignum nettle_asn1_der_get_bignum
52 
53 
54 /* enum asn1_type keeps the class number and the constructive in bits
55  13-14, and the constructive flag in bit 12. The remaining 14 bits
56  are the tag (although currently, only tags in the range 0-30 are
57  supported). */
58 
59 enum
60  {
62 
66  ASN1_CLASS_PRIVATE = 3 << 13,
67 
68  ASN1_CLASS_MASK = 3 << 13,
70  };
71 
73  {
78  ASN1_NULL = 5,
80  ASN1_REAL = 9,
88  ASN1_UTC = 23,
91  };
92 
94  {
99  };
100 
101 /* Parsing DER objects. */
103 {
105  const uint8_t *buffer;
106 
107  /* Next object to parse. */
108  size_t pos;
109 
110  enum asn1_type type;
111 
112  /* Pointer to the current object */
113  size_t length;
114  const uint8_t *data;
115 };
116 
117 /* Initializes the iterator. */
120  size_t length, const uint8_t *input);
121 
123 asn1_der_iterator_next(struct asn1_der_iterator *iterator);
124 
125 /* Starts parsing of a constructed object. */
128  struct asn1_der_iterator *contents);
129 
130 /* For the common case that we have a sequence at the end of the
131  object. Checks that the current object is the final one, and then
132  reinitializes the iterator to parse its ontents. */
135 
138  struct asn1_der_iterator *contents);
139 
142 
143 /* All these functions return 1 on success, 0 on failure */
144 int
146  uint32_t *x);
147 
148 #ifdef __cplusplus
149 }
150 #endif
151 
152 #endif /* NETTLE_ASN1_H_INCLUDED */
#define asn1_der_iterator_first
Definition: asn1.h:44
#define asn1_der_decode_constructed_last
Definition: asn1.h:47
#define asn1_der_decode_bitstring_last
Definition: asn1.h:49
#define asn1_der_get_uint32
Definition: asn1.h:50
#define asn1_der_decode_constructed
Definition: asn1.h:46
asn1_type
Definition: asn1.h:73
@ ASN1_UNIVERSALSTRING
Definition: asn1.h:89
@ ASN1_PRINTABLESTRING
Definition: asn1.h:85
@ ASN1_SEQUENCE
Definition: asn1.h:83
@ ASN1_ENUMERATED
Definition: asn1.h:81
@ ASN1_UTF8STRING
Definition: asn1.h:82
@ ASN1_UTC
Definition: asn1.h:88
@ ASN1_IDENTIFIER
Definition: asn1.h:79
@ ASN1_BITSTRING
Definition: asn1.h:76
@ ASN1_TELETEXSTRING
Definition: asn1.h:86
@ ASN1_NULL
Definition: asn1.h:78
@ ASN1_INTEGER
Definition: asn1.h:75
@ ASN1_OCTETSTRING
Definition: asn1.h:77
@ ASN1_REAL
Definition: asn1.h:80
@ ASN1_IA5STRING
Definition: asn1.h:87
@ ASN1_SET
Definition: asn1.h:84
@ ASN1_BMPSTRING
Definition: asn1.h:90
@ ASN1_BOOLEAN
Definition: asn1.h:74
#define asn1_der_iterator_next
Definition: asn1.h:45
asn1_iterator_result
Definition: asn1.h:94
@ ASN1_ITERATOR_ERROR
Definition: asn1.h:95
@ ASN1_ITERATOR_END
Definition: asn1.h:98
@ ASN1_ITERATOR_PRIMITIVE
Definition: asn1.h:96
@ ASN1_ITERATOR_CONSTRUCTED
Definition: asn1.h:97
@ ASN1_CLASS_UNIVERSAL
Definition: asn1.h:63
@ ASN1_CLASS_APPLICATION
Definition: asn1.h:64
@ ASN1_CLASS_SHIFT
Definition: asn1.h:69
@ ASN1_CLASS_PRIVATE
Definition: asn1.h:66
@ ASN1_TYPE_CONSTRUCTED
Definition: asn1.h:61
@ ASN1_CLASS_MASK
Definition: asn1.h:68
@ ASN1_CLASS_CONTEXT_SPECIFIC
Definition: asn1.h:65
#define asn1_der_decode_bitstring
Definition: asn1.h:48
#define x
#define i
size_t length
Definition: asn1.h:113
enum asn1_type type
Definition: asn1.h:110
const uint8_t * data
Definition: asn1.h:114
size_t buffer_length
Definition: asn1.h:104
const uint8_t * buffer
Definition: asn1.h:105
size_t pos
Definition: asn1.h:108