OSSL_DECODER_from_bio.3ossl 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 "OSSL_DECODER_FROM_BIO 3ossl"
  58. .TH OSSL_DECODER_FROM_BIO 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. OSSL_DECODER_from_data,
  65. OSSL_DECODER_from_bio,
  66. OSSL_DECODER_from_fp
  67. \&\- Routines to perform a decoding
  68. .SH SYNOPSIS
  69. .IX Header "SYNOPSIS"
  70. .Vb 1
  71. \& #include <openssl/decoder.h>
  72. \&
  73. \& int OSSL_DECODER_from_bio(OSSL_DECODER_CTX *ctx, BIO *in);
  74. \& int OSSL_DECODER_from_fp(OSSL_DECODER_CTX *ctx, FILE *fp);
  75. \& int OSSL_DECODER_from_data(OSSL_DECODER_CTX *ctx, const unsigned char **pdata,
  76. \& size_t *pdata_len);
  77. .Ve
  78. .PP
  79. Feature availability macros:
  80. .IP "\fBOSSL_DECODER_from_fp()\fR is only available when \fBOPENSSL_NO_STDIO\fR is undefined." 4
  81. .IX Item "OSSL_DECODER_from_fp() is only available when OPENSSL_NO_STDIO is undefined."
  82. .SH DESCRIPTION
  83. .IX Header "DESCRIPTION"
  84. \&\fBOSSL_DECODER_from_data()\fR runs the decoding process for the context \fIctx\fR,
  85. with input coming from \fI*pdata\fR, \fI*pdata_len\fR bytes long. Both \fI*pdata\fR
  86. and \fI*pdata_len\fR must be non-NULL. When \fBOSSL_DECODER_from_data()\fR returns,
  87. \&\fI*pdata\fR is updated to point at the location after what has been decoded,
  88. and \fI*pdata_len\fR to have the number of remaining bytes.
  89. .PP
  90. \&\fBOSSL_DECODER_from_bio()\fR runs the decoding process for the context \fIctx\fR,
  91. with the input coming from the \fBBIO\fR \fIin\fR. Should it make a difference,
  92. it's recommended to have the BIO set in binary mode rather than text mode.
  93. .PP
  94. \&\fBOSSL_DECODER_from_fp()\fR does the same thing as \fBOSSL_DECODER_from_bio()\fR,
  95. except that the input is coming from the \fBFILE\fR \fIfp\fR.
  96. .SH "RETURN VALUES"
  97. .IX Header "RETURN VALUES"
  98. \&\fBOSSL_DECODER_from_bio()\fR, \fBOSSL_DECODER_from_data()\fR and \fBOSSL_DECODER_from_fp()\fR
  99. return 1 on success, or 0 on failure.
  100. .SH EXAMPLES
  101. .IX Header "EXAMPLES"
  102. To decode an RSA key encoded with PEM from a bio:
  103. .PP
  104. .Vb 6
  105. \& OSSL_DECODER_CTX *dctx;
  106. \& EVP_PKEY *pkey = NULL;
  107. \& const char *format = "PEM"; /* NULL for any format */
  108. \& const char *structure = NULL; /* any structure */
  109. \& const char *keytype = "RSA"; /* NULL for any key */
  110. \& const unsigned char *pass = "my password";
  111. \&
  112. \& dctx = OSSL_DECODER_CTX_new_for_pkey(&pkey, format, structure,
  113. \& keytype,
  114. \& OSSL_KEYMGMT_SELECT_KEYPAIR,
  115. \& NULL, NULL);
  116. \& if (dctx == NULL) {
  117. \& /* error: no suitable potential decoders found */
  118. \& }
  119. \& if (pass != NULL)
  120. \& OSSL_DECODER_CTX_set_passphrase(dctx, pass, strlen(pass));
  121. \& if (OSSL_DECODER_from_bio(dctx, bio)) {
  122. \& /* pkey is created with the decoded data from the bio */
  123. \& } else {
  124. \& /* decoding failure */
  125. \& }
  126. \& OSSL_DECODER_CTX_free(dctx);
  127. .Ve
  128. .PP
  129. To decode an EC key encoded with DER from a buffer:
  130. .PP
  131. .Vb 8
  132. \& OSSL_DECODER_CTX *dctx;
  133. \& EVP_PKEY *pkey = NULL;
  134. \& const char *format = "DER"; /* NULL for any format */
  135. \& const char *structure = NULL; /* any structure */
  136. \& const char *keytype = "EC"; /* NULL for any key */
  137. \& const unsigned char *pass = NULL
  138. \& const unsigned char *data = buffer;
  139. \& size_t datalen = sizeof(buffer);
  140. \&
  141. \& dctx = OSSL_DECODER_CTX_new_for_pkey(&pkey, format, structure,
  142. \& keytype,
  143. \& OSSL_KEYMGMT_SELECT_KEYPAIR
  144. \& | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS,
  145. \& NULL, NULL);
  146. \& if (dctx == NULL) {
  147. \& /* error: no suitable potential decoders found */
  148. \& }
  149. \& if (pass != NULL)
  150. \& OSSL_DECODER_CTX_set_passphrase(dctx, pass, strlen(pass));
  151. \& if (OSSL_DECODER_from_data(dctx, &data, &datalen)) {
  152. \& /* pkey is created with the decoded data from the buffer */
  153. \& } else {
  154. \& /* decoding failure */
  155. \& }
  156. \& OSSL_DECODER_CTX_free(dctx);
  157. .Ve
  158. .SH "SEE ALSO"
  159. .IX Header "SEE ALSO"
  160. \&\fBprovider\fR\|(7), \fBOSSL_DECODER_CTX\fR\|(3)
  161. .SH HISTORY
  162. .IX Header "HISTORY"
  163. The functions described here were added in OpenSSL 3.0.
  164. .SH COPYRIGHT
  165. .IX Header "COPYRIGHT"
  166. Copyright 2020\-2023 The OpenSSL Project Authors. All Rights Reserved.
  167. .PP
  168. Licensed under the Apache License 2.0 (the "License"). You may not use
  169. this file except in compliance with the License. You can obtain a copy
  170. in the file LICENSE in the source distribution or at
  171. <https://www.openssl.org/source/license.html>.