1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is the Netscape security libraries.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
19 * the Initial Developer. All Rights Reserved.
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
35 * ***** END LICENSE BLOCK ***** */
40 * secdert.h - public data structures for the DER encoding and
41 * decoding utilities library
43 * $Id: secdert.h,v 1.5 2007/10/12 01:44:51 julien.pierre.boogz%sun.com Exp $
46 #include "utilrename.h"
49 typedef struct DERTemplateStr DERTemplate;
52 ** An array of these structures defines an encoding for an object using DER.
53 ** The array usually starts with a dummy entry whose kind is DER_SEQUENCE;
54 ** such an array is terminated with an entry where kind == 0. (An array
55 ** which consists of a single component does not require a second dummy
56 ** entry -- the array is only searched as long as previous component(s)
59 struct DERTemplateStr {
61 ** Kind of item being decoded/encoded, including tags and modifiers.
66 ** Offset from base of structure to field that holds the value
67 ** being decoded/encoded.
72 ** When kind suggests it (DER_POINTER, DER_INDEFINITE, DER_INLINE),
73 ** this points to a sub-template for nested encoding/decoding.
78 ** Argument value, dependent on "kind" and/or template placement
79 ** within an array of templates:
80 ** - In the first element of a template array, the value is the
81 ** size of the structure to allocate when this template is being
82 ** referenced by another template via DER_POINTER or DER_INDEFINITE.
83 ** - In a component of a DER_SET or DER_SEQUENCE which is *not* a
84 ** DER_UNIVERSAL type (that is, it has a class tag for either
85 ** DER_APPLICATION, DER_CONTEXT_SPECIFIC, or DER_PRIVATE), the
86 ** value is the underlying type of item being decoded/encoded.
91 /************************************************************************/
93 /* default chunksize for arenas used for DER stuff */
94 #define DER_DEFAULT_CHUNKSIZE (2048)
97 ** BER/DER values for ASN.1 identifier octets.
99 #define DER_TAG_MASK 0xff
102 * BER/DER universal type tag numbers.
103 * The values are defined by the X.208 standard; do not change them!
104 * NOTE: if you add anything to this list, you must add code to derdec.c
105 * to accept the tag, and probably also to derenc.c to encode it.
107 #define DER_TAGNUM_MASK 0x1f
108 #define DER_BOOLEAN 0x01
109 #define DER_INTEGER 0x02
110 #define DER_BIT_STRING 0x03
111 #define DER_OCTET_STRING 0x04
112 #define DER_NULL 0x05
113 #define DER_OBJECT_ID 0x06
114 #define DER_SEQUENCE 0x10
116 #define DER_PRINTABLE_STRING 0x13
117 #define DER_T61_STRING 0x14
118 #define DER_IA5_STRING 0x16
119 #define DER_UTC_TIME 0x17
120 #define DER_VISIBLE_STRING 0x1a
121 #define DER_HIGH_TAG_NUMBER 0x1f
124 ** Modifiers to type tags. These are also specified by a/the
125 ** standard, and must not be changed.
128 #define DER_METHOD_MASK 0x20
129 #define DER_PRIMITIVE 0x00
130 #define DER_CONSTRUCTED 0x20
132 #define DER_CLASS_MASK 0xc0
133 #define DER_UNIVERSAL 0x00
134 #define DER_APPLICATION 0x40
135 #define DER_CONTEXT_SPECIFIC 0x80
136 #define DER_PRIVATE 0xc0
139 ** Our additions, used for templates.
140 ** These are not defined by any standard; the values are used internally only.
141 ** Just be careful to keep them out of the low 8 bits.
143 #define DER_OPTIONAL 0x00100
144 #define DER_EXPLICIT 0x00200
145 #define DER_ANY 0x00400
146 #define DER_INLINE 0x00800
147 #define DER_POINTER 0x01000
148 #define DER_INDEFINITE 0x02000
149 #define DER_DERPTR 0x04000
150 #define DER_SKIP 0x08000
151 #define DER_FORCE 0x10000
152 #define DER_OUTER 0x40000 /* for DER_DERPTR */
155 ** Macro to convert der decoded bit string into a decoded octet
156 ** string. All it needs to do is fiddle with the length code.
158 #define DER_ConvertBitString(item) \
160 (item)->len = ((item)->len + 7) >> 3; \
163 #endif /* _SECDERT_H_ */