d2i_X509.3ossl 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "D2I_X509 3ossl"
  58. .TH D2I_X509 3ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. d2i_ACCESS_DESCRIPTION,
  65. d2i_ADMISSIONS,
  66. d2i_ADMISSION_SYNTAX,
  67. d2i_ASIdOrRange,
  68. d2i_ASIdentifierChoice,
  69. d2i_ASIdentifiers,
  70. d2i_ASN1_BIT_STRING,
  71. d2i_ASN1_BMPSTRING,
  72. d2i_ASN1_ENUMERATED,
  73. d2i_ASN1_GENERALIZEDTIME,
  74. d2i_ASN1_GENERALSTRING,
  75. d2i_ASN1_IA5STRING,
  76. d2i_ASN1_INTEGER,
  77. d2i_ASN1_NULL,
  78. d2i_ASN1_OBJECT,
  79. d2i_ASN1_OCTET_STRING,
  80. d2i_ASN1_PRINTABLE,
  81. d2i_ASN1_PRINTABLESTRING,
  82. d2i_ASN1_SEQUENCE_ANY,
  83. d2i_ASN1_SET_ANY,
  84. d2i_ASN1_T61STRING,
  85. d2i_ASN1_TIME,
  86. d2i_ASN1_TYPE,
  87. d2i_ASN1_UINTEGER,
  88. d2i_ASN1_UNIVERSALSTRING,
  89. d2i_ASN1_UTCTIME,
  90. d2i_ASN1_UTF8STRING,
  91. d2i_ASN1_VISIBLESTRING,
  92. d2i_ASRange,
  93. d2i_AUTHORITY_INFO_ACCESS,
  94. d2i_AUTHORITY_KEYID,
  95. d2i_BASIC_CONSTRAINTS,
  96. d2i_CERTIFICATEPOLICIES,
  97. d2i_CMS_ContentInfo,
  98. d2i_CMS_ReceiptRequest,
  99. d2i_CMS_bio,
  100. d2i_CRL_DIST_POINTS,
  101. d2i_DHxparams,
  102. d2i_DIRECTORYSTRING,
  103. d2i_DISPLAYTEXT,
  104. d2i_DIST_POINT,
  105. d2i_DIST_POINT_NAME,
  106. d2i_DSA_SIG,
  107. d2i_ECDSA_SIG,
  108. d2i_ECPKParameters,
  109. d2i_EDIPARTYNAME,
  110. d2i_ESS_CERT_ID,
  111. d2i_ESS_CERT_ID_V2,
  112. d2i_ESS_ISSUER_SERIAL,
  113. d2i_ESS_SIGNING_CERT,
  114. d2i_ESS_SIGNING_CERT_V2,
  115. d2i_EXTENDED_KEY_USAGE,
  116. d2i_GENERAL_NAME,
  117. d2i_GENERAL_NAMES,
  118. d2i_IPAddressChoice,
  119. d2i_IPAddressFamily,
  120. d2i_IPAddressOrRange,
  121. d2i_IPAddressRange,
  122. d2i_ISSUER_SIGN_TOOL,
  123. d2i_ISSUING_DIST_POINT,
  124. d2i_NAMING_AUTHORITY,
  125. d2i_NETSCAPE_CERT_SEQUENCE,
  126. d2i_NETSCAPE_SPKAC,
  127. d2i_NETSCAPE_SPKI,
  128. d2i_NOTICEREF,
  129. d2i_OCSP_BASICRESP,
  130. d2i_OCSP_CERTID,
  131. d2i_OCSP_CERTSTATUS,
  132. d2i_OCSP_CRLID,
  133. d2i_OCSP_ONEREQ,
  134. d2i_OCSP_REQINFO,
  135. d2i_OCSP_REQUEST,
  136. d2i_OCSP_RESPBYTES,
  137. d2i_OCSP_RESPDATA,
  138. d2i_OCSP_RESPID,
  139. d2i_OCSP_RESPONSE,
  140. d2i_OCSP_REVOKEDINFO,
  141. d2i_OCSP_SERVICELOC,
  142. d2i_OCSP_SIGNATURE,
  143. d2i_OCSP_SINGLERESP,
  144. d2i_OSSL_ATTRIBUTES_SYNTAX,
  145. d2i_OSSL_BASIC_ATTR_CONSTRAINTS,
  146. d2i_OSSL_CMP_ATAVS,
  147. d2i_OSSL_CMP_MSG,
  148. d2i_OSSL_CMP_PKIHEADER,
  149. d2i_OSSL_CMP_PKISI,
  150. d2i_OSSL_CRMF_CERTID,
  151. d2i_OSSL_CRMF_CERTTEMPLATE,
  152. d2i_OSSL_CRMF_ENCRYPTEDVALUE,
  153. d2i_OSSL_CRMF_MSG,
  154. d2i_OSSL_CRMF_MSGS,
  155. d2i_OSSL_CRMF_PBMPARAMETER,
  156. d2i_OSSL_CRMF_PKIPUBLICATIONINFO,
  157. d2i_OSSL_CRMF_SINGLEPUBINFO,
  158. d2i_OSSL_IETF_ATTR_SYNTAX,
  159. d2i_OSSL_ISSUER_SERIAL,
  160. d2i_OSSL_OBJECT_DIGEST_INFO,
  161. d2i_OSSL_TARGET_CERT,
  162. d2i_OSSL_TARGET,
  163. d2i_OSSL_TARGETING_INFORMATION,
  164. d2i_OSSL_TARGETS,
  165. d2i_OSSL_USER_NOTICE_SYNTAX,
  166. d2i_OTHERNAME,
  167. d2i_PBE2PARAM,
  168. d2i_PBEPARAM,
  169. d2i_PBKDF2PARAM,
  170. d2i_PBMAC1PARAM,
  171. d2i_PKCS12,
  172. d2i_PKCS12_BAGS,
  173. d2i_PKCS12_MAC_DATA,
  174. d2i_PKCS12_SAFEBAG,
  175. d2i_PKCS12_bio,
  176. d2i_PKCS12_fp,
  177. d2i_PKCS7,
  178. d2i_PKCS7_DIGEST,
  179. d2i_PKCS7_ENCRYPT,
  180. d2i_PKCS7_ENC_CONTENT,
  181. d2i_PKCS7_ENVELOPE,
  182. d2i_PKCS7_ISSUER_AND_SERIAL,
  183. d2i_PKCS7_RECIP_INFO,
  184. d2i_PKCS7_SIGNED,
  185. d2i_PKCS7_SIGNER_INFO,
  186. d2i_PKCS7_SIGN_ENVELOPE,
  187. d2i_PKCS7_bio,
  188. d2i_PKCS7_fp,
  189. d2i_PKCS8_PRIV_KEY_INFO,
  190. d2i_PKCS8_PRIV_KEY_INFO_bio,
  191. d2i_PKCS8_PRIV_KEY_INFO_fp,
  192. d2i_PKCS8_bio,
  193. d2i_PKCS8_fp,
  194. d2i_PKEY_USAGE_PERIOD,
  195. d2i_POLICYINFO,
  196. d2i_POLICYQUALINFO,
  197. d2i_PROFESSION_INFO,
  198. d2i_PROXY_CERT_INFO_EXTENSION,
  199. d2i_PROXY_POLICY,
  200. d2i_RSA_OAEP_PARAMS,
  201. d2i_RSA_PSS_PARAMS,
  202. d2i_SCRYPT_PARAMS,
  203. d2i_SCT_LIST,
  204. d2i_SXNET,
  205. d2i_SXNETID,
  206. d2i_TS_ACCURACY,
  207. d2i_TS_MSG_IMPRINT,
  208. d2i_TS_MSG_IMPRINT_bio,
  209. d2i_TS_MSG_IMPRINT_fp,
  210. d2i_TS_REQ,
  211. d2i_TS_REQ_bio,
  212. d2i_TS_REQ_fp,
  213. d2i_TS_RESP,
  214. d2i_TS_RESP_bio,
  215. d2i_TS_RESP_fp,
  216. d2i_TS_STATUS_INFO,
  217. d2i_TS_TST_INFO,
  218. d2i_TS_TST_INFO_bio,
  219. d2i_TS_TST_INFO_fp,
  220. d2i_USERNOTICE,
  221. d2i_X509,
  222. d2i_X509_bio,
  223. d2i_X509_fp,
  224. d2i_X509_ACERT,
  225. d2i_X509_ACERT_bio,
  226. d2i_X509_ACERT_fp,
  227. d2i_X509_ALGOR,
  228. d2i_X509_ALGORS,
  229. d2i_X509_ATTRIBUTE,
  230. d2i_X509_CERT_AUX,
  231. d2i_X509_CINF,
  232. d2i_X509_CRL,
  233. d2i_X509_CRL_INFO,
  234. d2i_X509_CRL_bio,
  235. d2i_X509_CRL_fp,
  236. d2i_X509_EXTENSION,
  237. d2i_X509_EXTENSIONS,
  238. d2i_X509_NAME,
  239. d2i_X509_NAME_ENTRY,
  240. d2i_X509_PUBKEY,
  241. d2i_X509_PUBKEY_bio,
  242. d2i_X509_PUBKEY_fp,
  243. d2i_X509_REQ,
  244. d2i_X509_REQ_INFO,
  245. d2i_X509_REQ_bio,
  246. d2i_X509_REQ_fp,
  247. d2i_X509_REVOKED,
  248. d2i_X509_SIG,
  249. d2i_X509_VAL,
  250. i2d_ACCESS_DESCRIPTION,
  251. i2d_ADMISSIONS,
  252. i2d_ADMISSION_SYNTAX,
  253. i2d_ASIdOrRange,
  254. i2d_ASIdentifierChoice,
  255. i2d_ASIdentifiers,
  256. i2d_ASN1_BIT_STRING,
  257. i2d_ASN1_BMPSTRING,
  258. i2d_ASN1_ENUMERATED,
  259. i2d_ASN1_GENERALIZEDTIME,
  260. i2d_ASN1_GENERALSTRING,
  261. i2d_ASN1_IA5STRING,
  262. i2d_ASN1_INTEGER,
  263. i2d_ASN1_NULL,
  264. i2d_ASN1_OBJECT,
  265. i2d_ASN1_OCTET_STRING,
  266. i2d_ASN1_PRINTABLE,
  267. i2d_ASN1_PRINTABLESTRING,
  268. i2d_ASN1_SEQUENCE_ANY,
  269. i2d_ASN1_SET_ANY,
  270. i2d_ASN1_T61STRING,
  271. i2d_ASN1_TIME,
  272. i2d_ASN1_TYPE,
  273. i2d_ASN1_UNIVERSALSTRING,
  274. i2d_ASN1_UTCTIME,
  275. i2d_ASN1_UTF8STRING,
  276. i2d_ASN1_VISIBLESTRING,
  277. i2d_ASN1_bio_stream,
  278. i2d_ASRange,
  279. i2d_AUTHORITY_INFO_ACCESS,
  280. i2d_AUTHORITY_KEYID,
  281. i2d_BASIC_CONSTRAINTS,
  282. i2d_CERTIFICATEPOLICIES,
  283. i2d_CMS_ContentInfo,
  284. i2d_CMS_ReceiptRequest,
  285. i2d_CMS_bio,
  286. i2d_CRL_DIST_POINTS,
  287. i2d_DHxparams,
  288. i2d_DIRECTORYSTRING,
  289. i2d_DISPLAYTEXT,
  290. i2d_DIST_POINT,
  291. i2d_DIST_POINT_NAME,
  292. i2d_DSA_SIG,
  293. i2d_ECDSA_SIG,
  294. i2d_ECPKParameters,
  295. i2d_EDIPARTYNAME,
  296. i2d_ESS_CERT_ID,
  297. i2d_ESS_CERT_ID_V2,
  298. i2d_ESS_ISSUER_SERIAL,
  299. i2d_ESS_SIGNING_CERT,
  300. i2d_ESS_SIGNING_CERT_V2,
  301. i2d_EXTENDED_KEY_USAGE,
  302. i2d_GENERAL_NAME,
  303. i2d_GENERAL_NAMES,
  304. i2d_IPAddressChoice,
  305. i2d_IPAddressFamily,
  306. i2d_IPAddressOrRange,
  307. i2d_IPAddressRange,
  308. i2d_ISSUER_SIGN_TOOL,
  309. i2d_ISSUING_DIST_POINT,
  310. i2d_NAMING_AUTHORITY,
  311. i2d_NETSCAPE_CERT_SEQUENCE,
  312. i2d_NETSCAPE_SPKAC,
  313. i2d_NETSCAPE_SPKI,
  314. i2d_NOTICEREF,
  315. i2d_OCSP_BASICRESP,
  316. i2d_OCSP_CERTID,
  317. i2d_OCSP_CERTSTATUS,
  318. i2d_OCSP_CRLID,
  319. i2d_OCSP_ONEREQ,
  320. i2d_OCSP_REQINFO,
  321. i2d_OCSP_REQUEST,
  322. i2d_OCSP_RESPBYTES,
  323. i2d_OCSP_RESPDATA,
  324. i2d_OCSP_RESPID,
  325. i2d_OCSP_RESPONSE,
  326. i2d_OCSP_REVOKEDINFO,
  327. i2d_OCSP_SERVICELOC,
  328. i2d_OCSP_SIGNATURE,
  329. i2d_OCSP_SINGLERESP,
  330. i2d_OSSL_ATTRIBUTES_SYNTAX,
  331. i2d_OSSL_BASIC_ATTR_CONSTRAINTS,
  332. i2d_OSSL_CMP_ATAVS,
  333. i2d_OSSL_CMP_MSG,
  334. i2d_OSSL_CMP_PKIHEADER,
  335. i2d_OSSL_CMP_PKISI,
  336. i2d_OSSL_CRMF_CERTID,
  337. i2d_OSSL_CRMF_CERTTEMPLATE,
  338. i2d_OSSL_CRMF_ENCRYPTEDVALUE,
  339. i2d_OSSL_CRMF_MSG,
  340. i2d_OSSL_CRMF_MSGS,
  341. i2d_OSSL_CRMF_PBMPARAMETER,
  342. i2d_OSSL_CRMF_PKIPUBLICATIONINFO,
  343. i2d_OSSL_CRMF_SINGLEPUBINFO,
  344. i2d_OSSL_IETF_ATTR_SYNTAX,
  345. i2d_OSSL_ISSUER_SERIAL,
  346. i2d_OSSL_OBJECT_DIGEST_INFO,
  347. i2d_OSSL_TARGET_CERT,
  348. i2d_OSSL_TARGET,
  349. i2d_OSSL_TARGETING_INFORMATION,
  350. i2d_OSSL_TARGETS,
  351. i2d_OSSL_USER_NOTICE_SYNTAX,
  352. i2d_OTHERNAME,
  353. i2d_PBE2PARAM,
  354. i2d_PBEPARAM,
  355. i2d_PBKDF2PARAM,
  356. i2d_PBMAC1PARAM,
  357. i2d_PKCS12,
  358. i2d_PKCS12_BAGS,
  359. i2d_PKCS12_MAC_DATA,
  360. i2d_PKCS12_SAFEBAG,
  361. i2d_PKCS12_bio,
  362. i2d_PKCS12_fp,
  363. i2d_PKCS7,
  364. i2d_PKCS7_DIGEST,
  365. i2d_PKCS7_ENCRYPT,
  366. i2d_PKCS7_ENC_CONTENT,
  367. i2d_PKCS7_ENVELOPE,
  368. i2d_PKCS7_ISSUER_AND_SERIAL,
  369. i2d_PKCS7_NDEF,
  370. i2d_PKCS7_RECIP_INFO,
  371. i2d_PKCS7_SIGNED,
  372. i2d_PKCS7_SIGNER_INFO,
  373. i2d_PKCS7_SIGN_ENVELOPE,
  374. i2d_PKCS7_bio,
  375. i2d_PKCS7_fp,
  376. i2d_PKCS8PrivateKeyInfo_bio,
  377. i2d_PKCS8PrivateKeyInfo_fp,
  378. i2d_PKCS8_PRIV_KEY_INFO,
  379. i2d_PKCS8_PRIV_KEY_INFO_bio,
  380. i2d_PKCS8_PRIV_KEY_INFO_fp,
  381. i2d_PKCS8_bio,
  382. i2d_PKCS8_fp,
  383. i2d_PKEY_USAGE_PERIOD,
  384. i2d_POLICYINFO,
  385. i2d_POLICYQUALINFO,
  386. i2d_PROFESSION_INFO,
  387. i2d_PROXY_CERT_INFO_EXTENSION,
  388. i2d_PROXY_POLICY,
  389. i2d_RSA_OAEP_PARAMS,
  390. i2d_RSA_PSS_PARAMS,
  391. i2d_SCRYPT_PARAMS,
  392. i2d_SCT_LIST,
  393. i2d_SXNET,
  394. i2d_SXNETID,
  395. i2d_TS_ACCURACY,
  396. i2d_TS_MSG_IMPRINT,
  397. i2d_TS_MSG_IMPRINT_bio,
  398. i2d_TS_MSG_IMPRINT_fp,
  399. i2d_TS_REQ,
  400. i2d_TS_REQ_bio,
  401. i2d_TS_REQ_fp,
  402. i2d_TS_RESP,
  403. i2d_TS_RESP_bio,
  404. i2d_TS_RESP_fp,
  405. i2d_TS_STATUS_INFO,
  406. i2d_TS_TST_INFO,
  407. i2d_TS_TST_INFO_bio,
  408. i2d_TS_TST_INFO_fp,
  409. i2d_USERNOTICE,
  410. i2d_X509,
  411. i2d_X509_bio,
  412. i2d_X509_fp,
  413. i2d_X509_ACERT,
  414. i2d_X509_ACERT_bio,
  415. i2d_X509_ACERT_fp,
  416. i2d_X509_ALGOR,
  417. i2d_X509_ALGORS,
  418. i2d_X509_ATTRIBUTE,
  419. i2d_X509_CERT_AUX,
  420. i2d_X509_CINF,
  421. i2d_X509_CRL,
  422. i2d_X509_CRL_INFO,
  423. i2d_X509_CRL_bio,
  424. i2d_X509_CRL_fp,
  425. i2d_X509_EXTENSION,
  426. i2d_X509_EXTENSIONS,
  427. i2d_X509_NAME,
  428. i2d_X509_NAME_ENTRY,
  429. i2d_X509_PUBKEY,
  430. i2d_X509_PUBKEY_bio,
  431. i2d_X509_PUBKEY_fp,
  432. i2d_X509_REQ,
  433. i2d_X509_REQ_INFO,
  434. i2d_X509_REQ_bio,
  435. i2d_X509_REQ_fp,
  436. i2d_X509_REVOKED,
  437. i2d_X509_SIG,
  438. i2d_X509_VAL,
  439. \&\- convert objects from/to ASN.1/DER representation
  440. .SH SYNOPSIS
  441. .IX Header "SYNOPSIS"
  442. .Vb 3
  443. \& TYPE *d2i_TYPE(TYPE **a, const unsigned char **ppin, long length);
  444. \& TYPE *d2i_TYPE_bio(BIO *bp, TYPE **a);
  445. \& TYPE *d2i_TYPE_fp(FILE *fp, TYPE **a);
  446. \&
  447. \& int i2d_TYPE(const TYPE *a, unsigned char **ppout);
  448. \& int i2d_TYPE(TYPE *a, unsigned char **ppout);
  449. \& int i2d_TYPE_fp(FILE *fp, const TYPE *a);
  450. \& int i2d_TYPE_fp(FILE *fp, TYPE *a);
  451. \& int i2d_TYPE_bio(BIO *bp, const TYPE *a);
  452. \& int i2d_TYPE_bio(BIO *bp, TYPE *a);
  453. .Ve
  454. .SH DESCRIPTION
  455. .IX Header "DESCRIPTION"
  456. In the description here, \fR\f(BITYPE\fR\fB\fR is used a placeholder
  457. for any of the OpenSSL datatypes, such as \fBX509_CRL\fR.
  458. The function parameters \fIppin\fR and \fIppout\fR are generally
  459. either both named \fIpp\fR in the headers, or \fIin\fR and \fIout\fR.
  460. .PP
  461. These functions convert OpenSSL objects to and from their ASN.1/DER
  462. encoding. Unlike the C structures which can have pointers to sub-objects
  463. within, the DER is a serialized encoding, suitable for sending over the
  464. network, writing to a file, and so on.
  465. .PP
  466. \&\fBd2i_\fR\f(BITYPE\fR() attempts to decode \fIlen\fR bytes at \fI*ppin\fR. If successful a
  467. pointer to the \fB\fR\f(BITYPE\fR\fB\fR structure is returned and \fI*ppin\fR is incremented to
  468. the byte following the parsed data. If \fIa\fR is not NULL then a pointer
  469. to the returned structure is also written to \fI*a\fR. If an error occurred
  470. then NULL is returned. The caller retains ownership of the
  471. returned object and needs to free it when it is no longer needed, e.g.
  472. using \fBX509_free()\fR for X509 objects or \fBDSA_SIG_free()\fR for DSA_SIG objects.
  473. .PP
  474. On a successful return, if \fI*a\fR is not NULL then it is assumed that \fI*a\fR
  475. contains a valid \fR\f(BITYPE\fR\fB\fR structure and an attempt is made to reuse it.
  476. For \fB\fR\f(BITYPE\fR\fB\fR structures where it matters it is possible to set up a library
  477. context on the decoded structure this way (see the \fBEXAMPLES\fR section).
  478. However using the "reuse" capability for other purposes is \fBstrongly
  479. discouraged\fR (see \fBBUGS\fR below, and the discussion in the \fBRETURN VALUES\fR
  480. section).
  481. .PP
  482. \&\fBd2i_\fR\f(BITYPE\fR\fB_bio\fR() is similar to \fBd2i_\fR\f(BITYPE\fR() except it attempts
  483. to parse data from BIO \fIbp\fR.
  484. .PP
  485. \&\fBd2i_\fR\f(BITYPE\fR\fB_fp\fR() is similar to \fBd2i_\fR\f(BITYPE\fR() except it attempts
  486. to parse data from FILE pointer \fIfp\fR.
  487. .PP
  488. \&\fBi2d_\fR\f(BITYPE\fR() encodes the structure pointed to by \fIa\fR into DER format.
  489. If \fIppout\fR is not NULL, it writes the DER encoded data to the buffer
  490. at \fI*ppout\fR, and increments it to point after the data just written.
  491. If the return value is negative an error occurred, otherwise it
  492. returns the length of the encoded data.
  493. .PP
  494. If \fI*ppout\fR is NULL memory will be allocated for a buffer and the encoded
  495. data written to it. In this case \fI*ppout\fR is not incremented and it points
  496. to the start of the data just written.
  497. .PP
  498. \&\fBi2d_\fR\f(BITYPE\fR\fB_bio\fR() is similar to \fBi2d_\fR\f(BITYPE\fR() except it writes
  499. the encoding of the structure \fIa\fR to BIO \fIbp\fR and it
  500. returns 1 for success and 0 for failure.
  501. .PP
  502. \&\fBi2d_\fR\f(BITYPE\fR\fB_fp\fR() is similar to \fBi2d_\fR\f(BITYPE\fR() except it writes
  503. the encoding of the structure \fIa\fR to FILE pointer \fIfp\fR and it
  504. returns 1 for success and 0 for failure.
  505. .PP
  506. These routines do not encrypt private keys and therefore offer no
  507. security; use \fBPEM_write_PrivateKey\fR\|(3) or similar for writing to files.
  508. .SH NOTES
  509. .IX Header "NOTES"
  510. The letters \fBi\fR and \fBd\fR in \fBi2d_\fR\f(BITYPE\fR() stand for
  511. "internal" (that is, an internal C structure) and "DER" respectively.
  512. So \fBi2d_\fR\f(BITYPE\fR\fB\fR() converts from internal to DER.
  513. .PP
  514. The functions can also understand \fBBER\fR forms.
  515. .PP
  516. The actual TYPE structure passed to \fBi2d_\fR\f(BITYPE\fR() must be a valid
  517. populated \fB\fR\f(BITYPE\fR\fB\fR structure \-\- it \fBcannot\fR simply be fed with an
  518. empty structure such as that returned by \fBTYPE_new()\fR.
  519. .PP
  520. The encoded data is in binary form and may contain embedded zeros.
  521. Therefore, any FILE pointers or BIOs should be opened in binary mode.
  522. Functions such as \fBstrlen()\fR will \fBnot\fR return the correct length
  523. of the encoded structure.
  524. .PP
  525. The ways that \fI*ppin\fR and \fI*ppout\fR are incremented after the operation
  526. can trap the unwary. See the \fBWARNINGS\fR section for some common
  527. errors.
  528. The reason for this-auto increment behaviour is to reflect a typical
  529. usage of ASN1 functions: after one structure is encoded or decoded
  530. another will be processed after it.
  531. .PP
  532. The following points about the data types might be useful:
  533. .IP \fBASN1_OBJECT\fR 4
  534. .IX Item "ASN1_OBJECT"
  535. Represents an ASN1 OBJECT IDENTIFIER.
  536. .IP \fBDHparams\fR 4
  537. .IX Item "DHparams"
  538. Represents a PKCS#3 DH parameters structure.
  539. .IP \fBDHxparams\fR 4
  540. .IX Item "DHxparams"
  541. Represents an ANSI X9.42 DH parameters structure.
  542. .IP \fBECDSA_SIG\fR 4
  543. .IX Item "ECDSA_SIG"
  544. Represents an ECDSA signature.
  545. .IP \fBX509_ALGOR\fR 4
  546. .IX Item "X509_ALGOR"
  547. Represents an \fBAlgorithmIdentifier\fR structure as used in IETF RFC 6960 and
  548. elsewhere.
  549. .IP \fBX509_NAME\fR 4
  550. .IX Item "X509_NAME"
  551. Represents a \fBName\fR type as used for subject and issuer names in
  552. IETF RFC 6960 and elsewhere.
  553. .IP \fBX509_REQ\fR 4
  554. .IX Item "X509_REQ"
  555. Represents a PKCS#10 certificate request.
  556. .IP \fBX509_SIG\fR 4
  557. .IX Item "X509_SIG"
  558. Represents the \fBDigestInfo\fR structure defined in PKCS#1 and PKCS#7.
  559. .SH "RETURN VALUES"
  560. .IX Header "RETURN VALUES"
  561. \&\fBd2i_\fR\f(BITYPE\fR(), \fBd2i_\fR\f(BITYPE\fR\fB_bio\fR() and \fBd2i_\fR\f(BITYPE\fR\fB_fp\fR() return a valid
  562. \&\fB\fR\f(BITYPE\fR\fB\fR structure or NULL if an error occurs. If the "reuse" capability has
  563. been used with a valid structure being passed in via \fIa\fR, then the object is
  564. freed in the event of error and \fI*a\fR is set to NULL.
  565. .PP
  566. \&\fBi2d_\fR\f(BITYPE\fR() returns the number of bytes successfully encoded or a negative
  567. value if an error occurs.
  568. .PP
  569. \&\fBi2d_\fR\f(BITYPE\fR\fB_bio\fR() and \fBi2d_\fR\f(BITYPE\fR\fB_fp\fR() return 1 for success and 0 if an
  570. error occurs.
  571. .SH EXAMPLES
  572. .IX Header "EXAMPLES"
  573. Allocate and encode the DER encoding of an X509 structure:
  574. .PP
  575. .Vb 2
  576. \& int len;
  577. \& unsigned char *buf;
  578. \&
  579. \& buf = NULL;
  580. \& len = i2d_X509(x, &buf);
  581. \& if (len < 0)
  582. \& /* error */
  583. .Ve
  584. .PP
  585. Attempt to decode a buffer:
  586. .PP
  587. .Vb 4
  588. \& X509 *x;
  589. \& unsigned char *buf;
  590. \& const unsigned char *p;
  591. \& int len;
  592. \&
  593. \& /* Set up buf and len to point to the input buffer. */
  594. \& p = buf;
  595. \& x = d2i_X509(NULL, &p, len);
  596. \& if (x == NULL)
  597. \& /* error */
  598. .Ve
  599. .PP
  600. Alternative technique:
  601. .PP
  602. .Vb 4
  603. \& X509 *x;
  604. \& unsigned char *buf;
  605. \& const unsigned char *p;
  606. \& int len;
  607. \&
  608. \& /* Set up buf and len to point to the input buffer. */
  609. \& p = buf;
  610. \& x = NULL;
  611. \&
  612. \& if (d2i_X509(&x, &p, len) == NULL)
  613. \& /* error */
  614. .Ve
  615. .PP
  616. Setting up a library context and property query:
  617. .PP
  618. .Vb 6
  619. \& X509 *x;
  620. \& unsigned char *buf;
  621. \& const unsigned char *p;
  622. \& int len;
  623. \& OSSL_LIB_CTX *libctx = ....;
  624. \& const char *propq = ....;
  625. \&
  626. \& /* Set up buf and len to point to the input buffer. */
  627. \& p = buf;
  628. \& x = X509_new_ex(libctx, propq);
  629. \&
  630. \& if (d2i_X509(&x, &p, len) == NULL)
  631. \& /* error, x was freed and NULL assigned to it (see RETURN VALUES) */
  632. .Ve
  633. .SH WARNINGS
  634. .IX Header "WARNINGS"
  635. Using a temporary variable is mandatory. A common
  636. mistake is to attempt to use a buffer directly as follows:
  637. .PP
  638. .Vb 2
  639. \& int len;
  640. \& unsigned char *buf;
  641. \&
  642. \& len = i2d_X509(x, NULL);
  643. \& buf = OPENSSL_malloc(len);
  644. \& ...
  645. \& i2d_X509(x, &buf);
  646. \& ...
  647. \& OPENSSL_free(buf);
  648. .Ve
  649. .PP
  650. This code will result in \fIbuf\fR apparently containing garbage because
  651. it was incremented after the call to point after the data just written.
  652. Also \fIbuf\fR will no longer contain the pointer allocated by \fBOPENSSL_malloc()\fR
  653. and the subsequent call to \fBOPENSSL_free()\fR is likely to crash.
  654. .PP
  655. Another trap to avoid is misuse of the \fIa\fR argument to \fBd2i_\fR\f(BITYPE\fR():
  656. .PP
  657. .Vb 1
  658. \& X509 *x;
  659. \&
  660. \& if (d2i_X509(&x, &p, len) == NULL)
  661. \& /* error */
  662. .Ve
  663. .PP
  664. This will probably crash somewhere in \fBd2i_X509()\fR. The reason for this
  665. is that the variable \fIx\fR is uninitialized and an attempt will be made to
  666. interpret its (invalid) value as an \fBX509\fR structure, typically causing
  667. a segmentation violation. If \fIx\fR is set to NULL first then this will not
  668. happen.
  669. .SH BUGS
  670. .IX Header "BUGS"
  671. In some versions of OpenSSL the "reuse" behaviour of \fBd2i_\fR\f(BITYPE\fR() when
  672. \&\fI*a\fR is valid is broken and some parts of the reused structure may
  673. persist if they are not present in the new one. Additionally, in versions of
  674. OpenSSL prior to 1.1.0, when the "reuse" behaviour is used and an error occurs
  675. the behaviour is inconsistent. Some functions behaved as described here, while
  676. some did not free \fI*a\fR on error and did not set \fI*a\fR to NULL.
  677. .PP
  678. As a result of the above issues the "reuse" behaviour is strongly discouraged.
  679. .PP
  680. \&\fBi2d_\fR\f(BITYPE\fR() will not return an error in many versions of OpenSSL,
  681. if mandatory fields are not initialized due to a programming error
  682. then the encoded structure may contain invalid data or omit the
  683. fields entirely and will not be parsed by \fBd2i_\fR\f(BITYPE\fR\fB\fR(). This may be
  684. fixed in future so code should not assume that \fBi2d_\fR\f(BITYPE\fR\fB\fR() will
  685. always succeed.
  686. .PP
  687. Any function which encodes a structure (\fBi2d_\fR\f(BITYPE\fR(),
  688. \&\fBi2d_\fR\f(BITYPE\fR\fB_bio\fR() or \fBi2d_\fR\f(BITYPE\fR\fB_fp\fR()) may return a stale encoding if the
  689. structure has been modified after deserialization or previous
  690. serialization. This is because some objects cache the encoding for
  691. efficiency reasons.
  692. .SH COPYRIGHT
  693. .IX Header "COPYRIGHT"
  694. Copyright 1998\-2024 The OpenSSL Project Authors. All Rights Reserved.
  695. .PP
  696. Licensed under the Apache License 2.0 (the "License"). You may not use
  697. this file except in compliance with the License. You can obtain a copy
  698. in the file LICENSE in the source distribution or at
  699. <https://www.openssl.org/source/license.html>.