Added SILC Thread Queue API
[silc.git] / lib / silcasn1 / silcber.h
1 /*
2
3   silcber.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2003 - 2007 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 /****h* silcasn1/BER Interface
21  *
22  * DESCRIPTION
23  *
24  * The Basic Encoding Rules (BER) is the data encoding format for the
25  * ASN.1.  This interface provides routines for encoding and decoding
26  * arbitraty BER data blocks.  Naturally, this interface can be used
27  * to encode and decode DER blocks as well.  These routines does not
28  * allocate any memory and have been optimized for general ASN.1 usage.
29  *
30  * References: ITU-T X.690
31  * http://www.itu.int/ITU-T/studygroups/com17/languages/X690_0702.pdf
32  *
33  ***/
34
35 #ifndef SILCBER_H
36 #define SILCBER_H
37
38 /****d* silcasn1/SilcBerAPI/SilcBerClass
39  *
40  * NAME
41  *
42  *    typedef enum { ... } SilcBerClass;
43  *
44  * DESCRIPTION
45  *
46  *    Defines the BER classes.
47  *
48  ***/
49 typedef enum {
50   SILC_BER_CLASS_UNIVERSAL       = 0x00,   /* Universal */
51   SILC_BER_CLASS_APPLICATION     = 0x01,   /* Application */
52   SILC_BER_CLASS_CONTEXT         = 0x02,   /* Context-specific */
53   SILC_BER_CLASS_PRIVATE         = 0x03,   /* Private */
54 } SilcBerClass;
55 /***/
56
57 /****d* silcasn1/SilcBerAPI/SilcBerEncoding
58  *
59  * NAME
60  *
61  *    typedef enum { ... } SilcBerEncoding;
62  *
63  * DESCRIPTION
64  *
65  *    Defines the BER encoding type.
66  *
67  ***/
68 typedef enum {
69   SILC_BER_ENC_PRIMITIVE         = 0x00,
70   SILC_BER_ENC_CONSTRUCTED       = 0x01,
71 } SilcBerEncoding;
72 /***/
73
74 /****f* silcasn1/SilcBerAPI/silc_ber_encode
75  *
76  * SYNOPSIS
77  *
78  *    SilcBool
79  *    silc_ber_encode(SilcBuffer ber, SilcBerClass ber_class,
80  *                    SilcBerEncoding encoding, SilcUInt32 tag,
81  *                    const unsigned char *data, SilcUInt32 data_len,
82  *                    SilcBool indefinite);
83  *
84  * DESCRIPTION
85  *
86  *    Encodes a BER data block into the `ber', which must already have
87  *    sufficient space allocated.  Caller can use silc_ber_encoded_len
88  *    function to determine how much to allocate space before calling this
89  *    function.  If the `indefinite' is TRUE then the BER block will not
90  *    include the length of the data in the BER block.
91  *
92  ***/
93 SilcBool silc_ber_encode(SilcBuffer ber, SilcBerClass ber_class,
94                          SilcBerEncoding encoding, SilcUInt32 tag,
95                          const unsigned char *data, SilcUInt32 data_len,
96                          SilcBool indefinite);
97
98 /****f* silcasn1/SilcBerAPI/silc_ber_decode
99  *
100  * SYNOPSIS
101  *
102  *    SilcBool
103  *    silc_ber_decode(SilcBuffer ber, SilcBerClass *ber_class,
104  *                    SilcBerEncoding *encoding, SilcUInt32 *tag,
105  *                    const unsigned char **data, SilcUInt32 *data_len,
106  *                    SilcBool *indefinite, SilcUInt32 *identifier_len);
107  *
108  * DESCRIPTION
109  *
110  *    Decodesa a BER data from the buffer `ber'.  Returns the class,
111  *    encoding and the tag number for the BER data into `ber_class',
112  *    `encoding' and `tag'.  A pointer to the start of the data area is
113  *    returned into `data'.  If the length of the data is available from
114  *    the BER data the length is returned into `data_len'.  If the
115  *    `indefinite' is TRUE then the length found in `data_len' was found
116  *    by finding end-of-contents octets from the BER data.  The
117  *    `identifier_len' is the length of the BER header, and the length
118  *    of the entire BER object is `identifier_len' + `data_len'.
119  *
120  ***/
121 SilcBool silc_ber_decode(SilcBuffer ber, SilcBerClass *ber_class,
122                          SilcBerEncoding *encoding, SilcUInt32 *tag,
123                          const unsigned char **data, SilcUInt32 *data_len,
124                          SilcBool *indefinite, SilcUInt32 *identifier_len);
125
126 /****f* silcasn1/SilcBerAPI/silc_ber_encoded_len
127  *
128  * SYNOPSIS
129  *
130  *    SilcUInt32 silc_ber_encoded_len(SilcUInt32 tag, SilcUInt32 data_len,
131  *                                    SilcBool indefinite);
132  *
133  * DESCRIPTION
134  *
135  *    Calculates the length of the encoded BER data object.  This utility
136  *    function can be used to calculate how much to allocate space before
137  *    encoding with silc_ber_encode.
138  *
139  ***/
140 SilcUInt32 silc_ber_encoded_len(SilcUInt32 tag, SilcUInt32 data_len,
141                                 SilcBool indefinite);
142
143 #endif /* SILCBER_H */