asn1.h 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  1. /* crypto/asn1/asn1.h */
  2. /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  3. * All rights reserved.
  4. *
  5. * This package is an SSL implementation written
  6. * by Eric Young (eay@cryptsoft.com).
  7. * The implementation was written so as to conform with Netscapes SSL.
  8. *
  9. * This library is free for commercial and non-commercial use as long as
  10. * the following conditions are aheared to. The following conditions
  11. * apply to all code found in this distribution, be it the RC4, RSA,
  12. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  13. * included with this distribution is covered by the same copyright terms
  14. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  15. *
  16. * Copyright remains Eric Young's, and as such any Copyright notices in
  17. * the code are not to be removed.
  18. * If this package is used in a product, Eric Young should be given attribution
  19. * as the author of the parts of the library used.
  20. * This can be in the form of a textual message at program startup or
  21. * in documentation (online or textual) provided with the package.
  22. *
  23. * Redistribution and use in source and binary forms, with or without
  24. * modification, are permitted provided that the following conditions
  25. * are met:
  26. * 1. Redistributions of source code must retain the copyright
  27. * notice, this list of conditions and the following disclaimer.
  28. * 2. Redistributions in binary form must reproduce the above copyright
  29. * notice, this list of conditions and the following disclaimer in the
  30. * documentation and/or other materials provided with the distribution.
  31. * 3. All advertising materials mentioning features or use of this software
  32. * must display the following acknowledgement:
  33. * "This product includes cryptographic software written by
  34. * Eric Young (eay@cryptsoft.com)"
  35. * The word 'cryptographic' can be left out if the rouines from the library
  36. * being used are not cryptographic related :-).
  37. * 4. If you include any Windows specific code (or a derivative thereof) from
  38. * the apps directory (application code) you must include an acknowledgement:
  39. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  40. *
  41. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  42. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  43. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  44. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  45. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  46. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  47. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  48. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  49. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  50. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  51. * SUCH DAMAGE.
  52. *
  53. * The licence and distribution terms for any publically available version or
  54. * derivative of this code cannot be changed. i.e. this code cannot simply be
  55. * copied and put under another distribution licence
  56. * [including the GNU Public Licence.]
  57. */
  58. #ifndef HEADER_ASN1_H
  59. #define HEADER_ASN1_H
  60. #include <time.h>
  61. #ifndef OPENSSL_NO_BIO
  62. #include <openssl/bio.h>
  63. #endif
  64. #include <openssl/e_os2.h>
  65. #include <openssl/bn.h>
  66. #include <openssl/stack.h>
  67. #include <openssl/safestack.h>
  68. #include <openssl/symhacks.h>
  69. #include <openssl/e_os2.h>
  70. #include <openssl/types.h>
  71. #ifdef OPENSSL_BUILD_SHLIBCRYPTO
  72. # undef OPENSSL_EXTERN
  73. # define OPENSSL_EXTERN OPENSSL_EXPORT
  74. #endif
  75. #ifdef __cplusplus
  76. extern "C" {
  77. #endif
  78. #define V_ASN1_UNIVERSAL 0x00
  79. #define V_ASN1_APPLICATION 0x40
  80. #define V_ASN1_CONTEXT_SPECIFIC 0x80
  81. #define V_ASN1_PRIVATE 0xc0
  82. #define V_ASN1_CONSTRUCTED 0x20
  83. #define V_ASN1_PRIMITIVE_TAG 0x1f
  84. #define V_ASN1_PRIMATIVE_TAG 0x1f
  85. #define V_ASN1_APP_CHOOSE -2 /* let the recipient choose */
  86. #define V_ASN1_OTHER -3 /* used in ASN1_TYPE */
  87. #define V_ASN1_ANY -4 /* used in ASN1 template code */
  88. #define V_ASN1_NEG 0x100 /* negative flag */
  89. #define V_ASN1_UNDEF -1
  90. #define V_ASN1_EOC 0
  91. #define V_ASN1_BOOLEAN 1 /**/
  92. #define V_ASN1_INTEGER 2
  93. #define V_ASN1_NEG_INTEGER (2 | V_ASN1_NEG)
  94. #define V_ASN1_BIT_STRING 3
  95. #define V_ASN1_OCTET_STRING 4
  96. #define V_ASN1_NULL 5
  97. #define V_ASN1_OBJECT 6
  98. #define V_ASN1_OBJECT_DESCRIPTOR 7
  99. #define V_ASN1_EXTERNAL 8
  100. #define V_ASN1_REAL 9
  101. #define V_ASN1_ENUMERATED 10
  102. #define V_ASN1_NEG_ENUMERATED (10 | V_ASN1_NEG)
  103. #define V_ASN1_UTF8STRING 12
  104. #define V_ASN1_SEQUENCE 16
  105. #define V_ASN1_SET 17
  106. #define V_ASN1_NUMERICSTRING 18 /**/
  107. #define V_ASN1_PRINTABLESTRING 19
  108. #define V_ASN1_T61STRING 20
  109. #define V_ASN1_TELETEXSTRING 20 /* alias */
  110. #define V_ASN1_VIDEOTEXSTRING 21 /**/
  111. #define V_ASN1_IA5STRING 22
  112. #define V_ASN1_UTCTIME 23
  113. #define V_ASN1_GENERALIZEDTIME 24 /**/
  114. #define V_ASN1_GRAPHICSTRING 25 /**/
  115. #define V_ASN1_ISO64STRING 26 /**/
  116. #define V_ASN1_VISIBLESTRING 26 /* alias */
  117. #define V_ASN1_GENERALSTRING 27 /**/
  118. #define V_ASN1_UNIVERSALSTRING 28 /**/
  119. #define V_ASN1_BMPSTRING 30
  120. /* For use with d2i_ASN1_type_bytes() */
  121. #define B_ASN1_NUMERICSTRING 0x0001
  122. #define B_ASN1_PRINTABLESTRING 0x0002
  123. #define B_ASN1_T61STRING 0x0004
  124. #define B_ASN1_TELETEXSTRING 0x0008
  125. #define B_ASN1_VIDEOTEXSTRING 0x0008
  126. #define B_ASN1_IA5STRING 0x0010
  127. #define B_ASN1_GRAPHICSTRING 0x0020
  128. #define B_ASN1_ISO64STRING 0x0040
  129. #define B_ASN1_VISIBLESTRING 0x0040
  130. #define B_ASN1_GENERALSTRING 0x0080
  131. #define B_ASN1_UNIVERSALSTRING 0x0100
  132. #define B_ASN1_OCTET_STRING 0x0200
  133. #define B_ASN1_BIT_STRING 0x0400
  134. #define B_ASN1_BMPSTRING 0x0800
  135. #define B_ASN1_UNKNOWN 0x1000
  136. #define B_ASN1_UTF8STRING 0x2000
  137. #define B_ASN1_UTCTIME 0x4000
  138. #define B_ASN1_GENERALIZEDTIME 0x8000
  139. /* For use with ASN1_mbstring_copy() */
  140. #define MBSTRING_FLAG 0x1000
  141. #define MBSTRING_ASC (MBSTRING_FLAG|1)
  142. #define MBSTRING_BMP (MBSTRING_FLAG|2)
  143. #define MBSTRING_UNIV (MBSTRING_FLAG|3)
  144. #define MBSTRING_UTF8 (MBSTRING_FLAG|4)
  145. struct X509_algor_st;
  146. #define DECLARE_ASN1_SET_OF(type) /* filled in by mkstack.pl */
  147. #define IMPLEMENT_ASN1_SET_OF(type) /* nothing, no longer needed */
  148. typedef struct asn1_ctx_st
  149. {
  150. unsigned char *p;/* work char pointer */
  151. int eos; /* end of sequence read for indefinite encoding */
  152. int error; /* error code to use when returning an error */
  153. int inf; /* constructed if 0x20, indefinite is 0x21 */
  154. int tag; /* tag from last 'get object' */
  155. int xclass; /* class from last 'get object' */
  156. long slen; /* length of last 'get object' */
  157. unsigned char *max; /* largest value of p allowed */
  158. unsigned char *q;/* temporary variable */
  159. unsigned char **pp;/* variable */
  160. int line; /* used in error processing */
  161. } ASN1_CTX;
  162. /* These are used internally in the ASN1_OBJECT to keep track of
  163. * whether the names and data need to be free()ed */
  164. #define ASN1_OBJECT_FLAG_DYNAMIC 0x01 /* internal use */
  165. #define ASN1_OBJECT_FLAG_CRITICAL 0x02 /* critical x509v3 object id */
  166. #define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04 /* internal use */
  167. #define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08 /* internal use */
  168. typedef struct asn1_object_st
  169. {
  170. const char *sn,*ln;
  171. int nid;
  172. int length;
  173. unsigned char *data;
  174. int flags; /* Should we free this one */
  175. } ASN1_OBJECT;
  176. #define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */
  177. /* This is the base type that holds just about everything :-) */
  178. typedef struct asn1_string_st
  179. {
  180. int length;
  181. int type;
  182. unsigned char *data;
  183. /* The value of the following field depends on the type being
  184. * held. It is mostly being used for BIT_STRING so if the
  185. * input data has a non-zero 'unused bits' value, it will be
  186. * handled correctly */
  187. long flags;
  188. } ASN1_STRING;
  189. /* ASN1_ENCODING structure: this is used to save the received
  190. * encoding of an ASN1 type. This is useful to get round
  191. * problems with invalid encodings which can break signatures.
  192. */
  193. typedef struct ASN1_ENCODING_st
  194. {
  195. unsigned char *enc; /* DER encoding */
  196. long len; /* Length of encoding */
  197. int modified; /* set to 1 if 'enc' is invalid */
  198. } ASN1_ENCODING;
  199. /* Used with ASN1 LONG type: if a long is set to this it is omitted */
  200. #define ASN1_LONG_UNDEF 0x7fffffffL
  201. #define STABLE_FLAGS_MALLOC 0x01
  202. #define STABLE_NO_MASK 0x02
  203. #define DIRSTRING_TYPE \
  204. (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)
  205. #define PKCS9STRING_TYPE (DIRSTRING_TYPE|B_ASN1_IA5STRING)
  206. typedef struct asn1_string_table_st {
  207. int nid;
  208. long minsize;
  209. long maxsize;
  210. unsigned long mask;
  211. unsigned long flags;
  212. } ASN1_STRING_TABLE;
  213. DECLARE_STACK_OF(ASN1_STRING_TABLE)
  214. /* size limits: this stuff is taken straight from RFC2459 */
  215. #define ub_name 32768
  216. #define ub_common_name 64
  217. #define ub_locality_name 128
  218. #define ub_state_name 128
  219. #define ub_organization_name 64
  220. #define ub_organization_unit_name 64
  221. #define ub_title 64
  222. #define ub_email_address 128
  223. /* Declarations for template structures: for full definitions
  224. * see asn1t.h
  225. */
  226. typedef struct ASN1_TEMPLATE_st ASN1_TEMPLATE;
  227. typedef struct ASN1_ITEM_st ASN1_ITEM;
  228. typedef struct ASN1_TLC_st ASN1_TLC;
  229. /* This is just an opaque pointer */
  230. typedef struct ASN1_VALUE_st ASN1_VALUE;
  231. /* Declare ASN1 functions: the implement macro in in asn1t.h */
  232. #define DECLARE_ASN1_FUNCTIONS(type) DECLARE_ASN1_FUNCTIONS_name(type, type)
  233. #define DECLARE_ASN1_FUNCTIONS_name(type, name) \
  234. type *name##_new(void); \
  235. void name##_free(type *a); \
  236. DECLARE_ASN1_ENCODE_FUNCTIONS(type, name, name)
  237. #define DECLARE_ASN1_FUNCTIONS_fname(type, itname, name) \
  238. type *name##_new(void); \
  239. void name##_free(type *a); \
  240. DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name)
  241. #define DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) \
  242. type *d2i_##name(type **a, unsigned char **in, long len); \
  243. int i2d_##name(type *a, unsigned char **out); \
  244. DECLARE_ASN1_ITEM(itname)
  245. #define DECLARE_ASN1_ENCODE_FUNCTIONS_const(type, name) \
  246. type *d2i_##name(type **a, const unsigned char **in, long len); \
  247. int i2d_##name(const type *a, unsigned char **out); \
  248. DECLARE_ASN1_ITEM(name)
  249. #define DECLARE_ASN1_FUNCTIONS_const(name) \
  250. name *name##_new(void); \
  251. void name##_free(name *a);
  252. /* The following macros and typedefs allow an ASN1_ITEM
  253. * to be embedded in a structure and referenced. Since
  254. * the ASN1_ITEM pointers need to be globally accessible
  255. * (possibly from shared libraries) they may exist in
  256. * different forms. On platforms that support it the
  257. * ASN1_ITEM structure itself will be globally exported.
  258. * Other platforms will export a function that returns
  259. * an ASN1_ITEM pointer.
  260. *
  261. * To handle both cases transparently the macros below
  262. * should be used instead of hard coding an ASN1_ITEM
  263. * pointer in a structure.
  264. *
  265. * The structure will look like this:
  266. *
  267. * typedef struct SOMETHING_st {
  268. * ...
  269. * ASN1_ITEM_EXP *iptr;
  270. * ...
  271. * } SOMETHING;
  272. *
  273. * It would be initialised as e.g.:
  274. *
  275. * SOMETHING somevar = {...,ASN1_ITEM_ref(X509),...};
  276. *
  277. * and the actual pointer extracted with:
  278. *
  279. * const ASN1_ITEM *it = ASN1_ITEM_ptr(somevar.iptr);
  280. *
  281. * Finally an ASN1_ITEM pointer can be extracted from an
  282. * appropriate reference with: ASN1_ITEM_rptr(X509). This
  283. * would be used when a function takes an ASN1_ITEM * argument.
  284. *
  285. */
  286. #ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
  287. /* ASN1_ITEM pointer exported type */
  288. typedef const ASN1_ITEM ASN1_ITEM_EXP;
  289. /* Macro to obtain ASN1_ITEM pointer from exported type */
  290. #define ASN1_ITEM_ptr(iptr) (iptr)
  291. /* Macro to include ASN1_ITEM pointer from base type */
  292. #define ASN1_ITEM_ref(iptr) (&(iptr##_it))
  293. #define ASN1_ITEM_rptr(ref) (&(ref##_it))
  294. #define DECLARE_ASN1_ITEM(name) \
  295. OPENSSL_EXTERN const ASN1_ITEM name##_it;
  296. #else
  297. /* Platforms that can't easily handle shared global variables are declared
  298. * as functions returning ASN1_ITEM pointers.
  299. */
  300. /* ASN1_ITEM pointer exported type */
  301. typedef const ASN1_ITEM * ASN1_ITEM_EXP(void);
  302. /* Macro to obtain ASN1_ITEM pointer from exported type */
  303. #define ASN1_ITEM_ptr(iptr) (iptr())
  304. /* Macro to include ASN1_ITEM pointer from base type */
  305. #define ASN1_ITEM_ref(iptr) (iptr##_it)
  306. #define ASN1_ITEM_rptr(ref) (ref##_it())
  307. #define DECLARE_ASN1_ITEM(name) \
  308. const ASN1_ITEM * name##_it(void);
  309. #endif
  310. /* Parameters used by ASN1_STRING_print_ex() */
  311. /* These determine which characters to escape:
  312. * RFC2253 special characters, control characters and
  313. * MSB set characters
  314. */
  315. #define ASN1_STRFLGS_ESC_2253 1
  316. #define ASN1_STRFLGS_ESC_CTRL 2
  317. #define ASN1_STRFLGS_ESC_MSB 4
  318. /* This flag determines how we do escaping: normally
  319. * RC2253 backslash only, set this to use backslash and
  320. * quote.
  321. */
  322. #define ASN1_STRFLGS_ESC_QUOTE 8
  323. /* These three flags are internal use only. */
  324. /* Character is a valid PrintableString character */
  325. #define CHARTYPE_PRINTABLESTRING 0x10
  326. /* Character needs escaping if it is the first character */
  327. #define CHARTYPE_FIRST_ESC_2253 0x20
  328. /* Character needs escaping if it is the last character */
  329. #define CHARTYPE_LAST_ESC_2253 0x40
  330. /* NB the internal flags are safely reused below by flags
  331. * handled at the top level.
  332. */
  333. /* If this is set we convert all character strings
  334. * to UTF8 first
  335. */
  336. #define ASN1_STRFLGS_UTF8_CONVERT 0x10
  337. /* If this is set we don't attempt to interpret content:
  338. * just assume all strings are 1 byte per character. This
  339. * will produce some pretty odd looking output!
  340. */
  341. #define ASN1_STRFLGS_IGNORE_TYPE 0x20
  342. /* If this is set we include the string type in the output */
  343. #define ASN1_STRFLGS_SHOW_TYPE 0x40
  344. /* This determines which strings to display and which to
  345. * 'dump' (hex dump of content octets or DER encoding). We can
  346. * only dump non character strings or everything. If we
  347. * don't dump 'unknown' they are interpreted as character
  348. * strings with 1 octet per character and are subject to
  349. * the usual escaping options.
  350. */
  351. #define ASN1_STRFLGS_DUMP_ALL 0x80
  352. #define ASN1_STRFLGS_DUMP_UNKNOWN 0x100
  353. /* These determine what 'dumping' does, we can dump the
  354. * content octets or the DER encoding: both use the
  355. * RFC2253 #XXXXX notation.
  356. */
  357. #define ASN1_STRFLGS_DUMP_DER 0x200
  358. /* All the string flags consistent with RFC2253,
  359. * escaping control characters isn't essential in
  360. * RFC2253 but it is advisable anyway.
  361. */
  362. #define ASN1_STRFLGS_RFC2253 (ASN1_STRFLGS_ESC_2253 | \
  363. ASN1_STRFLGS_ESC_CTRL | \
  364. ASN1_STRFLGS_ESC_MSB | \
  365. ASN1_STRFLGS_UTF8_CONVERT | \
  366. ASN1_STRFLGS_DUMP_UNKNOWN | \
  367. ASN1_STRFLGS_DUMP_DER)
  368. DECLARE_STACK_OF(ASN1_INTEGER)
  369. DECLARE_ASN1_SET_OF(ASN1_INTEGER)
  370. typedef struct asn1_type_st
  371. {
  372. int type;
  373. union {
  374. char *ptr;
  375. ASN1_BOOLEAN boolean;
  376. ASN1_STRING * asn1_string;
  377. ASN1_OBJECT * object;
  378. ASN1_INTEGER * integer;
  379. ASN1_ENUMERATED * enumerated;
  380. ASN1_BIT_STRING * bit_string;
  381. ASN1_OCTET_STRING * octet_string;
  382. ASN1_PRINTABLESTRING * printablestring;
  383. ASN1_T61STRING * t61string;
  384. ASN1_IA5STRING * ia5string;
  385. ASN1_GENERALSTRING * generalstring;
  386. ASN1_BMPSTRING * bmpstring;
  387. ASN1_UNIVERSALSTRING * universalstring;
  388. ASN1_UTCTIME * utctime;
  389. ASN1_GENERALIZEDTIME * generalizedtime;
  390. ASN1_VISIBLESTRING * visiblestring;
  391. ASN1_UTF8STRING * utf8string;
  392. /* set and sequence are left complete and still
  393. * contain the set or sequence bytes */
  394. ASN1_STRING * set;
  395. ASN1_STRING * sequence;
  396. } value;
  397. } ASN1_TYPE;
  398. DECLARE_STACK_OF(ASN1_TYPE)
  399. DECLARE_ASN1_SET_OF(ASN1_TYPE)
  400. typedef struct asn1_method_st
  401. {
  402. int (*i2d)();
  403. char *(*d2i)();
  404. char *(*create)();
  405. void (*destroy)();
  406. } ASN1_METHOD;
  407. /* This is used when parsing some Netscape objects */
  408. typedef struct asn1_header_st
  409. {
  410. ASN1_OCTET_STRING *header;
  411. char *data;
  412. ASN1_METHOD *meth;
  413. } ASN1_HEADER;
  414. /* This is used to contain a list of bit names */
  415. typedef struct BIT_STRING_BITNAME_st {
  416. int bitnum;
  417. const char *lname;
  418. const char *sname;
  419. } BIT_STRING_BITNAME;
  420. #define M_ASN1_STRING_length(x) ((x)->length)
  421. #define M_ASN1_STRING_length_set(x, n) ((x)->length = (n))
  422. #define M_ASN1_STRING_type(x) ((x)->type)
  423. #define M_ASN1_STRING_data(x) ((x)->data)
  424. /* Macros for string operations */
  425. #define M_ASN1_BIT_STRING_new() (ASN1_BIT_STRING *)\
  426. ASN1_STRING_type_new(V_ASN1_BIT_STRING)
  427. #define M_ASN1_BIT_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
  428. #define M_ASN1_BIT_STRING_dup(a) (ASN1_BIT_STRING *)\
  429. ASN1_STRING_dup((ASN1_STRING *)a)
  430. #define M_ASN1_BIT_STRING_cmp(a,b) ASN1_STRING_cmp(\
  431. (ASN1_STRING *)a,(ASN1_STRING *)b)
  432. #define M_ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
  433. #define M_ASN1_INTEGER_new() (ASN1_INTEGER *)\
  434. ASN1_STRING_type_new(V_ASN1_INTEGER)
  435. #define M_ASN1_INTEGER_free(a) ASN1_STRING_free((ASN1_STRING *)a)
  436. #define M_ASN1_INTEGER_dup(a) (ASN1_INTEGER *)ASN1_STRING_dup((ASN1_STRING *)a)
  437. #define M_ASN1_INTEGER_cmp(a,b) ASN1_STRING_cmp(\
  438. (ASN1_STRING *)a,(ASN1_STRING *)b)
  439. #define M_ASN1_ENUMERATED_new() (ASN1_ENUMERATED *)\
  440. ASN1_STRING_type_new(V_ASN1_ENUMERATED)
  441. #define M_ASN1_ENUMERATED_free(a) ASN1_STRING_free((ASN1_STRING *)a)
  442. #define M_ASN1_ENUMERATED_dup(a) (ASN1_ENUMERATED *)ASN1_STRING_dup((ASN1_STRING *)a)
  443. #define M_ASN1_ENUMERATED_cmp(a,b) ASN1_STRING_cmp(\
  444. (ASN1_STRING *)a,(ASN1_STRING *)b)
  445. #define M_ASN1_OCTET_STRING_new() (ASN1_OCTET_STRING *)\
  446. ASN1_STRING_type_new(V_ASN1_OCTET_STRING)
  447. #define M_ASN1_OCTET_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
  448. #define M_ASN1_OCTET_STRING_dup(a) (ASN1_OCTET_STRING *)\
  449. ASN1_STRING_dup((ASN1_STRING *)a)
  450. #define M_ASN1_OCTET_STRING_cmp(a,b) ASN1_STRING_cmp(\
  451. (ASN1_STRING *)a,(ASN1_STRING *)b)
  452. #define M_ASN1_OCTET_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
  453. #define M_ASN1_OCTET_STRING_print(a,b) ASN1_STRING_print(a,(ASN1_STRING *)b)
  454. #define M_i2d_ASN1_OCTET_STRING(a,pp) \
  455. i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_OCTET_STRING,\
  456. V_ASN1_UNIVERSAL)
  457. #define B_ASN1_TIME \
  458. B_ASN1_UTCTIME | \
  459. B_ASN1_GENERALIZEDTIME
  460. #define B_ASN1_PRINTABLE \
  461. B_ASN1_PRINTABLESTRING| \
  462. B_ASN1_T61STRING| \
  463. B_ASN1_IA5STRING| \
  464. B_ASN1_BIT_STRING| \
  465. B_ASN1_UNIVERSALSTRING|\
  466. B_ASN1_BMPSTRING|\
  467. B_ASN1_UTF8STRING|\
  468. B_ASN1_UNKNOWN
  469. #define B_ASN1_DIRECTORYSTRING \
  470. B_ASN1_PRINTABLESTRING| \
  471. B_ASN1_TELETEXSTRING|\
  472. B_ASN1_BMPSTRING|\
  473. B_ASN1_UNIVERSALSTRING|\
  474. B_ASN1_UTF8STRING
  475. #define B_ASN1_DISPLAYTEXT \
  476. B_ASN1_IA5STRING| \
  477. B_ASN1_VISIBLESTRING| \
  478. B_ASN1_BMPSTRING|\
  479. B_ASN1_UTF8STRING
  480. #define M_ASN1_PRINTABLE_new() ASN1_STRING_type_new(V_ASN1_T61STRING)
  481. #define M_ASN1_PRINTABLE_free(a) ASN1_STRING_free((ASN1_STRING *)a)
  482. #define M_i2d_ASN1_PRINTABLE(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
  483. pp,a->type,V_ASN1_UNIVERSAL)
  484. #define M_d2i_ASN1_PRINTABLE(a,pp,l) \
  485. d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
  486. B_ASN1_PRINTABLE)
  487. #define M_DIRECTORYSTRING_new() ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
  488. #define M_DIRECTORYSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
  489. #define M_i2d_DIRECTORYSTRING(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
  490. pp,a->type,V_ASN1_UNIVERSAL)
  491. #define M_d2i_DIRECTORYSTRING(a,pp,l) \
  492. d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
  493. B_ASN1_DIRECTORYSTRING)
  494. #define M_DISPLAYTEXT_new() ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
  495. #define M_DISPLAYTEXT_free(a) ASN1_STRING_free((ASN1_STRING *)a)
  496. #define M_i2d_DISPLAYTEXT(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
  497. pp,a->type,V_ASN1_UNIVERSAL)
  498. #define M_d2i_DISPLAYTEXT(a,pp,l) \
  499. d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
  500. B_ASN1_DISPLAYTEXT)
  501. #define M_ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING *)\
  502. ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
  503. #define M_ASN1_PRINTABLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
  504. #define M_i2d_ASN1_PRINTABLESTRING(a,pp) \
  505. i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_PRINTABLESTRING,\
  506. V_ASN1_UNIVERSAL)
  507. #define M_d2i_ASN1_PRINTABLESTRING(a,pp,l) \
  508. (ASN1_PRINTABLESTRING *)d2i_ASN1_type_bytes\
  509. ((ASN1_STRING **)a,pp,l,B_ASN1_PRINTABLESTRING)
  510. #define M_ASN1_T61STRING_new() (ASN1_T61STRING *)\
  511. ASN1_STRING_type_new(V_ASN1_T61STRING)
  512. #define M_ASN1_T61STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
  513. #define M_i2d_ASN1_T61STRING(a,pp) \
  514. i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_T61STRING,\
  515. V_ASN1_UNIVERSAL)
  516. #define M_d2i_ASN1_T61STRING(a,pp,l) \
  517. (ASN1_T61STRING *)d2i_ASN1_type_bytes\
  518. ((ASN1_STRING **)a,pp,l,B_ASN1_T61STRING)
  519. #define M_ASN1_IA5STRING_new() (ASN1_IA5STRING *)\
  520. ASN1_STRING_type_new(V_ASN1_IA5STRING)
  521. #define M_ASN1_IA5STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
  522. #define M_ASN1_IA5STRING_dup(a) \
  523. (ASN1_IA5STRING *)ASN1_STRING_dup((ASN1_STRING *)a)
  524. #define M_i2d_ASN1_IA5STRING(a,pp) \
  525. i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\
  526. V_ASN1_UNIVERSAL)
  527. #define M_d2i_ASN1_IA5STRING(a,pp,l) \
  528. (ASN1_IA5STRING *)d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l,\
  529. B_ASN1_IA5STRING)
  530. #define M_ASN1_UTCTIME_new() (ASN1_UTCTIME *)\
  531. ASN1_STRING_type_new(V_ASN1_UTCTIME)
  532. #define M_ASN1_UTCTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
  533. #define M_ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup((ASN1_STRING *)a)
  534. #define M_ASN1_GENERALIZEDTIME_new() (ASN1_GENERALIZEDTIME *)\
  535. ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME)
  536. #define M_ASN1_GENERALIZEDTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
  537. #define M_ASN1_GENERALIZEDTIME_dup(a) (ASN1_GENERALIZEDTIME *)ASN1_STRING_dup(\
  538. (ASN1_STRING *)a)
  539. #define M_ASN1_TIME_new() (ASN1_TIME *)\
  540. ASN1_STRING_type_new(V_ASN1_UTCTIME)
  541. #define M_ASN1_TIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
  542. #define M_ASN1_TIME_dup(a) (ASN1_TIME *)ASN1_STRING_dup((ASN1_STRING *)a)
  543. #define M_ASN1_GENERALSTRING_new() (ASN1_GENERALSTRING *)\
  544. ASN1_STRING_type_new(V_ASN1_GENERALSTRING)
  545. #define M_ASN1_GENERALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
  546. #define M_i2d_ASN1_GENERALSTRING(a,pp) \
  547. i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_GENERALSTRING,\
  548. V_ASN1_UNIVERSAL)
  549. #define M_d2i_ASN1_GENERALSTRING(a,pp,l) \
  550. (ASN1_GENERALSTRING *)d2i_ASN1_type_bytes\
  551. ((ASN1_STRING **)a,pp,l,B_ASN1_GENERALSTRING)
  552. #define M_ASN1_UNIVERSALSTRING_new() (ASN1_UNIVERSALSTRING *)\
  553. ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING)
  554. #define M_ASN1_UNIVERSALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
  555. #define M_i2d_ASN1_UNIVERSALSTRING(a,pp) \
  556. i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UNIVERSALSTRING,\
  557. V_ASN1_UNIVERSAL)
  558. #define M_d2i_ASN1_UNIVERSALSTRING(a,pp,l) \
  559. (ASN1_UNIVERSALSTRING *)d2i_ASN1_type_bytes\
  560. ((ASN1_STRING **)a,pp,l,B_ASN1_UNIVERSALSTRING)
  561. #define M_ASN1_BMPSTRING_new() (ASN1_BMPSTRING *)\
  562. ASN1_STRING_type_new(V_ASN1_BMPSTRING)
  563. #define M_ASN1_BMPSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
  564. #define M_i2d_ASN1_BMPSTRING(a,pp) \
  565. i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_BMPSTRING,\
  566. V_ASN1_UNIVERSAL)
  567. #define M_d2i_ASN1_BMPSTRING(a,pp,l) \
  568. (ASN1_BMPSTRING *)d2i_ASN1_type_bytes\
  569. ((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING)
  570. #define M_ASN1_VISIBLESTRING_new() (ASN1_VISIBLESTRING *)\
  571. ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
  572. #define M_ASN1_VISIBLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
  573. #define M_i2d_ASN1_VISIBLESTRING(a,pp) \
  574. i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_VISIBLESTRING,\
  575. V_ASN1_UNIVERSAL)
  576. #define M_d2i_ASN1_VISIBLESTRING(a,pp,l) \
  577. (ASN1_VISIBLESTRING *)d2i_ASN1_type_bytes\
  578. ((ASN1_STRING **)a,pp,l,B_ASN1_VISIBLESTRING)
  579. #define M_ASN1_UTF8STRING_new() (ASN1_UTF8STRING *)\
  580. ASN1_STRING_type_new(V_ASN1_UTF8STRING)
  581. #define M_ASN1_UTF8STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
  582. #define M_i2d_ASN1_UTF8STRING(a,pp) \
  583. i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UTF8STRING,\
  584. V_ASN1_UNIVERSAL)
  585. #define M_d2i_ASN1_UTF8STRING(a,pp,l) \
  586. (ASN1_UTF8STRING *)d2i_ASN1_type_bytes\
  587. ((ASN1_STRING **)a,pp,l,B_ASN1_UTF8STRING)
  588. /* for the is_set parameter to i2d_ASN1_SET */
  589. #define IS_SEQUENCE 0
  590. #define IS_SET 1
  591. DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
  592. int ASN1_TYPE_get(ASN1_TYPE *a);
  593. void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);
  594. ASN1_OBJECT * ASN1_OBJECT_new(void );
  595. void ASN1_OBJECT_free(ASN1_OBJECT *a);
  596. int i2d_ASN1_OBJECT(ASN1_OBJECT *a,unsigned char **pp);
  597. ASN1_OBJECT * c2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp,
  598. long length);
  599. ASN1_OBJECT * d2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp,
  600. long length);
  601. DECLARE_ASN1_ITEM(ASN1_OBJECT)
  602. DECLARE_STACK_OF(ASN1_OBJECT)
  603. DECLARE_ASN1_SET_OF(ASN1_OBJECT)
  604. ASN1_STRING * ASN1_STRING_new(void);
  605. void ASN1_STRING_free(ASN1_STRING *a);
  606. ASN1_STRING * ASN1_STRING_dup(ASN1_STRING *a);
  607. ASN1_STRING * ASN1_STRING_type_new(int type );
  608. int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b);
  609. /* Since this is used to store all sorts of things, via macros, for now, make
  610. its data void * */
  611. int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len);
  612. int ASN1_STRING_length(ASN1_STRING *x);
  613. void ASN1_STRING_length_set(ASN1_STRING *x, int n);
  614. int ASN1_STRING_type(ASN1_STRING *x);
  615. unsigned char * ASN1_STRING_data(ASN1_STRING *x);
  616. DECLARE_ASN1_FUNCTIONS(ASN1_BIT_STRING)
  617. int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp);
  618. ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,unsigned char **pp,
  619. long length);
  620. int ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d,
  621. int length );
  622. int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value);
  623. int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n);
  624. #ifndef OPENSSL_NO_BIO
  625. int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
  626. BIT_STRING_BITNAME *tbl, int indent);
  627. #endif
  628. int ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl);
  629. int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value,
  630. BIT_STRING_BITNAME *tbl);
  631. int i2d_ASN1_BOOLEAN(int a,unsigned char **pp);
  632. int d2i_ASN1_BOOLEAN(int *a,unsigned char **pp,long length);
  633. DECLARE_ASN1_FUNCTIONS(ASN1_INTEGER)
  634. int i2c_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp);
  635. ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp,
  636. long length);
  637. ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a,unsigned char **pp,
  638. long length);
  639. ASN1_INTEGER * ASN1_INTEGER_dup(ASN1_INTEGER *x);
  640. int ASN1_INTEGER_cmp(ASN1_INTEGER *x, ASN1_INTEGER *y);
  641. DECLARE_ASN1_FUNCTIONS(ASN1_ENUMERATED)
  642. int ASN1_UTCTIME_check(ASN1_UTCTIME *a);
  643. ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t);
  644. int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, char *str);
  645. int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t);
  646. #if 0
  647. time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s);
  648. #endif
  649. int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *a);
  650. ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,time_t t);
  651. int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, char *str);
  652. DECLARE_ASN1_FUNCTIONS(ASN1_OCTET_STRING)
  653. ASN1_OCTET_STRING * ASN1_OCTET_STRING_dup(ASN1_OCTET_STRING *a);
  654. int ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b);
  655. int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, unsigned char *data, int len);
  656. DECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING)
  657. DECLARE_ASN1_FUNCTIONS(ASN1_UTF8STRING)
  658. DECLARE_ASN1_FUNCTIONS(ASN1_NULL)
  659. DECLARE_ASN1_FUNCTIONS(ASN1_BMPSTRING)
  660. int UTF8_getc(const unsigned char *str, int len, unsigned long *val);
  661. int UTF8_putc(unsigned char *str, int len, unsigned long value);
  662. DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE)
  663. DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING)
  664. DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT)
  665. DECLARE_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING)
  666. DECLARE_ASN1_FUNCTIONS(ASN1_T61STRING)
  667. DECLARE_ASN1_FUNCTIONS(ASN1_IA5STRING)
  668. DECLARE_ASN1_FUNCTIONS(ASN1_GENERALSTRING)
  669. DECLARE_ASN1_FUNCTIONS(ASN1_UTCTIME)
  670. DECLARE_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME)
  671. DECLARE_ASN1_FUNCTIONS(ASN1_TIME)
  672. ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t);
  673. int ASN1_TIME_check(ASN1_TIME *t);
  674. ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out);
  675. int i2d_ASN1_SET(STACK *a, unsigned char **pp,
  676. int (*func)(), int ex_tag, int ex_class, int is_set);
  677. STACK * d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
  678. char *(*func)(), void (*free_func)(void *),
  679. int ex_tag, int ex_class);
  680. #ifndef OPENSSL_NO_BIO
  681. int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a);
  682. int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size);
  683. int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a);
  684. int a2i_ASN1_ENUMERATED(BIO *bp,ASN1_ENUMERATED *bs,char *buf,int size);
  685. int i2a_ASN1_OBJECT(BIO *bp,ASN1_OBJECT *a);
  686. int a2i_ASN1_STRING(BIO *bp,ASN1_STRING *bs,char *buf,int size);
  687. int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type);
  688. #endif
  689. int i2t_ASN1_OBJECT(char *buf,int buf_len,ASN1_OBJECT *a);
  690. int a2d_ASN1_OBJECT(unsigned char *out,int olen, const char *buf, int num);
  691. ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data,int len,
  692. const char *sn, const char *ln);
  693. int ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
  694. long ASN1_INTEGER_get(ASN1_INTEGER *a);
  695. ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai);
  696. BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn);
  697. int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v);
  698. long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a);
  699. ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai);
  700. BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai,BIGNUM *bn);
  701. /* General */
  702. /* given a string, return the correct type, max is the maximum length */
  703. int ASN1_PRINTABLE_type(unsigned char *s, int max);
  704. int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass);
  705. ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp,
  706. long length, int Ptag, int Pclass);
  707. unsigned long ASN1_tag2bit(int tag);
  708. /* type is one or more of the B_ASN1_ values. */
  709. ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a,unsigned char **pp,
  710. long length,int type);
  711. /* PARSING */
  712. int asn1_Finish(ASN1_CTX *c);
  713. /* SPECIALS */
  714. int ASN1_get_object(unsigned char **pp, long *plength, int *ptag,
  715. int *pclass, long omax);
  716. int ASN1_check_infinite_end(unsigned char **p,long len);
  717. void ASN1_put_object(unsigned char **pp, int constructed, int length,
  718. int tag, int xclass);
  719. int ASN1_object_size(int constructed, int length, int tag);
  720. /* Used to implement other functions */
  721. char *ASN1_dup(int (*i2d)(),char *(*d2i)(),char *x);
  722. void *ASN1_item_dup(const ASN1_ITEM *it, void *x);
  723. #ifndef OPENSSL_NO_FP_API
  724. char *ASN1_d2i_fp(char *(*xnew)(),char *(*d2i)(),FILE *fp,unsigned char **x);
  725. void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x);
  726. int ASN1_i2d_fp(int (*i2d)(),FILE *out,unsigned char *x);
  727. int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x);
  728. int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags);
  729. #endif
  730. int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in);
  731. #ifndef OPENSSL_NO_BIO
  732. char *ASN1_d2i_bio(char *(*xnew)(),char *(*d2i)(),BIO *bp,unsigned char **x);
  733. void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x);
  734. int ASN1_i2d_bio(int (*i2d)(),BIO *out,unsigned char *x);
  735. int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x);
  736. int ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a);
  737. int ASN1_GENERALIZEDTIME_print(BIO *fp,ASN1_GENERALIZEDTIME *a);
  738. int ASN1_TIME_print(BIO *fp,ASN1_TIME *a);
  739. int ASN1_STRING_print(BIO *bp,ASN1_STRING *v);
  740. int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags);
  741. int ASN1_parse(BIO *bp,unsigned char *pp,long len,int indent);
  742. int ASN1_parse_dump(BIO *bp,unsigned char *pp,long len,int indent,int dump);
  743. #endif
  744. const char *ASN1_tag2str(int tag);
  745. /* Used to load and write netscape format cert/key */
  746. int i2d_ASN1_HEADER(ASN1_HEADER *a,unsigned char **pp);
  747. ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a,unsigned char **pp, long length);
  748. ASN1_HEADER *ASN1_HEADER_new(void );
  749. void ASN1_HEADER_free(ASN1_HEADER *a);
  750. int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s);
  751. void ERR_load_ASN1_strings(void);
  752. /* Not used that much at this point, except for the first two */
  753. ASN1_METHOD *X509_asn1_meth(void);
  754. ASN1_METHOD *RSAPrivateKey_asn1_meth(void);
  755. ASN1_METHOD *ASN1_IA5STRING_asn1_meth(void);
  756. ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(void);
  757. int ASN1_TYPE_set_octetstring(ASN1_TYPE *a,
  758. unsigned char *data, int len);
  759. int ASN1_TYPE_get_octetstring(ASN1_TYPE *a,
  760. unsigned char *data, int max_len);
  761. int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num,
  762. unsigned char *data, int len);
  763. int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num,
  764. unsigned char *data, int max_len);
  765. STACK *ASN1_seq_unpack(unsigned char *buf, int len, char *(*d2i)(),
  766. void (*free_func)(void *) );
  767. unsigned char *ASN1_seq_pack(STACK *safes, int (*i2d)(), unsigned char **buf,
  768. int *len );
  769. void *ASN1_unpack_string(ASN1_STRING *oct, char *(*d2i)());
  770. void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it);
  771. ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct);
  772. ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_OCTET_STRING **oct);
  773. void ASN1_STRING_set_default_mask(unsigned long mask);
  774. int ASN1_STRING_set_default_mask_asc(char *p);
  775. unsigned long ASN1_STRING_get_default_mask(void);
  776. int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
  777. int inform, unsigned long mask);
  778. int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
  779. int inform, unsigned long mask,
  780. long minsize, long maxsize);
  781. ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out,
  782. const unsigned char *in, int inlen, int inform, int nid);
  783. ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid);
  784. int ASN1_STRING_TABLE_add(int, long, long, unsigned long, unsigned long);
  785. void ASN1_STRING_TABLE_cleanup(void);
  786. /* ASN1 template functions */
  787. /* Old API compatible functions */
  788. ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it);
  789. void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it);
  790. ASN1_VALUE * ASN1_item_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_ITEM *it);
  791. int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);
  792. /* BEGIN ERROR CODES */
  793. /* The following lines are auto generated by the script mkerr.pl. Any changes
  794. * made after this point may be overwritten when the script is next run.
  795. */
  796. /* Error codes for the ASN1 functions. */
  797. /* Function codes. */
  798. #define ASN1_F_A2D_ASN1_OBJECT 100
  799. #define ASN1_F_A2I_ASN1_ENUMERATED 101
  800. #define ASN1_F_A2I_ASN1_INTEGER 102
  801. #define ASN1_F_A2I_ASN1_STRING 103
  802. #define ASN1_F_ASN1_CHECK_TLEN 104
  803. #define ASN1_F_ASN1_COLLATE_PRIMITIVE 105
  804. #define ASN1_F_ASN1_COLLECT 106
  805. #define ASN1_F_ASN1_D2I_BIO 107
  806. #define ASN1_F_ASN1_D2I_EX_PRIMITIVE 108
  807. #define ASN1_F_ASN1_D2I_FP 109
  808. #define ASN1_F_ASN1_DO_ADB 110
  809. #define ASN1_F_ASN1_DUP 111
  810. #define ASN1_F_ASN1_ENUMERATED_SET 112
  811. #define ASN1_F_ASN1_ENUMERATED_TO_BN 113
  812. #define ASN1_F_ASN1_GET_OBJECT 114
  813. #define ASN1_F_ASN1_HEADER_NEW 115
  814. #define ASN1_F_ASN1_I2D_BIO 116
  815. #define ASN1_F_ASN1_I2D_FP 117
  816. #define ASN1_F_ASN1_INTEGER_SET 118
  817. #define ASN1_F_ASN1_INTEGER_TO_BN 119
  818. #define ASN1_F_ASN1_ITEM_EX_D2I 120
  819. #define ASN1_F_ASN1_ITEM_NEW 121
  820. #define ASN1_F_ASN1_MBSTRING_COPY 122
  821. #define ASN1_F_ASN1_OBJECT_NEW 123
  822. #define ASN1_F_ASN1_PACK_STRING 124
  823. #define ASN1_F_ASN1_PBE_SET 125
  824. #define ASN1_F_ASN1_SEQ_PACK 126
  825. #define ASN1_F_ASN1_SEQ_UNPACK 127
  826. #define ASN1_F_ASN1_SIGN 128
  827. #define ASN1_F_ASN1_STRING_TABLE_ADD 129
  828. #define ASN1_F_ASN1_STRING_TYPE_NEW 130
  829. #define ASN1_F_ASN1_TEMPLATE_D2I 131
  830. #define ASN1_F_ASN1_TEMPLATE_EX_D2I 132
  831. #define ASN1_F_ASN1_TEMPLATE_NEW 133
  832. #define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 134
  833. #define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 135
  834. #define ASN1_F_ASN1_UNPACK_STRING 136
  835. #define ASN1_F_ASN1_VERIFY 137
  836. #define ASN1_F_BN_TO_ASN1_ENUMERATED 138
  837. #define ASN1_F_BN_TO_ASN1_INTEGER 139
  838. #define ASN1_F_COLLECT_DATA 140
  839. #define ASN1_F_D2I_ASN1_BIT_STRING 141
  840. #define ASN1_F_D2I_ASN1_BOOLEAN 142
  841. #define ASN1_F_D2I_ASN1_BYTES 143
  842. #define ASN1_F_D2I_ASN1_GENERALIZEDTIME 144
  843. #define ASN1_F_D2I_ASN1_HEADER 145
  844. #define ASN1_F_D2I_ASN1_INTEGER 146
  845. #define ASN1_F_D2I_ASN1_OBJECT 147
  846. #define ASN1_F_D2I_ASN1_SET 148
  847. #define ASN1_F_D2I_ASN1_TYPE_BYTES 149
  848. #define ASN1_F_D2I_ASN1_UINTEGER 150
  849. #define ASN1_F_D2I_ASN1_UTCTIME 151
  850. #define ASN1_F_D2I_NETSCAPE_RSA 152
  851. #define ASN1_F_D2I_NETSCAPE_RSA_2 153
  852. #define ASN1_F_D2I_PRIVATEKEY 154
  853. #define ASN1_F_D2I_PUBLICKEY 155
  854. #define ASN1_F_D2I_X509 156
  855. #define ASN1_F_D2I_X509_CINF 157
  856. #define ASN1_F_D2I_X509_NAME 158
  857. #define ASN1_F_D2I_X509_PKEY 159
  858. #define ASN1_F_I2D_ASN1_TIME 160
  859. #define ASN1_F_I2D_DSA_PUBKEY 161
  860. #define ASN1_F_I2D_NETSCAPE_RSA 162
  861. #define ASN1_F_I2D_PRIVATEKEY 163
  862. #define ASN1_F_I2D_PUBLICKEY 164
  863. #define ASN1_F_I2D_RSA_PUBKEY 165
  864. #define ASN1_F_LONG_C2I 166
  865. #define ASN1_F_PKCS5_PBE2_SET 167
  866. #define ASN1_F_X509_CINF_NEW 168
  867. #define ASN1_F_X509_CRL_ADD0_REVOKED 169
  868. #define ASN1_F_X509_INFO_NEW 170
  869. #define ASN1_F_X509_NAME_NEW 171
  870. #define ASN1_F_X509_NEW 172
  871. #define ASN1_F_X509_PKEY_NEW 173
  872. /* Reason codes. */
  873. #define ASN1_R_AUX_ERROR 100
  874. #define ASN1_R_BAD_CLASS 101
  875. #define ASN1_R_BAD_OBJECT_HEADER 102
  876. #define ASN1_R_BAD_PASSWORD_READ 103
  877. #define ASN1_R_BAD_TAG 104
  878. #define ASN1_R_BN_LIB 105
  879. #define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 106
  880. #define ASN1_R_BUFFER_TOO_SMALL 107
  881. #define ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER 108
  882. #define ASN1_R_DATA_IS_WRONG 109
  883. #define ASN1_R_DECODE_ERROR 110
  884. #define ASN1_R_DECODING_ERROR 111
  885. #define ASN1_R_ENCODE_ERROR 112
  886. #define ASN1_R_ERROR_PARSING_SET_ELEMENT 113
  887. #define ASN1_R_ERROR_SETTING_CIPHER_PARAMS 114
  888. #define ASN1_R_EXPECTING_AN_INTEGER 115
  889. #define ASN1_R_EXPECTING_AN_OBJECT 116
  890. #define ASN1_R_EXPECTING_A_BOOLEAN 117
  891. #define ASN1_R_EXPECTING_A_TIME 118
  892. #define ASN1_R_EXPLICIT_LENGTH_MISMATCH 119
  893. #define ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED 120
  894. #define ASN1_R_FIELD_MISSING 121
  895. #define ASN1_R_FIRST_NUM_TOO_LARGE 122
  896. #define ASN1_R_HEADER_TOO_LONG 123
  897. #define ASN1_R_ILLEGAL_CHARACTERS 124
  898. #define ASN1_R_ILLEGAL_NULL 125
  899. #define ASN1_R_ILLEGAL_OPTIONAL_ANY 126
  900. #define ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE 170
  901. #define ASN1_R_ILLEGAL_TAGGED_ANY 127
  902. #define ASN1_R_INTEGER_TOO_LARGE_FOR_LONG 128
  903. #define ASN1_R_INVALID_BMPSTRING_LENGTH 129
  904. #define ASN1_R_INVALID_DIGIT 130
  905. #define ASN1_R_INVALID_SEPARATOR 131
  906. #define ASN1_R_INVALID_TIME_FORMAT 132
  907. #define ASN1_R_INVALID_UNIVERSALSTRING_LENGTH 133
  908. #define ASN1_R_INVALID_UTF8STRING 134
  909. #define ASN1_R_IV_TOO_LARGE 135
  910. #define ASN1_R_LENGTH_ERROR 136
  911. #define ASN1_R_MISSING_EOC 137
  912. #define ASN1_R_MISSING_SECOND_NUMBER 138
  913. #define ASN1_R_MSTRING_NOT_UNIVERSAL 139
  914. #define ASN1_R_MSTRING_WRONG_TAG 140
  915. #define ASN1_R_NON_HEX_CHARACTERS 141
  916. #define ASN1_R_NOT_ENOUGH_DATA 142
  917. #define ASN1_R_NO_MATCHING_CHOICE_TYPE 143
  918. #define ASN1_R_NULL_IS_WRONG_LENGTH 144
  919. #define ASN1_R_ODD_NUMBER_OF_CHARS 145
  920. #define ASN1_R_PRIVATE_KEY_HEADER_MISSING 146
  921. #define ASN1_R_SECOND_NUMBER_TOO_LARGE 147
  922. #define ASN1_R_SEQUENCE_LENGTH_MISMATCH 148
  923. #define ASN1_R_SEQUENCE_NOT_CONSTRUCTED 149
  924. #define ASN1_R_SHORT_LINE 150
  925. #define ASN1_R_STRING_TOO_LONG 151
  926. #define ASN1_R_STRING_TOO_SHORT 152
  927. #define ASN1_R_TAG_VALUE_TOO_HIGH 153
  928. #define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 154
  929. #define ASN1_R_TOO_LONG 155
  930. #define ASN1_R_TYPE_NOT_CONSTRUCTED 156
  931. #define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 157
  932. #define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 158
  933. #define ASN1_R_UNEXPECTED_EOC 159
  934. #define ASN1_R_UNKNOWN_FORMAT 160
  935. #define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 161
  936. #define ASN1_R_UNKNOWN_OBJECT_TYPE 162
  937. #define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 163
  938. #define ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE 164
  939. #define ASN1_R_UNSUPPORTED_CIPHER 165
  940. #define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 166
  941. #define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 167
  942. #define ASN1_R_WRONG_TAG 168
  943. #define ASN1_R_WRONG_TYPE 169
  944. #ifdef __cplusplus
  945. }
  946. #endif
  947. #endif