andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: andre@0: #ifndef _SECDERT_H_ andre@0: #define _SECDERT_H_ andre@0: /* andre@0: * secdert.h - public data structures for the DER encoding and andre@0: * decoding utilities library andre@0: */ andre@0: andre@0: #include "utilrename.h" andre@0: #include "seccomon.h" andre@0: andre@0: typedef struct DERTemplateStr DERTemplate; andre@0: andre@0: /* andre@0: ** An array of these structures defines an encoding for an object using DER. andre@0: ** The array usually starts with a dummy entry whose kind is DER_SEQUENCE; andre@0: ** such an array is terminated with an entry where kind == 0. (An array andre@0: ** which consists of a single component does not require a second dummy andre@0: ** entry -- the array is only searched as long as previous component(s) andre@0: ** instruct it.) andre@0: */ andre@0: struct DERTemplateStr { andre@0: /* andre@0: ** Kind of item being decoded/encoded, including tags and modifiers. andre@0: */ andre@0: unsigned long kind; andre@0: andre@0: /* andre@0: ** Offset from base of structure to field that holds the value andre@0: ** being decoded/encoded. andre@0: */ andre@0: unsigned int offset; andre@0: andre@0: /* andre@0: ** When kind suggests it (DER_POINTER, DER_INDEFINITE, DER_INLINE), andre@0: ** this points to a sub-template for nested encoding/decoding. andre@0: */ andre@0: DERTemplate *sub; andre@0: andre@0: /* andre@0: ** Argument value, dependent on "kind" and/or template placement andre@0: ** within an array of templates: andre@0: ** - In the first element of a template array, the value is the andre@0: ** size of the structure to allocate when this template is being andre@0: ** referenced by another template via DER_POINTER or DER_INDEFINITE. andre@0: ** - In a component of a DER_SET or DER_SEQUENCE which is *not* a andre@0: ** DER_UNIVERSAL type (that is, it has a class tag for either andre@0: ** DER_APPLICATION, DER_CONTEXT_SPECIFIC, or DER_PRIVATE), the andre@0: ** value is the underlying type of item being decoded/encoded. andre@0: */ andre@0: unsigned long arg; andre@0: }; andre@0: andre@0: /************************************************************************/ andre@0: andre@0: /* default chunksize for arenas used for DER stuff */ andre@0: #define DER_DEFAULT_CHUNKSIZE (2048) andre@0: andre@0: /* andre@0: ** BER/DER values for ASN.1 identifier octets. andre@0: */ andre@0: #define DER_TAG_MASK 0xff andre@0: andre@0: /* andre@0: * BER/DER universal type tag numbers. andre@0: * The values are defined by the X.208 standard; do not change them! andre@0: * NOTE: if you add anything to this list, you must add code to derdec.c andre@0: * to accept the tag, and probably also to derenc.c to encode it. andre@0: */ andre@0: #define DER_TAGNUM_MASK 0x1f andre@0: #define DER_BOOLEAN 0x01 andre@0: #define DER_INTEGER 0x02 andre@0: #define DER_BIT_STRING 0x03 andre@0: #define DER_OCTET_STRING 0x04 andre@0: #define DER_NULL 0x05 andre@0: #define DER_OBJECT_ID 0x06 andre@0: #define DER_SEQUENCE 0x10 andre@0: #define DER_SET 0x11 andre@0: #define DER_PRINTABLE_STRING 0x13 andre@0: #define DER_T61_STRING 0x14 andre@0: #define DER_IA5_STRING 0x16 andre@0: #define DER_UTC_TIME 0x17 andre@0: #define DER_VISIBLE_STRING 0x1a andre@0: #define DER_HIGH_TAG_NUMBER 0x1f andre@0: andre@0: /* andre@0: ** Modifiers to type tags. These are also specified by a/the andre@0: ** standard, and must not be changed. andre@0: */ andre@0: andre@0: #define DER_METHOD_MASK 0x20 andre@0: #define DER_PRIMITIVE 0x00 andre@0: #define DER_CONSTRUCTED 0x20 andre@0: andre@0: #define DER_CLASS_MASK 0xc0 andre@0: #define DER_UNIVERSAL 0x00 andre@0: #define DER_APPLICATION 0x40 andre@0: #define DER_CONTEXT_SPECIFIC 0x80 andre@0: #define DER_PRIVATE 0xc0 andre@0: andre@0: /* andre@0: ** Our additions, used for templates. andre@0: ** These are not defined by any standard; the values are used internally only. andre@0: ** Just be careful to keep them out of the low 8 bits. andre@0: */ andre@0: #define DER_OPTIONAL 0x00100 andre@0: #define DER_EXPLICIT 0x00200 andre@0: #define DER_ANY 0x00400 andre@0: #define DER_INLINE 0x00800 andre@0: #define DER_POINTER 0x01000 andre@0: #define DER_INDEFINITE 0x02000 andre@0: #define DER_DERPTR 0x04000 andre@0: #define DER_SKIP 0x08000 andre@0: #define DER_FORCE 0x10000 andre@0: #define DER_OUTER 0x40000 /* for DER_DERPTR */ andre@0: andre@0: /* andre@0: ** Macro to convert der decoded bit string into a decoded octet andre@0: ** string. All it needs to do is fiddle with the length code. andre@0: */ andre@0: #define DER_ConvertBitString(item) \ andre@0: { \ andre@0: (item)->len = ((item)->len + 7) >> 3; \ andre@0: } andre@0: andre@0: #endif /* _SECDERT_H_ */