secdert.h 3.9 KB

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