asn1.h.in 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964
  1. /*
  2. * {- join("\n * ", @autowarntext) -}
  3. *
  4. * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
  5. *
  6. * Licensed under the Apache License 2.0 (the "License"). You may not use
  7. * this file except in compliance with the License. You can obtain a copy
  8. * in the file LICENSE in the source distribution or at
  9. * https://www.openssl.org/source/license.html
  10. */
  11. {-
  12. use OpenSSL::stackhash qw(generate_stack_macros);
  13. -}
  14. #ifndef OPENSSL_ASN1_H
  15. # define OPENSSL_ASN1_H
  16. # pragma once
  17. # include <openssl/macros.h>
  18. # ifndef OPENSSL_NO_DEPRECATED_3_0
  19. # define HEADER_ASN1_H
  20. # endif
  21. # ifndef OPENSSL_NO_STDIO
  22. # include <stdio.h>
  23. # endif
  24. # include <time.h>
  25. # include <openssl/e_os2.h>
  26. # include <openssl/opensslconf.h>
  27. # include <openssl/bio.h>
  28. # include <openssl/safestack.h>
  29. # include <openssl/asn1err.h>
  30. # include <openssl/symhacks.h>
  31. # include <openssl/types.h>
  32. # include <openssl/bn.h>
  33. # ifdef OPENSSL_BUILD_SHLIBCRYPTO
  34. # undef OPENSSL_EXTERN
  35. # define OPENSSL_EXTERN OPENSSL_EXPORT
  36. # endif
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. # define V_ASN1_UNIVERSAL 0x00
  41. # define V_ASN1_APPLICATION 0x40
  42. # define V_ASN1_CONTEXT_SPECIFIC 0x80
  43. # define V_ASN1_PRIVATE 0xc0
  44. # define V_ASN1_CONSTRUCTED 0x20
  45. # define V_ASN1_PRIMITIVE_TAG 0x1f
  46. # define V_ASN1_PRIMATIVE_TAG /*compat*/ V_ASN1_PRIMITIVE_TAG
  47. # define V_ASN1_APP_CHOOSE -2/* let the recipient choose */
  48. # define V_ASN1_OTHER -3/* used in ASN1_TYPE */
  49. # define V_ASN1_ANY -4/* used in ASN1 template code */
  50. # define V_ASN1_UNDEF -1
  51. /* ASN.1 tag values */
  52. # define V_ASN1_EOC 0
  53. # define V_ASN1_BOOLEAN 1 /**/
  54. # define V_ASN1_INTEGER 2
  55. # define V_ASN1_BIT_STRING 3
  56. # define V_ASN1_OCTET_STRING 4
  57. # define V_ASN1_NULL 5
  58. # define V_ASN1_OBJECT 6
  59. # define V_ASN1_OBJECT_DESCRIPTOR 7
  60. # define V_ASN1_EXTERNAL 8
  61. # define V_ASN1_REAL 9
  62. # define V_ASN1_ENUMERATED 10
  63. # define V_ASN1_UTF8STRING 12
  64. # define V_ASN1_SEQUENCE 16
  65. # define V_ASN1_SET 17
  66. # define V_ASN1_NUMERICSTRING 18 /**/
  67. # define V_ASN1_PRINTABLESTRING 19
  68. # define V_ASN1_T61STRING 20
  69. # define V_ASN1_TELETEXSTRING 20/* alias */
  70. # define V_ASN1_VIDEOTEXSTRING 21 /**/
  71. # define V_ASN1_IA5STRING 22
  72. # define V_ASN1_UTCTIME 23
  73. # define V_ASN1_GENERALIZEDTIME 24 /**/
  74. # define V_ASN1_GRAPHICSTRING 25 /**/
  75. # define V_ASN1_ISO64STRING 26 /**/
  76. # define V_ASN1_VISIBLESTRING 26/* alias */
  77. # define V_ASN1_GENERALSTRING 27 /**/
  78. # define V_ASN1_UNIVERSALSTRING 28 /**/
  79. # define V_ASN1_BMPSTRING 30
  80. /*
  81. * NB the constants below are used internally by ASN1_INTEGER
  82. * and ASN1_ENUMERATED to indicate the sign. They are *not* on
  83. * the wire tag values.
  84. */
  85. # define V_ASN1_NEG 0x100
  86. # define V_ASN1_NEG_INTEGER (2 | V_ASN1_NEG)
  87. # define V_ASN1_NEG_ENUMERATED (10 | V_ASN1_NEG)
  88. /* For use with d2i_ASN1_type_bytes() */
  89. # define B_ASN1_NUMERICSTRING 0x0001
  90. # define B_ASN1_PRINTABLESTRING 0x0002
  91. # define B_ASN1_T61STRING 0x0004
  92. # define B_ASN1_TELETEXSTRING 0x0004
  93. # define B_ASN1_VIDEOTEXSTRING 0x0008
  94. # define B_ASN1_IA5STRING 0x0010
  95. # define B_ASN1_GRAPHICSTRING 0x0020
  96. # define B_ASN1_ISO64STRING 0x0040
  97. # define B_ASN1_VISIBLESTRING 0x0040
  98. # define B_ASN1_GENERALSTRING 0x0080
  99. # define B_ASN1_UNIVERSALSTRING 0x0100
  100. # define B_ASN1_OCTET_STRING 0x0200
  101. # define B_ASN1_BIT_STRING 0x0400
  102. # define B_ASN1_BMPSTRING 0x0800
  103. # define B_ASN1_UNKNOWN 0x1000
  104. # define B_ASN1_UTF8STRING 0x2000
  105. # define B_ASN1_UTCTIME 0x4000
  106. # define B_ASN1_GENERALIZEDTIME 0x8000
  107. # define B_ASN1_SEQUENCE 0x10000
  108. /* For use with ASN1_mbstring_copy() */
  109. # define MBSTRING_FLAG 0x1000
  110. # define MBSTRING_UTF8 (MBSTRING_FLAG)
  111. # define MBSTRING_ASC (MBSTRING_FLAG|1)
  112. # define MBSTRING_BMP (MBSTRING_FLAG|2)
  113. # define MBSTRING_UNIV (MBSTRING_FLAG|4)
  114. # define SMIME_OLDMIME 0x400
  115. # define SMIME_CRLFEOL 0x800
  116. # define SMIME_STREAM 0x1000
  117. /* Stacks for types not otherwise defined in this header */
  118. {-
  119. generate_stack_macros("X509_ALGOR");
  120. -}
  121. # define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */
  122. /*
  123. * This indicates that the ASN1_STRING is not a real value but just a place
  124. * holder for the location where indefinite length constructed data should be
  125. * inserted in the memory buffer
  126. */
  127. # define ASN1_STRING_FLAG_NDEF 0x010
  128. /*
  129. * This flag is used by the CMS code to indicate that a string is not
  130. * complete and is a place holder for content when it had all been accessed.
  131. * The flag will be reset when content has been written to it.
  132. */
  133. # define ASN1_STRING_FLAG_CONT 0x020
  134. /*
  135. * This flag is used by ASN1 code to indicate an ASN1_STRING is an MSTRING
  136. * type.
  137. */
  138. # define ASN1_STRING_FLAG_MSTRING 0x040
  139. /* String is embedded and only content should be freed */
  140. # define ASN1_STRING_FLAG_EMBED 0x080
  141. /* String should be parsed in RFC 5280's time format */
  142. # define ASN1_STRING_FLAG_X509_TIME 0x100
  143. /* This is the base type that holds just about everything :-) */
  144. struct asn1_string_st {
  145. int length;
  146. int type;
  147. unsigned char *data;
  148. /*
  149. * The value of the following field depends on the type being held. It
  150. * is mostly being used for BIT_STRING so if the input data has a
  151. * non-zero 'unused bits' value, it will be handled correctly
  152. */
  153. long flags;
  154. };
  155. /*
  156. * ASN1_ENCODING structure: this is used to save the received encoding of an
  157. * ASN1 type. This is useful to get round problems with invalid encodings
  158. * which can break signatures.
  159. */
  160. typedef struct ASN1_ENCODING_st {
  161. unsigned char *enc; /* DER encoding */
  162. long len; /* Length of encoding */
  163. int modified; /* set to 1 if 'enc' is invalid */
  164. } ASN1_ENCODING;
  165. /* Used with ASN1 LONG type: if a long is set to this it is omitted */
  166. # define ASN1_LONG_UNDEF 0x7fffffffL
  167. # define STABLE_FLAGS_MALLOC 0x01
  168. /*
  169. * A zero passed to ASN1_STRING_TABLE_new_add for the flags is interpreted
  170. * as "don't change" and STABLE_FLAGS_MALLOC is always set. By setting
  171. * STABLE_FLAGS_MALLOC only we can clear the existing value. Use the alias
  172. * STABLE_FLAGS_CLEAR to reflect this.
  173. */
  174. # define STABLE_FLAGS_CLEAR STABLE_FLAGS_MALLOC
  175. # define STABLE_NO_MASK 0x02
  176. # define DIRSTRING_TYPE \
  177. (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)
  178. # define PKCS9STRING_TYPE (DIRSTRING_TYPE|B_ASN1_IA5STRING)
  179. struct asn1_string_table_st {
  180. int nid;
  181. long minsize;
  182. long maxsize;
  183. unsigned long mask;
  184. unsigned long flags;
  185. };
  186. {-
  187. generate_stack_macros("ASN1_STRING_TABLE");
  188. -}
  189. /* size limits: this stuff is taken straight from RFC2459 */
  190. # define ub_name 32768
  191. # define ub_common_name 64
  192. # define ub_locality_name 128
  193. # define ub_state_name 128
  194. # define ub_organization_name 64
  195. # define ub_organization_unit_name 64
  196. # define ub_title 64
  197. # define ub_email_address 128
  198. /*
  199. * Declarations for template structures: for full definitions see asn1t.h
  200. */
  201. typedef struct ASN1_TEMPLATE_st ASN1_TEMPLATE;
  202. typedef struct ASN1_TLC_st ASN1_TLC;
  203. /* This is just an opaque pointer */
  204. typedef struct ASN1_VALUE_st ASN1_VALUE;
  205. /* Declare ASN1 functions: the implement macro in in asn1t.h */
  206. /*
  207. * The mysterious 'extern' that's passed to some macros is innocuous,
  208. * and is there to quiet pre-C99 compilers that may complain about empty
  209. * arguments in macro calls.
  210. */
  211. # define DECLARE_ASN1_FUNCTIONS_attr(attr, type) \
  212. DECLARE_ASN1_FUNCTIONS_name_attr(attr, type, type)
  213. # define DECLARE_ASN1_FUNCTIONS(type) \
  214. DECLARE_ASN1_FUNCTIONS_attr(extern, type)
  215. # define DECLARE_ASN1_ALLOC_FUNCTIONS_attr(attr, type) \
  216. DECLARE_ASN1_ALLOC_FUNCTIONS_name_attr(attr, type, type)
  217. # define DECLARE_ASN1_ALLOC_FUNCTIONS(type) \
  218. DECLARE_ASN1_ALLOC_FUNCTIONS_attr(extern, type)
  219. # define DECLARE_ASN1_FUNCTIONS_name_attr(attr, type, name) \
  220. DECLARE_ASN1_ALLOC_FUNCTIONS_name_attr(attr, type, name) \
  221. DECLARE_ASN1_ENCODE_FUNCTIONS_name_attr(attr, type, name)
  222. # define DECLARE_ASN1_FUNCTIONS_name(type, name) \
  223. DECLARE_ASN1_FUNCTIONS_name_attr(extern, type, name)
  224. # define DECLARE_ASN1_ENCODE_FUNCTIONS_attr(attr, type, itname, name) \
  225. DECLARE_ASN1_ENCODE_FUNCTIONS_only_attr(attr, type, name) \
  226. DECLARE_ASN1_ITEM_attr(attr, itname)
  227. # define DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) \
  228. DECLARE_ASN1_ENCODE_FUNCTIONS_attr(extern, type, itname, name)
  229. # define DECLARE_ASN1_ENCODE_FUNCTIONS_name_attr(attr, type, name) \
  230. DECLARE_ASN1_ENCODE_FUNCTIONS_attr(attr, type, name, name)
  231. # define DECLARE_ASN1_ENCODE_FUNCTIONS_name(type, name) \
  232. DECLARE_ASN1_ENCODE_FUNCTIONS_name_attr(extern, type, name)
  233. # define DECLARE_ASN1_ENCODE_FUNCTIONS_only_attr(attr, type, name) \
  234. attr type *d2i_##name(type **a, const unsigned char **in, long len); \
  235. attr int i2d_##name(const type *a, unsigned char **out);
  236. # define DECLARE_ASN1_ENCODE_FUNCTIONS_only(type, name) \
  237. DECLARE_ASN1_ENCODE_FUNCTIONS_only_attr(extern, type, name)
  238. # define DECLARE_ASN1_NDEF_FUNCTION_attr(attr, name) \
  239. attr int i2d_##name##_NDEF(const name *a, unsigned char **out);
  240. # define DECLARE_ASN1_NDEF_FUNCTION(name) \
  241. DECLARE_ASN1_NDEF_FUNCTION_attr(extern, name)
  242. # define DECLARE_ASN1_ALLOC_FUNCTIONS_name_attr(attr, type, name) \
  243. attr type *name##_new(void); \
  244. attr void name##_free(type *a);
  245. # define DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \
  246. DECLARE_ASN1_ALLOC_FUNCTIONS_name_attr(extern, type, name)
  247. # define DECLARE_ASN1_DUP_FUNCTION_attr(attr, type) \
  248. DECLARE_ASN1_DUP_FUNCTION_name_attr(attr, type, type)
  249. # define DECLARE_ASN1_DUP_FUNCTION(type) \
  250. DECLARE_ASN1_DUP_FUNCTION_attr(extern, type)
  251. # define DECLARE_ASN1_DUP_FUNCTION_name_attr(attr, type, name) \
  252. attr type *name##_dup(const type *a);
  253. # define DECLARE_ASN1_DUP_FUNCTION_name(type, name) \
  254. DECLARE_ASN1_DUP_FUNCTION_name_attr(extern, type, name)
  255. # define DECLARE_ASN1_PRINT_FUNCTION_attr(attr, stname) \
  256. DECLARE_ASN1_PRINT_FUNCTION_fname_attr(attr, stname, stname)
  257. # define DECLARE_ASN1_PRINT_FUNCTION(stname) \
  258. DECLARE_ASN1_PRINT_FUNCTION_attr(extern, stname)
  259. # define DECLARE_ASN1_PRINT_FUNCTION_fname_attr(attr, stname, fname) \
  260. attr int fname##_print_ctx(BIO *out, const stname *x, int indent, \
  261. const ASN1_PCTX *pctx);
  262. # define DECLARE_ASN1_PRINT_FUNCTION_fname(stname, fname) \
  263. DECLARE_ASN1_PRINT_FUNCTION_fname_attr(extern, stname, fname)
  264. # define D2I_OF(type) type *(*)(type **,const unsigned char **,long)
  265. # define I2D_OF(type) int (*)(const type *,unsigned char **)
  266. # define CHECKED_D2I_OF(type, d2i) \
  267. ((d2i_of_void*) (1 ? d2i : ((D2I_OF(type))0)))
  268. # define CHECKED_I2D_OF(type, i2d) \
  269. ((i2d_of_void*) (1 ? i2d : ((I2D_OF(type))0)))
  270. # define CHECKED_NEW_OF(type, xnew) \
  271. ((void *(*)(void)) (1 ? xnew : ((type *(*)(void))0)))
  272. # define CHECKED_PTR_OF(type, p) \
  273. ((void*) (1 ? p : (type*)0))
  274. # define CHECKED_PPTR_OF(type, p) \
  275. ((void**) (1 ? p : (type**)0))
  276. # define TYPEDEF_D2I_OF(type) typedef type *d2i_of_##type(type **,const unsigned char **,long)
  277. # define TYPEDEF_I2D_OF(type) typedef int i2d_of_##type(const type *,unsigned char **)
  278. # define TYPEDEF_D2I2D_OF(type) TYPEDEF_D2I_OF(type); TYPEDEF_I2D_OF(type)
  279. typedef void *d2i_of_void(void **, const unsigned char **, long);
  280. typedef int i2d_of_void(const void *, unsigned char **);
  281. /*-
  282. * The following macros and typedefs allow an ASN1_ITEM
  283. * to be embedded in a structure and referenced. Since
  284. * the ASN1_ITEM pointers need to be globally accessible
  285. * (possibly from shared libraries) they may exist in
  286. * different forms. On platforms that support it the
  287. * ASN1_ITEM structure itself will be globally exported.
  288. * Other platforms will export a function that returns
  289. * an ASN1_ITEM pointer.
  290. *
  291. * To handle both cases transparently the macros below
  292. * should be used instead of hard coding an ASN1_ITEM
  293. * pointer in a structure.
  294. *
  295. * The structure will look like this:
  296. *
  297. * typedef struct SOMETHING_st {
  298. * ...
  299. * ASN1_ITEM_EXP *iptr;
  300. * ...
  301. * } SOMETHING;
  302. *
  303. * It would be initialised as e.g.:
  304. *
  305. * SOMETHING somevar = {...,ASN1_ITEM_ref(X509),...};
  306. *
  307. * and the actual pointer extracted with:
  308. *
  309. * const ASN1_ITEM *it = ASN1_ITEM_ptr(somevar.iptr);
  310. *
  311. * Finally an ASN1_ITEM pointer can be extracted from an
  312. * appropriate reference with: ASN1_ITEM_rptr(X509). This
  313. * would be used when a function takes an ASN1_ITEM * argument.
  314. *
  315. */
  316. /*
  317. * Platforms that can't easily handle shared global variables are declared as
  318. * functions returning ASN1_ITEM pointers.
  319. */
  320. /* ASN1_ITEM pointer exported type */
  321. typedef const ASN1_ITEM *ASN1_ITEM_EXP (void);
  322. /* Macro to obtain ASN1_ITEM pointer from exported type */
  323. # define ASN1_ITEM_ptr(iptr) (iptr())
  324. /* Macro to include ASN1_ITEM pointer from base type */
  325. # define ASN1_ITEM_ref(iptr) (iptr##_it)
  326. # define ASN1_ITEM_rptr(ref) (ref##_it())
  327. # define DECLARE_ASN1_ITEM_attr(attr, name) \
  328. attr const ASN1_ITEM * name##_it(void);
  329. # define DECLARE_ASN1_ITEM(name) \
  330. DECLARE_ASN1_ITEM_attr(extern, name)
  331. /* Parameters used by ASN1_STRING_print_ex() */
  332. /*
  333. * These determine which characters to escape: RFC2253 special characters,
  334. * control characters and MSB set characters
  335. */
  336. # define ASN1_STRFLGS_ESC_2253 1
  337. # define ASN1_STRFLGS_ESC_CTRL 2
  338. # define ASN1_STRFLGS_ESC_MSB 4
  339. /* Lower 8 bits are reserved as an output type specifier */
  340. # define ASN1_DTFLGS_TYPE_MASK 0x0FUL
  341. # define ASN1_DTFLGS_RFC822 0x00UL
  342. # define ASN1_DTFLGS_ISO8601 0x01UL
  343. /*
  344. * This flag determines how we do escaping: normally RC2253 backslash only,
  345. * set this to use backslash and quote.
  346. */
  347. # define ASN1_STRFLGS_ESC_QUOTE 8
  348. /* These three flags are internal use only. */
  349. /* Character is a valid PrintableString character */
  350. # define CHARTYPE_PRINTABLESTRING 0x10
  351. /* Character needs escaping if it is the first character */
  352. # define CHARTYPE_FIRST_ESC_2253 0x20
  353. /* Character needs escaping if it is the last character */
  354. # define CHARTYPE_LAST_ESC_2253 0x40
  355. /*
  356. * NB the internal flags are safely reused below by flags handled at the top
  357. * level.
  358. */
  359. /*
  360. * If this is set we convert all character strings to UTF8 first
  361. */
  362. # define ASN1_STRFLGS_UTF8_CONVERT 0x10
  363. /*
  364. * If this is set we don't attempt to interpret content: just assume all
  365. * strings are 1 byte per character. This will produce some pretty odd
  366. * looking output!
  367. */
  368. # define ASN1_STRFLGS_IGNORE_TYPE 0x20
  369. /* If this is set we include the string type in the output */
  370. # define ASN1_STRFLGS_SHOW_TYPE 0x40
  371. /*
  372. * This determines which strings to display and which to 'dump' (hex dump of
  373. * content octets or DER encoding). We can only dump non character strings or
  374. * everything. If we don't dump 'unknown' they are interpreted as character
  375. * strings with 1 octet per character and are subject to the usual escaping
  376. * options.
  377. */
  378. # define ASN1_STRFLGS_DUMP_ALL 0x80
  379. # define ASN1_STRFLGS_DUMP_UNKNOWN 0x100
  380. /*
  381. * These determine what 'dumping' does, we can dump the content octets or the
  382. * DER encoding: both use the RFC2253 #XXXXX notation.
  383. */
  384. # define ASN1_STRFLGS_DUMP_DER 0x200
  385. /*
  386. * This flag specifies that RC2254 escaping shall be performed.
  387. */
  388. #define ASN1_STRFLGS_ESC_2254 0x400
  389. /*
  390. * All the string flags consistent with RFC2253, escaping control characters
  391. * isn't essential in RFC2253 but it is advisable anyway.
  392. */
  393. # define ASN1_STRFLGS_RFC2253 (ASN1_STRFLGS_ESC_2253 | \
  394. ASN1_STRFLGS_ESC_CTRL | \
  395. ASN1_STRFLGS_ESC_MSB | \
  396. ASN1_STRFLGS_UTF8_CONVERT | \
  397. ASN1_STRFLGS_DUMP_UNKNOWN | \
  398. ASN1_STRFLGS_DUMP_DER)
  399. struct asn1_type_st {
  400. int type;
  401. union {
  402. char *ptr;
  403. ASN1_BOOLEAN boolean;
  404. ASN1_STRING *asn1_string;
  405. ASN1_OBJECT *object;
  406. ASN1_INTEGER *integer;
  407. ASN1_ENUMERATED *enumerated;
  408. ASN1_BIT_STRING *bit_string;
  409. ASN1_OCTET_STRING *octet_string;
  410. ASN1_PRINTABLESTRING *printablestring;
  411. ASN1_T61STRING *t61string;
  412. ASN1_IA5STRING *ia5string;
  413. ASN1_GENERALSTRING *generalstring;
  414. ASN1_BMPSTRING *bmpstring;
  415. ASN1_UNIVERSALSTRING *universalstring;
  416. ASN1_UTCTIME *utctime;
  417. ASN1_GENERALIZEDTIME *generalizedtime;
  418. ASN1_VISIBLESTRING *visiblestring;
  419. ASN1_UTF8STRING *utf8string;
  420. /*
  421. * set and sequence are left complete and still contain the set or
  422. * sequence bytes
  423. */
  424. ASN1_STRING *set;
  425. ASN1_STRING *sequence;
  426. ASN1_VALUE *asn1_value;
  427. } value;
  428. };
  429. {-
  430. generate_stack_macros("ASN1_TYPE");
  431. -}
  432. typedef STACK_OF(ASN1_TYPE) ASN1_SEQUENCE_ANY;
  433. DECLARE_ASN1_ENCODE_FUNCTIONS_name(ASN1_SEQUENCE_ANY, ASN1_SEQUENCE_ANY)
  434. DECLARE_ASN1_ENCODE_FUNCTIONS_name(ASN1_SEQUENCE_ANY, ASN1_SET_ANY)
  435. /* This is used to contain a list of bit names */
  436. typedef struct BIT_STRING_BITNAME_st {
  437. int bitnum;
  438. const char *lname;
  439. const char *sname;
  440. } BIT_STRING_BITNAME;
  441. # define B_ASN1_TIME \
  442. B_ASN1_UTCTIME | \
  443. B_ASN1_GENERALIZEDTIME
  444. # define B_ASN1_PRINTABLE \
  445. B_ASN1_NUMERICSTRING| \
  446. B_ASN1_PRINTABLESTRING| \
  447. B_ASN1_T61STRING| \
  448. B_ASN1_IA5STRING| \
  449. B_ASN1_BIT_STRING| \
  450. B_ASN1_UNIVERSALSTRING|\
  451. B_ASN1_BMPSTRING|\
  452. B_ASN1_UTF8STRING|\
  453. B_ASN1_SEQUENCE|\
  454. B_ASN1_UNKNOWN
  455. # define B_ASN1_DIRECTORYSTRING \
  456. B_ASN1_PRINTABLESTRING| \
  457. B_ASN1_TELETEXSTRING|\
  458. B_ASN1_BMPSTRING|\
  459. B_ASN1_UNIVERSALSTRING|\
  460. B_ASN1_UTF8STRING
  461. # define B_ASN1_DISPLAYTEXT \
  462. B_ASN1_IA5STRING| \
  463. B_ASN1_VISIBLESTRING| \
  464. B_ASN1_BMPSTRING|\
  465. B_ASN1_UTF8STRING
  466. DECLARE_ASN1_ALLOC_FUNCTIONS_name(ASN1_TYPE, ASN1_TYPE)
  467. DECLARE_ASN1_ENCODE_FUNCTIONS(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
  468. int ASN1_TYPE_get(const ASN1_TYPE *a);
  469. void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);
  470. int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value);
  471. int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b);
  472. ASN1_TYPE *ASN1_TYPE_pack_sequence(const ASN1_ITEM *it, void *s, ASN1_TYPE **t);
  473. void *ASN1_TYPE_unpack_sequence(const ASN1_ITEM *it, const ASN1_TYPE *t);
  474. {-
  475. generate_stack_macros("ASN1_OBJECT");
  476. -}
  477. DECLARE_ASN1_FUNCTIONS(ASN1_OBJECT)
  478. ASN1_STRING *ASN1_STRING_new(void);
  479. void ASN1_STRING_free(ASN1_STRING *a);
  480. void ASN1_STRING_clear_free(ASN1_STRING *a);
  481. int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str);
  482. DECLARE_ASN1_DUP_FUNCTION(ASN1_STRING)
  483. ASN1_STRING *ASN1_STRING_type_new(int type);
  484. int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b);
  485. /*
  486. * Since this is used to store all sorts of things, via macros, for now,
  487. * make its data void *
  488. */
  489. int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len);
  490. void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len);
  491. int ASN1_STRING_length(const ASN1_STRING *x);
  492. # ifndef OPENSSL_NO_DEPRECATED_3_0
  493. OSSL_DEPRECATEDIN_3_0 void ASN1_STRING_length_set(ASN1_STRING *x, int n);
  494. # endif
  495. int ASN1_STRING_type(const ASN1_STRING *x);
  496. # ifndef OPENSSL_NO_DEPRECATED_1_1_0
  497. OSSL_DEPRECATEDIN_1_1_0 unsigned char *ASN1_STRING_data(ASN1_STRING *x);
  498. # endif
  499. const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *x);
  500. DECLARE_ASN1_FUNCTIONS(ASN1_BIT_STRING)
  501. int ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d, int length);
  502. int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value);
  503. int ASN1_BIT_STRING_get_bit(const ASN1_BIT_STRING *a, int n);
  504. int ASN1_BIT_STRING_check(const ASN1_BIT_STRING *a,
  505. const unsigned char *flags, int flags_len);
  506. int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
  507. BIT_STRING_BITNAME *tbl, int indent);
  508. int ASN1_BIT_STRING_num_asc(const char *name, BIT_STRING_BITNAME *tbl);
  509. int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, const char *name, int value,
  510. BIT_STRING_BITNAME *tbl);
  511. {-
  512. generate_stack_macros("ASN1_INTEGER");
  513. -}
  514. DECLARE_ASN1_FUNCTIONS(ASN1_INTEGER)
  515. ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp,
  516. long length);
  517. DECLARE_ASN1_DUP_FUNCTION(ASN1_INTEGER)
  518. int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y);
  519. DECLARE_ASN1_FUNCTIONS(ASN1_ENUMERATED)
  520. int ASN1_UTCTIME_check(const ASN1_UTCTIME *a);
  521. ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t);
  522. ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
  523. int offset_day, long offset_sec);
  524. int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str);
  525. int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t);
  526. int ASN1_GENERALIZEDTIME_check(const ASN1_GENERALIZEDTIME *a);
  527. ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
  528. time_t t);
  529. ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
  530. time_t t, int offset_day,
  531. long offset_sec);
  532. int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str);
  533. int ASN1_TIME_diff(int *pday, int *psec,
  534. const ASN1_TIME *from, const ASN1_TIME *to);
  535. DECLARE_ASN1_FUNCTIONS(ASN1_OCTET_STRING)
  536. DECLARE_ASN1_DUP_FUNCTION(ASN1_OCTET_STRING)
  537. int ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a,
  538. const ASN1_OCTET_STRING *b);
  539. int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, const unsigned char *data,
  540. int len);
  541. {-
  542. generate_stack_macros("ASN1_UTF8STRING");
  543. -}
  544. DECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING)
  545. DECLARE_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING)
  546. DECLARE_ASN1_FUNCTIONS(ASN1_UTF8STRING)
  547. DECLARE_ASN1_FUNCTIONS(ASN1_NULL)
  548. DECLARE_ASN1_FUNCTIONS(ASN1_BMPSTRING)
  549. int UTF8_getc(const unsigned char *str, int len, unsigned long *val);
  550. int UTF8_putc(unsigned char *str, int len, unsigned long value);
  551. {-
  552. generate_stack_macros("ASN1_GENERALSTRING");
  553. -}
  554. DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE)
  555. DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING)
  556. DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT)
  557. DECLARE_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING)
  558. DECLARE_ASN1_FUNCTIONS(ASN1_T61STRING)
  559. DECLARE_ASN1_FUNCTIONS(ASN1_IA5STRING)
  560. DECLARE_ASN1_FUNCTIONS(ASN1_GENERALSTRING)
  561. DECLARE_ASN1_FUNCTIONS(ASN1_UTCTIME)
  562. DECLARE_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME)
  563. DECLARE_ASN1_FUNCTIONS(ASN1_TIME)
  564. DECLARE_ASN1_DUP_FUNCTION(ASN1_TIME)
  565. DECLARE_ASN1_DUP_FUNCTION(ASN1_UTCTIME)
  566. DECLARE_ASN1_DUP_FUNCTION(ASN1_GENERALIZEDTIME)
  567. DECLARE_ASN1_ITEM(ASN1_OCTET_STRING_NDEF)
  568. ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t);
  569. ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t,
  570. int offset_day, long offset_sec);
  571. int ASN1_TIME_check(const ASN1_TIME *t);
  572. ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(const ASN1_TIME *t,
  573. ASN1_GENERALIZEDTIME **out);
  574. int ASN1_TIME_set_string(ASN1_TIME *s, const char *str);
  575. int ASN1_TIME_set_string_X509(ASN1_TIME *s, const char *str);
  576. int ASN1_TIME_to_tm(const ASN1_TIME *s, struct tm *tm);
  577. int ASN1_TIME_normalize(ASN1_TIME *s);
  578. int ASN1_TIME_cmp_time_t(const ASN1_TIME *s, time_t t);
  579. int ASN1_TIME_compare(const ASN1_TIME *a, const ASN1_TIME *b);
  580. int i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a);
  581. int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size);
  582. int i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a);
  583. int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size);
  584. int i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *a);
  585. int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size);
  586. int i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type);
  587. int i2t_ASN1_OBJECT(char *buf, int buf_len, const ASN1_OBJECT *a);
  588. int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num);
  589. ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len,
  590. const char *sn, const char *ln);
  591. int ASN1_INTEGER_get_int64(int64_t *pr, const ASN1_INTEGER *a);
  592. int ASN1_INTEGER_set_int64(ASN1_INTEGER *a, int64_t r);
  593. int ASN1_INTEGER_get_uint64(uint64_t *pr, const ASN1_INTEGER *a);
  594. int ASN1_INTEGER_set_uint64(ASN1_INTEGER *a, uint64_t r);
  595. int ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
  596. long ASN1_INTEGER_get(const ASN1_INTEGER *a);
  597. ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai);
  598. BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn);
  599. int ASN1_ENUMERATED_get_int64(int64_t *pr, const ASN1_ENUMERATED *a);
  600. int ASN1_ENUMERATED_set_int64(ASN1_ENUMERATED *a, int64_t r);
  601. int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v);
  602. long ASN1_ENUMERATED_get(const ASN1_ENUMERATED *a);
  603. ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(const BIGNUM *bn, ASN1_ENUMERATED *ai);
  604. BIGNUM *ASN1_ENUMERATED_to_BN(const ASN1_ENUMERATED *ai, BIGNUM *bn);
  605. /* General */
  606. /* given a string, return the correct type, max is the maximum length */
  607. int ASN1_PRINTABLE_type(const unsigned char *s, int max);
  608. unsigned long ASN1_tag2bit(int tag);
  609. /* SPECIALS */
  610. int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,
  611. int *pclass, long omax);
  612. int ASN1_check_infinite_end(unsigned char **p, long len);
  613. int ASN1_const_check_infinite_end(const unsigned char **p, long len);
  614. void ASN1_put_object(unsigned char **pp, int constructed, int length,
  615. int tag, int xclass);
  616. int ASN1_put_eoc(unsigned char **pp);
  617. int ASN1_object_size(int constructed, int length, int tag);
  618. /* Used to implement other functions */
  619. void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, const void *x);
  620. # define ASN1_dup_of(type,i2d,d2i,x) \
  621. ((type*)ASN1_dup(CHECKED_I2D_OF(type, i2d), \
  622. CHECKED_D2I_OF(type, d2i), \
  623. CHECKED_PTR_OF(const type, x)))
  624. void *ASN1_item_dup(const ASN1_ITEM *it, const void *x);
  625. int ASN1_item_sign_ex(const ASN1_ITEM *it, X509_ALGOR *algor1,
  626. X509_ALGOR *algor2, ASN1_BIT_STRING *signature,
  627. const void *data, const ASN1_OCTET_STRING *id,
  628. EVP_PKEY *pkey, const EVP_MD *md, OSSL_LIB_CTX *libctx,
  629. const char *propq);
  630. int ASN1_item_verify_ex(const ASN1_ITEM *it, const X509_ALGOR *alg,
  631. const ASN1_BIT_STRING *signature, const void *data,
  632. const ASN1_OCTET_STRING *id, EVP_PKEY *pkey,
  633. OSSL_LIB_CTX *libctx, const char *propq);
  634. /* ASN1 alloc/free macros for when a type is only used internally */
  635. # define M_ASN1_new_of(type) (type *)ASN1_item_new(ASN1_ITEM_rptr(type))
  636. # define M_ASN1_free_of(x, type) \
  637. ASN1_item_free(CHECKED_PTR_OF(type, x), ASN1_ITEM_rptr(type))
  638. # ifndef OPENSSL_NO_STDIO
  639. void *ASN1_d2i_fp(void *(*xnew) (void), d2i_of_void *d2i, FILE *in, void **x);
  640. # define ASN1_d2i_fp_of(type,xnew,d2i,in,x) \
  641. ((type*)ASN1_d2i_fp(CHECKED_NEW_OF(type, xnew), \
  642. CHECKED_D2I_OF(type, d2i), \
  643. in, \
  644. CHECKED_PPTR_OF(type, x)))
  645. void *ASN1_item_d2i_fp_ex(const ASN1_ITEM *it, FILE *in, void *x,
  646. OSSL_LIB_CTX *libctx, const char *propq);
  647. void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x);
  648. int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, const void *x);
  649. # define ASN1_i2d_fp_of(type,i2d,out,x) \
  650. (ASN1_i2d_fp(CHECKED_I2D_OF(type, i2d), \
  651. out, \
  652. CHECKED_PTR_OF(const type, x)))
  653. int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, const void *x);
  654. int ASN1_STRING_print_ex_fp(FILE *fp, const ASN1_STRING *str, unsigned long flags);
  655. # endif
  656. int ASN1_STRING_to_UTF8(unsigned char **out, const ASN1_STRING *in);
  657. void *ASN1_d2i_bio(void *(*xnew) (void), d2i_of_void *d2i, BIO *in, void **x);
  658. # define ASN1_d2i_bio_of(type,xnew,d2i,in,x) \
  659. ((type*)ASN1_d2i_bio( CHECKED_NEW_OF(type, xnew), \
  660. CHECKED_D2I_OF(type, d2i), \
  661. in, \
  662. CHECKED_PPTR_OF(type, x)))
  663. void *ASN1_item_d2i_bio_ex(const ASN1_ITEM *it, BIO *in, void *pval,
  664. OSSL_LIB_CTX *libctx, const char *propq);
  665. void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *pval);
  666. int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, const void *x);
  667. # define ASN1_i2d_bio_of(type,i2d,out,x) \
  668. (ASN1_i2d_bio(CHECKED_I2D_OF(type, i2d), \
  669. out, \
  670. CHECKED_PTR_OF(const type, x)))
  671. int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, const void *x);
  672. BIO *ASN1_item_i2d_mem_bio(const ASN1_ITEM *it, const ASN1_VALUE *val);
  673. int ASN1_UTCTIME_print(BIO *fp, const ASN1_UTCTIME *a);
  674. int ASN1_GENERALIZEDTIME_print(BIO *fp, const ASN1_GENERALIZEDTIME *a);
  675. int ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm);
  676. int ASN1_TIME_print_ex(BIO *bp, const ASN1_TIME *tm, unsigned long flags);
  677. int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v);
  678. int ASN1_STRING_print_ex(BIO *out, const ASN1_STRING *str, unsigned long flags);
  679. int ASN1_buf_print(BIO *bp, const unsigned char *buf, size_t buflen, int off);
  680. int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num,
  681. unsigned char *buf, int off);
  682. int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent);
  683. int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent,
  684. int dump);
  685. const char *ASN1_tag2str(int tag);
  686. /* Used to load and write Netscape format cert */
  687. int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s);
  688. int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len);
  689. int ASN1_TYPE_get_octetstring(const ASN1_TYPE *a, unsigned char *data, int max_len);
  690. int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num,
  691. unsigned char *data, int len);
  692. int ASN1_TYPE_get_int_octetstring(const ASN1_TYPE *a, long *num,
  693. unsigned char *data, int max_len);
  694. void *ASN1_item_unpack(const ASN1_STRING *oct, const ASN1_ITEM *it);
  695. ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it,
  696. ASN1_OCTET_STRING **oct);
  697. void ASN1_STRING_set_default_mask(unsigned long mask);
  698. int ASN1_STRING_set_default_mask_asc(const char *p);
  699. unsigned long ASN1_STRING_get_default_mask(void);
  700. int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
  701. int inform, unsigned long mask);
  702. int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
  703. int inform, unsigned long mask,
  704. long minsize, long maxsize);
  705. ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out,
  706. const unsigned char *in, int inlen,
  707. int inform, int nid);
  708. ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid);
  709. int ASN1_STRING_TABLE_add(int, long, long, unsigned long, unsigned long);
  710. void ASN1_STRING_TABLE_cleanup(void);
  711. /* ASN1 template functions */
  712. /* Old API compatible functions */
  713. ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it);
  714. ASN1_VALUE *ASN1_item_new_ex(const ASN1_ITEM *it, OSSL_LIB_CTX *libctx,
  715. const char *propq);
  716. void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it);
  717. ASN1_VALUE *ASN1_item_d2i_ex(ASN1_VALUE **val, const unsigned char **in,
  718. long len, const ASN1_ITEM *it,
  719. OSSL_LIB_CTX *libctx, const char *propq);
  720. ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **val, const unsigned char **in,
  721. long len, const ASN1_ITEM *it);
  722. int ASN1_item_i2d(const ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);
  723. int ASN1_item_ndef_i2d(const ASN1_VALUE *val, unsigned char **out,
  724. const ASN1_ITEM *it);
  725. void ASN1_add_oid_module(void);
  726. void ASN1_add_stable_module(void);
  727. ASN1_TYPE *ASN1_generate_nconf(const char *str, CONF *nconf);
  728. ASN1_TYPE *ASN1_generate_v3(const char *str, X509V3_CTX *cnf);
  729. int ASN1_str2mask(const char *str, unsigned long *pmask);
  730. /* ASN1 Print flags */
  731. /* Indicate missing OPTIONAL fields */
  732. # define ASN1_PCTX_FLAGS_SHOW_ABSENT 0x001
  733. /* Mark start and end of SEQUENCE */
  734. # define ASN1_PCTX_FLAGS_SHOW_SEQUENCE 0x002
  735. /* Mark start and end of SEQUENCE/SET OF */
  736. # define ASN1_PCTX_FLAGS_SHOW_SSOF 0x004
  737. /* Show the ASN1 type of primitives */
  738. # define ASN1_PCTX_FLAGS_SHOW_TYPE 0x008
  739. /* Don't show ASN1 type of ANY */
  740. # define ASN1_PCTX_FLAGS_NO_ANY_TYPE 0x010
  741. /* Don't show ASN1 type of MSTRINGs */
  742. # define ASN1_PCTX_FLAGS_NO_MSTRING_TYPE 0x020
  743. /* Don't show field names in SEQUENCE */
  744. # define ASN1_PCTX_FLAGS_NO_FIELD_NAME 0x040
  745. /* Show structure names of each SEQUENCE field */
  746. # define ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME 0x080
  747. /* Don't show structure name even at top level */
  748. # define ASN1_PCTX_FLAGS_NO_STRUCT_NAME 0x100
  749. int ASN1_item_print(BIO *out, const ASN1_VALUE *ifld, int indent,
  750. const ASN1_ITEM *it, const ASN1_PCTX *pctx);
  751. ASN1_PCTX *ASN1_PCTX_new(void);
  752. void ASN1_PCTX_free(ASN1_PCTX *p);
  753. unsigned long ASN1_PCTX_get_flags(const ASN1_PCTX *p);
  754. void ASN1_PCTX_set_flags(ASN1_PCTX *p, unsigned long flags);
  755. unsigned long ASN1_PCTX_get_nm_flags(const ASN1_PCTX *p);
  756. void ASN1_PCTX_set_nm_flags(ASN1_PCTX *p, unsigned long flags);
  757. unsigned long ASN1_PCTX_get_cert_flags(const ASN1_PCTX *p);
  758. void ASN1_PCTX_set_cert_flags(ASN1_PCTX *p, unsigned long flags);
  759. unsigned long ASN1_PCTX_get_oid_flags(const ASN1_PCTX *p);
  760. void ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags);
  761. unsigned long ASN1_PCTX_get_str_flags(const ASN1_PCTX *p);
  762. void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags);
  763. ASN1_SCTX *ASN1_SCTX_new(int (*scan_cb) (ASN1_SCTX *ctx));
  764. void ASN1_SCTX_free(ASN1_SCTX *p);
  765. const ASN1_ITEM *ASN1_SCTX_get_item(ASN1_SCTX *p);
  766. const ASN1_TEMPLATE *ASN1_SCTX_get_template(ASN1_SCTX *p);
  767. unsigned long ASN1_SCTX_get_flags(ASN1_SCTX *p);
  768. void ASN1_SCTX_set_app_data(ASN1_SCTX *p, void *data);
  769. void *ASN1_SCTX_get_app_data(ASN1_SCTX *p);
  770. const BIO_METHOD *BIO_f_asn1(void);
  771. /* cannot constify val because of CMS_stream() */
  772. BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it);
  773. int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
  774. const ASN1_ITEM *it);
  775. int PEM_write_bio_ASN1_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
  776. const char *hdr, const ASN1_ITEM *it);
  777. /* cannot constify val because of CMS_dataFinal() */
  778. int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
  779. int ctype_nid, int econt_nid,
  780. STACK_OF(X509_ALGOR) *mdalgs, const ASN1_ITEM *it);
  781. int SMIME_write_ASN1_ex(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
  782. int ctype_nid, int econt_nid,
  783. STACK_OF(X509_ALGOR) *mdalgs, const ASN1_ITEM *it,
  784. OSSL_LIB_CTX *libctx, const char *propq);
  785. ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it);
  786. ASN1_VALUE *SMIME_read_ASN1_ex(BIO *bio, int flags, BIO **bcont,
  787. const ASN1_ITEM *it, ASN1_VALUE **x,
  788. OSSL_LIB_CTX *libctx, const char *propq);
  789. int SMIME_crlf_copy(BIO *in, BIO *out, int flags);
  790. int SMIME_text(BIO *in, BIO *out);
  791. const ASN1_ITEM *ASN1_ITEM_lookup(const char *name);
  792. const ASN1_ITEM *ASN1_ITEM_get(size_t i);
  793. /* Legacy compatibility */
  794. # define DECLARE_ASN1_FUNCTIONS_fname(type, itname, name) \
  795. DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \
  796. DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name)
  797. # define DECLARE_ASN1_FUNCTIONS_const(type) DECLARE_ASN1_FUNCTIONS(type)
  798. # define DECLARE_ASN1_ENCODE_FUNCTIONS_const(type, name) \
  799. DECLARE_ASN1_ENCODE_FUNCTIONS(type, name)
  800. # define I2D_OF_const(type) I2D_OF(type)
  801. # define ASN1_dup_of_const(type,i2d,d2i,x) ASN1_dup_of(type,i2d,d2i,x)
  802. # define ASN1_i2d_fp_of_const(type,i2d,out,x) ASN1_i2d_fp_of(type,i2d,out,x)
  803. # define ASN1_i2d_bio_of_const(type,i2d,out,x) ASN1_i2d_bio_of(type,i2d,out,x)
  804. # ifdef __cplusplus
  805. }
  806. # endif
  807. #endif