libksba  1.6.0
About: KSBA is a library to make the tasks of working with X.509 certificates, CMS data and related objects more easy.
  Fossies Dox: libksba-1.6.0.tar.bz2  ("unofficial" and yet experimental doxygen-generated source code documentation)  

ber-help.h
Go to the documentation of this file.
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;
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 gpg_error_t _ksba_ber_read_tl (ksba_reader_t reader, struct tag_info *ti);
49 gpg_error_t _ksba_ber_parse_tl (unsigned char const **buffer, size_t *size,
50  struct tag_info *ti);
51 gpg_error_t _ksba_ber_write_tl (ksba_writer_t writer,
52  unsigned long tag,
53  enum tag_class class,
54  int constructed,
55  unsigned long length);
56 size_t _ksba_ber_encode_tl (unsigned char *buffer,
57  unsigned long tag,
58  enum tag_class class,
59  int constructed,
60  unsigned long length);
61 size_t _ksba_ber_count_tl (unsigned long tag,
62  enum tag_class class,
63  int constructed,
64  unsigned long length);
65 
66 
67 static inline void
68 parse_skip (unsigned char const **buf, size_t *len, struct tag_info *ti)
69 {
70  if (ti->length)
71  {
72  assert (ti->length <= *len);
73  *len -= ti->length;
74  *buf += ti->length;
75  }
76 }
77 
78 gpg_error_t _ksba_parse_sequence (unsigned char const **buf, size_t *len,
79  struct tag_info *ti);
80 #define parse_sequence(buf,len,ti) \
81  _ksba_parse_sequence ((buf),(len),(ti))
82 
83 gpg_error_t _ksba_parse_context_tag (unsigned char const **buf, size_t *len,
84  struct tag_info *ti, int tag);
85 #define parse_context_tag(buf,len,ti,tag) \
86  _ksba_parse_context_tag ((buf),(len),(ti),(tag))
87 
88 gpg_error_t _ksba_parse_enumerated (unsigned char const **buf, size_t *len,
89  struct tag_info *ti, size_t maxlen);
90 #define parse_enumerated(buf,len,ti,maxlen) \
91  _ksba_parse_enumerated ((buf),(len),(ti),(maxlen))
92 
93 gpg_error_t _ksba_parse_integer (unsigned char const **buf, size_t *len,
94  struct tag_info *ti);
95 #define parse_integer(buf,len,ti) \
96  _ksba_parse_integer ((buf),(len),(ti))
97 
98 gpg_error_t _ksba_parse_octet_string (unsigned char const **buf, size_t *len,
99  struct tag_info *ti);
100 #define parse_octet_string(buf,len,ti) \
101  _ksba_parse_octet_string ((buf),(len),(ti))
102 
103 gpg_error_t _ksba_parse_optional_boolean (unsigned char const **buf,
104  size_t *len, int *r_bool);
105 #define parse_optional_boolean(buf,len,r_bool) \
106  _ksba_parse_optional_boolean ((buf),(len),(r_bool))
107 
108 gpg_error_t _ksba_parse_optional_null (unsigned char const **buf, size_t *len,
109  int *r_seen);
110 #define parse_optional_null(buf,len,r_seen) \
111  _ksba_parse_optional_null ((buf),(len),(r_seen))
112 
113 gpg_error_t _ksba_parse_object_id_into_str (unsigned char const **buf,
114  size_t *len, char **oid);
115 #define parse_object_id_into_str(buf,len,r_oid) \
116  _ksba_parse_object_id_into_str ((buf),(len),(r_oid))
117 
118 
119 gpg_error_t _ksba_parse_asntime_into_isotime (unsigned char const **buf,
120  size_t *len,
121  ksba_isotime_t isotime);
122 #define parse_asntime_into_isotime(buf,len,isotime) \
123  _ksba_parse_asntime_into_isotime ((buf),(len),(isotime))
124 
125 
126 
127 #endif /*BER_HELP_H*/
tag_class
gpg_error_t _ksba_parse_object_id_into_str(unsigned char const **buf, size_t *len, char **oid)
Definition: ber-help.c:664
gpg_error_t _ksba_ber_write_tl(ksba_writer_t writer, unsigned long tag, enum tag_class class, int constructed, unsigned long length)
Definition: ber-help.c:316
gpg_error_t _ksba_ber_read_tl(ksba_reader_t reader, struct tag_info *ti)
Definition: ber-help.c:93
gpg_error_t _ksba_ber_parse_tl(unsigned char const **buffer, size_t *size, struct tag_info *ti)
Definition: ber-help.c:200
gpg_error_t _ksba_parse_optional_boolean(unsigned char const **buf, size_t *len, int *r_bool)
Definition: ber-help.c:596
gpg_error_t _ksba_parse_enumerated(unsigned char const **buf, size_t *len, struct tag_info *ti, size_t maxlen)
Definition: ber-help.c:527
gpg_error_t _ksba_parse_sequence(unsigned char const **buf, size_t *len, struct tag_info *ti)
Definition: ber-help.c:486
size_t _ksba_ber_encode_tl(unsigned char *buffer, unsigned long tag, enum tag_class class, int constructed, unsigned long length)
Definition: ber-help.c:376
static void parse_skip(unsigned char const **buf, size_t *len, struct tag_info *ti)
Definition: ber-help.h:68
size_t _ksba_ber_count_tl(unsigned long tag, enum tag_class class, int constructed, unsigned long length)
Definition: ber-help.c:434
gpg_error_t _ksba_parse_octet_string(unsigned char const **buf, size_t *len, struct tag_info *ti)
Definition: ber-help.c:571
gpg_error_t _ksba_parse_context_tag(unsigned char const **buf, size_t *len, struct tag_info *ti, int tag)
Definition: ber-help.c:507
gpg_error_t _ksba_parse_optional_null(unsigned char const **buf, size_t *len, int *r_seen)
Definition: ber-help.c:630
gpg_error_t _ksba_parse_integer(unsigned char const **buf, size_t *len, struct tag_info *ti)
Definition: ber-help.c:550
gpg_error_t _ksba_parse_asntime_into_isotime(unsigned char const **buf, size_t *len, ksba_isotime_t isotime)
Definition: ber-help.c:693
const char * oid
Definition: cms.c:71
char ksba_isotime_t[16]
Definition: ksba.h:212
unsigned long tag
Definition: ber-help.h:38
int is_constructed
Definition: ber-help.h:37
unsigned char buf[10]
Definition: ber-help.h:42
const char * err_string
Definition: ber-help.h:43
unsigned long length
Definition: ber-help.h:39
int non_der
Definition: ber-help.h:44
int ndef
Definition: ber-help.h:40
size_t nhdr
Definition: ber-help.h:41