Debian Codegraph @

src/ber-help.h

raw
1 /* ber-help.h - Basic Encoding Rules helpers
2 * Copyright (C) 2001, 2012 g10 Code GmbH
3 *
4 * This file is part of KSBA.
5 *
6 * KSBA is free software; you can redistribute it and/or modify
7 * it under the terms of either
8 *
9 * - the GNU Lesser General Public License as published by the Free
10 * Software Foundation; either version 3 of the License, or (at
11 * your option) any later version.
12 *
13 * or
14 *
15 * - the GNU General Public License as published by the Free
16 * Software Foundation; either version 2 of the License, or (at
17 * your option) any later version.
18 *
19 * or both in parallel, as here.
20 *
21 * KSBA is distributed in the hope that it will be useful, but WITHOUT
22 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
24 * License for more details.
25 *
26 * You should have received a copies of the GNU General Public License
27 * and the GNU Lesser General Public License along with this program;
28 * if not, see <http://www.gnu.org/licenses/>.
29 */
30
31 #ifndef BER_HELP_H
32 #define BER_HELP_H 1
33
34
35 struct tag_info {
36 enum tag_class class;
37 int is_constructed;
38 unsigned long tag;
39 unsigned long length; /* length part of the TLV */
40 int ndef; /* It is an indefinite length */
41 size_t nhdr; /* number of bytes in the TL */
42 unsigned char buf[10]; /* buffer for the TL */
43 const char *err_string;
44 int non_der;
45 };
46
47
48 /* Maximum length of certain object to avoid excessive memory
49 * allocation. Make sure that they are below 2^31. */
50 #define MAX_SERIALNO_LENGTH (1 * 1024)
51 #define MAX_KEYID_DER_LENGTH (4 * 1024)
52 #define MAX_CERT_EXT_LENGTH (2 * 1024*1024)
53 #define MAX_CRL_NUMBER_LENGTH (256)
54 #define MAX_NAME_URL_LENGTH (4 * 1024)
55
56
57 gpg_error_t _ksba_ber_read_tl (ksba_reader_t reader, struct tag_info *ti);
58 gpg_error_t _ksba_ber_parse_tl (unsigned char const **buffer, size_t *size,
59 struct tag_info *ti);
60 gpg_error_t _ksba_ber_write_tl (ksba_writer_t writer,
61 unsigned long tag,
62 enum tag_class class,
63 int constructed,
64 unsigned long length);
65 size_t _ksba_ber_encode_tl (unsigned char *buffer,
66 unsigned long tag,
67 enum tag_class class,
68 int constructed,
69 unsigned long length);
70 size_t _ksba_ber_count_tl (unsigned long tag,
71 enum tag_class class,
72 int constructed,
73 unsigned long length);
74
75
76 static inline void
77 parse_skip (unsigned char const **buf, size_t *len, struct tag_info *ti)
78 {
79 if (ti->length)
80 {
81 assert (ti->length <= *len);
82 *len -= ti->length;
83 *buf += ti->length;
84 }
85 }
86
87 gpg_error_t _ksba_parse_sequence (unsigned char const **buf, size_t *len,
88 struct tag_info *ti);
89 #define parse_sequence(buf,len,ti) \
90 _ksba_parse_sequence ((buf),(len),(ti))
91
92 gpg_error_t _ksba_parse_context_tag (unsigned char const **buf, size_t *len,
93 struct tag_info *ti, int tag);
94 #define parse_context_tag(buf,len,ti,tag) \
95 _ksba_parse_context_tag ((buf),(len),(ti),(tag))
96
97 gpg_error_t _ksba_parse_enumerated (unsigned char const **buf, size_t *len,
98 struct tag_info *ti, size_t maxlen);
99 #define parse_enumerated(buf,len,ti,maxlen) \
100 _ksba_parse_enumerated ((buf),(len),(ti),(maxlen))
101
102 gpg_error_t _ksba_parse_integer (unsigned char const **buf, size_t *len,
103 struct tag_info *ti);
104 #define parse_integer(buf,len,ti) \
105 _ksba_parse_integer ((buf),(len),(ti))
106
107 gpg_error_t _ksba_parse_octet_string (unsigned char const **buf, size_t *len,
108 struct tag_info *ti);
109 #define parse_octet_string(buf,len,ti) \
110 _ksba_parse_octet_string ((buf),(len),(ti))
111
112 gpg_error_t _ksba_parse_optional_boolean (unsigned char const **buf,
113 size_t *len, int *r_bool);
114 #define parse_optional_boolean(buf,len,r_bool) \
115 _ksba_parse_optional_boolean ((buf),(len),(r_bool))
116
117 gpg_error_t _ksba_parse_optional_null (unsigned char const **buf, size_t *len,
118 int *r_seen);
119 #define parse_optional_null(buf,len,r_seen) \
120 _ksba_parse_optional_null ((buf),(len),(r_seen))
121
122 gpg_error_t _ksba_parse_object_id_into_str (unsigned char const **buf,
123 size_t *len, char **oid);
124 #define parse_object_id_into_str(buf,len,r_oid) \
125 _ksba_parse_object_id_into_str ((buf),(len),(r_oid))
126
127
128 gpg_error_t _ksba_parse_asntime_into_isotime (unsigned char const **buf,
129 size_t *len,
130 ksba_isotime_t isotime);
131 #define parse_asntime_into_isotime(buf,len,isotime) \
132 _ksba_parse_asntime_into_isotime ((buf),(len),(isotime))
133
134
135
136 #endif /*BER_HELP_H*/