Back to index

lightning-sunbird  0.9+nobinonly
secdert.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Netscape security libraries.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 1994-2000
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 #ifndef _SECDERT_H_
00038 #define _SECDERT_H_
00039 /*
00040  * secdert.h - public data structures for the DER encoding and
00041  *            decoding utilities library
00042  *
00043  * $Id: secdert.h,v 1.2 2004/04/25 15:03:18 gerv%gerv.net Exp $
00044  */
00045 
00046 typedef struct DERTemplateStr DERTemplate;
00047 
00048 /*
00049 ** An array of these structures defines an encoding for an object using DER.
00050 ** The array usually starts with a dummy entry whose kind is DER_SEQUENCE;
00051 ** such an array is terminated with an entry where kind == 0.  (An array
00052 ** which consists of a single component does not require a second dummy
00053 ** entry -- the array is only searched as long as previous component(s)
00054 ** instruct it.)
00055 */
00056 struct DERTemplateStr {
00057     /*
00058     ** Kind of item being decoded/encoded, including tags and modifiers.
00059     */
00060     unsigned long kind;
00061 
00062     /*
00063     ** Offset from base of structure to field that holds the value
00064     ** being decoded/encoded.
00065     */
00066     unsigned int offset;
00067 
00068     /*
00069     ** When kind suggests it (DER_POINTER, DER_INDEFINITE, DER_INLINE),
00070     ** this points to a sub-template for nested encoding/decoding.
00071     */
00072     DERTemplate *sub;
00073 
00074     /*
00075     ** Argument value, dependent on "kind" and/or template placement
00076     ** within an array of templates:
00077     ** - In the first element of a template array, the value is the
00078     **   size of the structure to allocate when this template is being
00079     **   referenced by another template via DER_POINTER or DER_INDEFINITE.
00080     **  - In a component of a DER_SET or DER_SEQUENCE which is *not* a
00081     **   DER_UNIVERSAL type (that is, it has a class tag for either
00082     **   DER_APPLICATION, DER_CONTEXT_SPECIFIC, or DER_PRIVATE), the
00083     **   value is the underlying type of item being decoded/encoded.
00084     */
00085     unsigned long arg;
00086 };
00087 
00088 /************************************************************************/
00089 
00090 /* default chunksize for arenas used for DER stuff */
00091 #define DER_DEFAULT_CHUNKSIZE (2048)
00092 
00093 /*
00094 ** BER/DER values for ASN.1 identifier octets.
00095 */
00096 #define DER_TAG_MASK        0xff
00097 
00098 /*
00099  * BER/DER universal type tag numbers.
00100  * The values are defined by the X.208 standard; do not change them!
00101  * NOTE: if you add anything to this list, you must add code to derdec.c
00102  * to accept the tag, and probably also to derenc.c to encode it.
00103  */
00104 #define DER_TAGNUM_MASK            0x1f
00105 #define DER_BOOLEAN         0x01
00106 #define DER_INTEGER         0x02
00107 #define DER_BIT_STRING             0x03
00108 #define DER_OCTET_STRING    0x04
00109 #define DER_NULL            0x05
00110 #define DER_OBJECT_ID              0x06
00111 #define DER_SEQUENCE        0x10
00112 #define DER_SET                    0x11
00113 #define DER_PRINTABLE_STRING       0x13
00114 #define DER_T61_STRING             0x14
00115 #define DER_IA5_STRING             0x16
00116 #define DER_UTC_TIME        0x17
00117 #define DER_VISIBLE_STRING  0x1a
00118 #define DER_HIGH_TAG_NUMBER 0x1f
00119 
00120 /*
00121 ** Modifiers to type tags.  These are also specified by a/the
00122 ** standard, and must not be changed.
00123 */
00124 
00125 #define DER_METHOD_MASK            0x20
00126 #define DER_PRIMITIVE              0x00
00127 #define DER_CONSTRUCTED            0x20
00128 
00129 #define DER_CLASS_MASK             0xc0
00130 #define DER_UNIVERSAL              0x00
00131 #define DER_APPLICATION            0x40
00132 #define DER_CONTEXT_SPECIFIC       0x80
00133 #define DER_PRIVATE         0xc0
00134 
00135 /*
00136 ** Our additions, used for templates.
00137 ** These are not defined by any standard; the values are used internally only.
00138 ** Just be careful to keep them out of the low 8 bits.
00139 */
00140 #define DER_OPTIONAL        0x00100
00141 #define DER_EXPLICIT        0x00200
00142 #define DER_ANY                    0x00400
00143 #define DER_INLINE          0x00800
00144 #define DER_POINTER         0x01000
00145 #define DER_INDEFINITE             0x02000
00146 #define DER_DERPTR          0x04000
00147 #define DER_SKIP            0x08000
00148 #define DER_FORCE           0x10000
00149 #define DER_OUTER           0x40000 /* for DER_DERPTR */
00150 
00151 /*
00152 ** Macro to convert der decoded bit string into a decoded octet
00153 ** string. All it needs to do is fiddle with the length code.
00154 */
00155 #define DER_ConvertBitString(item)   \
00156 {                                    \
00157     (item)->len = ((item)->len + 7) >> 3; \
00158 }
00159 
00160 extern DERTemplate SECAnyTemplate[];
00161 extern DERTemplate SECBitStringTemplate[];
00162 extern DERTemplate SECBooleanTemplate[];
00163 extern DERTemplate SECIA5StringTemplate[];
00164 extern DERTemplate SECIntegerTemplate[];
00165 extern DERTemplate SECNullTemplate[];
00166 extern DERTemplate SECObjectIDTemplate[];
00167 extern DERTemplate SECOctetStringTemplate[];
00168 extern DERTemplate SECPrintableStringTemplate[];
00169 extern DERTemplate SECT61StringTemplate[];
00170 extern DERTemplate SECUTCTimeTemplate[];
00171 extern DERTemplate SECAlgorithmIDTemplate[];
00172 
00173 #endif /* _SECDERT_H_ */