security/nss/lib/util/secdert.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/nss/lib/util/secdert.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,129 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef _SECDERT_H_
     1.9 +#define _SECDERT_H_
    1.10 +/*
    1.11 + * secdert.h - public data structures for the DER encoding and
    1.12 + *	       decoding utilities library
    1.13 + */
    1.14 +
    1.15 +#include "utilrename.h"
    1.16 +#include "seccomon.h"
    1.17 +
    1.18 +typedef struct DERTemplateStr DERTemplate;
    1.19 +
    1.20 +/*
    1.21 +** An array of these structures defines an encoding for an object using DER.
    1.22 +** The array usually starts with a dummy entry whose kind is DER_SEQUENCE;
    1.23 +** such an array is terminated with an entry where kind == 0.  (An array
    1.24 +** which consists of a single component does not require a second dummy
    1.25 +** entry -- the array is only searched as long as previous component(s)
    1.26 +** instruct it.)
    1.27 +*/
    1.28 +struct DERTemplateStr {
    1.29 +    /*
    1.30 +    ** Kind of item being decoded/encoded, including tags and modifiers.
    1.31 +    */
    1.32 +    unsigned long kind;
    1.33 +
    1.34 +    /*
    1.35 +    ** Offset from base of structure to field that holds the value
    1.36 +    ** being decoded/encoded.
    1.37 +    */
    1.38 +    unsigned int offset;
    1.39 +
    1.40 +    /*
    1.41 +    ** When kind suggests it (DER_POINTER, DER_INDEFINITE, DER_INLINE),
    1.42 +    ** this points to a sub-template for nested encoding/decoding.
    1.43 +    */
    1.44 +    DERTemplate *sub;
    1.45 +
    1.46 +    /*
    1.47 +    ** Argument value, dependent on "kind" and/or template placement
    1.48 +    ** within an array of templates:
    1.49 +    **	- In the first element of a template array, the value is the
    1.50 +    **	  size of the structure to allocate when this template is being
    1.51 +    **	  referenced by another template via DER_POINTER or DER_INDEFINITE.
    1.52 +    **  - In a component of a DER_SET or DER_SEQUENCE which is *not* a
    1.53 +    **	  DER_UNIVERSAL type (that is, it has a class tag for either
    1.54 +    **	  DER_APPLICATION, DER_CONTEXT_SPECIFIC, or DER_PRIVATE), the
    1.55 +    **	  value is the underlying type of item being decoded/encoded.
    1.56 +    */
    1.57 +    unsigned long arg;
    1.58 +};
    1.59 +
    1.60 +/************************************************************************/
    1.61 +
    1.62 +/* default chunksize for arenas used for DER stuff */
    1.63 +#define DER_DEFAULT_CHUNKSIZE (2048)
    1.64 +
    1.65 +/*
    1.66 +** BER/DER values for ASN.1 identifier octets.
    1.67 +*/
    1.68 +#define DER_TAG_MASK		0xff
    1.69 +
    1.70 +/*
    1.71 + * BER/DER universal type tag numbers.
    1.72 + * The values are defined by the X.208 standard; do not change them!
    1.73 + * NOTE: if you add anything to this list, you must add code to derdec.c
    1.74 + * to accept the tag, and probably also to derenc.c to encode it.
    1.75 + */
    1.76 +#define DER_TAGNUM_MASK		0x1f
    1.77 +#define DER_BOOLEAN		0x01
    1.78 +#define DER_INTEGER		0x02
    1.79 +#define DER_BIT_STRING		0x03
    1.80 +#define DER_OCTET_STRING	0x04
    1.81 +#define DER_NULL		0x05
    1.82 +#define DER_OBJECT_ID		0x06
    1.83 +#define DER_SEQUENCE		0x10
    1.84 +#define DER_SET			0x11
    1.85 +#define DER_PRINTABLE_STRING	0x13
    1.86 +#define DER_T61_STRING		0x14
    1.87 +#define DER_IA5_STRING		0x16
    1.88 +#define DER_UTC_TIME		0x17
    1.89 +#define DER_VISIBLE_STRING	0x1a
    1.90 +#define DER_HIGH_TAG_NUMBER	0x1f
    1.91 +
    1.92 +/*
    1.93 +** Modifiers to type tags.  These are also specified by a/the
    1.94 +** standard, and must not be changed.
    1.95 +*/
    1.96 +
    1.97 +#define DER_METHOD_MASK		0x20
    1.98 +#define DER_PRIMITIVE		0x00
    1.99 +#define DER_CONSTRUCTED		0x20
   1.100 +
   1.101 +#define DER_CLASS_MASK		0xc0
   1.102 +#define DER_UNIVERSAL		0x00
   1.103 +#define DER_APPLICATION		0x40
   1.104 +#define DER_CONTEXT_SPECIFIC	0x80
   1.105 +#define DER_PRIVATE		0xc0
   1.106 +
   1.107 +/*
   1.108 +** Our additions, used for templates.
   1.109 +** These are not defined by any standard; the values are used internally only.
   1.110 +** Just be careful to keep them out of the low 8 bits.
   1.111 +*/
   1.112 +#define DER_OPTIONAL		0x00100
   1.113 +#define DER_EXPLICIT		0x00200
   1.114 +#define DER_ANY			0x00400
   1.115 +#define DER_INLINE		0x00800
   1.116 +#define DER_POINTER		0x01000
   1.117 +#define DER_INDEFINITE		0x02000
   1.118 +#define DER_DERPTR		0x04000
   1.119 +#define DER_SKIP		0x08000
   1.120 +#define DER_FORCE		0x10000
   1.121 +#define DER_OUTER		0x40000 /* for DER_DERPTR */
   1.122 +
   1.123 +/*
   1.124 +** Macro to convert der decoded bit string into a decoded octet
   1.125 +** string. All it needs to do is fiddle with the length code.
   1.126 +*/
   1.127 +#define DER_ConvertBitString(item)	  \
   1.128 +{					  \
   1.129 +    (item)->len = ((item)->len + 7) >> 3; \
   1.130 +}
   1.131 +
   1.132 +#endif /* _SECDERT_H_ */

mercurial