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