| OLD | NEW |
| (Empty) |
| 1 /* This Source Code Form is subject to the terms of the Mozilla Public | |
| 2 * License, v. 2.0. If a copy of the MPL was not distributed with this | |
| 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | |
| 4 | |
| 5 #ifndef _SECDERT_H_ | |
| 6 #define _SECDERT_H_ | |
| 7 /* | |
| 8 * secdert.h - public data structures for the DER encoding and | |
| 9 * decoding utilities library | |
| 10 * | |
| 11 * $Id: secdert.h,v 1.6 2012/04/25 14:50:16 gerv%gerv.net Exp $ | |
| 12 */ | |
| 13 | |
| 14 #include "utilrename.h" | |
| 15 #include "seccomon.h" | |
| 16 | |
| 17 typedef struct DERTemplateStr DERTemplate; | |
| 18 | |
| 19 /* | |
| 20 ** An array of these structures defines an encoding for an object using DER. | |
| 21 ** The array usually starts with a dummy entry whose kind is DER_SEQUENCE; | |
| 22 ** such an array is terminated with an entry where kind == 0. (An array | |
| 23 ** which consists of a single component does not require a second dummy | |
| 24 ** entry -- the array is only searched as long as previous component(s) | |
| 25 ** instruct it.) | |
| 26 */ | |
| 27 struct DERTemplateStr { | |
| 28 /* | |
| 29 ** Kind of item being decoded/encoded, including tags and modifiers. | |
| 30 */ | |
| 31 unsigned long kind; | |
| 32 | |
| 33 /* | |
| 34 ** Offset from base of structure to field that holds the value | |
| 35 ** being decoded/encoded. | |
| 36 */ | |
| 37 unsigned int offset; | |
| 38 | |
| 39 /* | |
| 40 ** When kind suggests it (DER_POINTER, DER_INDEFINITE, DER_INLINE), | |
| 41 ** this points to a sub-template for nested encoding/decoding. | |
| 42 */ | |
| 43 DERTemplate *sub; | |
| 44 | |
| 45 /* | |
| 46 ** Argument value, dependent on "kind" and/or template placement | |
| 47 ** within an array of templates: | |
| 48 ** - In the first element of a template array, the value is the | |
| 49 ** size of the structure to allocate when this template is being | |
| 50 ** referenced by another template via DER_POINTER or DER_INDEFINITE. | |
| 51 ** - In a component of a DER_SET or DER_SEQUENCE which is *not* a | |
| 52 ** DER_UNIVERSAL type (that is, it has a class tag for either | |
| 53 ** DER_APPLICATION, DER_CONTEXT_SPECIFIC, or DER_PRIVATE), the | |
| 54 ** value is the underlying type of item being decoded/encoded. | |
| 55 */ | |
| 56 unsigned long arg; | |
| 57 }; | |
| 58 | |
| 59 /************************************************************************/ | |
| 60 | |
| 61 /* default chunksize for arenas used for DER stuff */ | |
| 62 #define DER_DEFAULT_CHUNKSIZE (2048) | |
| 63 | |
| 64 /* | |
| 65 ** BER/DER values for ASN.1 identifier octets. | |
| 66 */ | |
| 67 #define DER_TAG_MASK 0xff | |
| 68 | |
| 69 /* | |
| 70 * BER/DER universal type tag numbers. | |
| 71 * The values are defined by the X.208 standard; do not change them! | |
| 72 * NOTE: if you add anything to this list, you must add code to derdec.c | |
| 73 * to accept the tag, and probably also to derenc.c to encode it. | |
| 74 */ | |
| 75 #define DER_TAGNUM_MASK 0x1f | |
| 76 #define DER_BOOLEAN 0x01 | |
| 77 #define DER_INTEGER 0x02 | |
| 78 #define DER_BIT_STRING 0x03 | |
| 79 #define DER_OCTET_STRING 0x04 | |
| 80 #define DER_NULL 0x05 | |
| 81 #define DER_OBJECT_ID 0x06 | |
| 82 #define DER_SEQUENCE 0x10 | |
| 83 #define DER_SET 0x11 | |
| 84 #define DER_PRINTABLE_STRING 0x13 | |
| 85 #define DER_T61_STRING 0x14 | |
| 86 #define DER_IA5_STRING 0x16 | |
| 87 #define DER_UTC_TIME 0x17 | |
| 88 #define DER_VISIBLE_STRING 0x1a | |
| 89 #define DER_HIGH_TAG_NUMBER 0x1f | |
| 90 | |
| 91 /* | |
| 92 ** Modifiers to type tags. These are also specified by a/the | |
| 93 ** standard, and must not be changed. | |
| 94 */ | |
| 95 | |
| 96 #define DER_METHOD_MASK 0x20 | |
| 97 #define DER_PRIMITIVE 0x00 | |
| 98 #define DER_CONSTRUCTED 0x20 | |
| 99 | |
| 100 #define DER_CLASS_MASK 0xc0 | |
| 101 #define DER_UNIVERSAL 0x00 | |
| 102 #define DER_APPLICATION 0x40 | |
| 103 #define DER_CONTEXT_SPECIFIC 0x80 | |
| 104 #define DER_PRIVATE 0xc0 | |
| 105 | |
| 106 /* | |
| 107 ** Our additions, used for templates. | |
| 108 ** These are not defined by any standard; the values are used internally only. | |
| 109 ** Just be careful to keep them out of the low 8 bits. | |
| 110 */ | |
| 111 #define DER_OPTIONAL 0x00100 | |
| 112 #define DER_EXPLICIT 0x00200 | |
| 113 #define DER_ANY 0x00400 | |
| 114 #define DER_INLINE 0x00800 | |
| 115 #define DER_POINTER 0x01000 | |
| 116 #define DER_INDEFINITE 0x02000 | |
| 117 #define DER_DERPTR 0x04000 | |
| 118 #define DER_SKIP 0x08000 | |
| 119 #define DER_FORCE 0x10000 | |
| 120 #define DER_OUTER 0x40000 /* for DER_DERPTR */ | |
| 121 | |
| 122 /* | |
| 123 ** Macro to convert der decoded bit string into a decoded octet | |
| 124 ** string. All it needs to do is fiddle with the length code. | |
| 125 */ | |
| 126 #define DER_ConvertBitString(item) \ | |
| 127 { \ | |
| 128 (item)->len = ((item)->len + 7) >> 3; \ | |
| 129 } | |
| 130 | |
| 131 #endif /* _SECDERT_H_ */ | |
| OLD | NEW |