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