Debian Codegraph @

upstream/debian-unstable/man3/OSSL_ENCODER_to_bio.3ssl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
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_ENCODER_TO_BIO 3SSL"
58 .TH OSSL_ENCODER_TO_BIO 3SSL 2026-04-07 3.6.2 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_ENCODER_to_data,
65 OSSL_ENCODER_to_bio,
66 OSSL_ENCODER_to_fp
67 \&\- Routines to perform an encoding
68 .SH SYNOPSIS
69 .IX Header "SYNOPSIS"
70 .Vb 1
71 \& #include <openssl/encoder.h>
72 \&
73 \& int OSSL_ENCODER_to_data(OSSL_ENCODER_CTX *ctx, unsigned char **pdata,
74 \& size_t *pdata_len);
75 \& int OSSL_ENCODER_to_bio(OSSL_ENCODER_CTX *ctx, BIO *out);
76 \& int OSSL_ENCODER_to_fp(OSSL_ENCODER_CTX *ctx, FILE *fp);
77 .Ve
78 .PP
79 Feature availability macros:
80 .IP "\fBOSSL_ENCODER_to_fp()\fR is only available when \fBOPENSSL_NO_STDIO\fR is undefined." 4
81 .IX Item "OSSL_ENCODER_to_fp() is only available when OPENSSL_NO_STDIO is undefined."
82 .SH DESCRIPTION
83 .IX Header "DESCRIPTION"
84 \&\fBOSSL_ENCODER_to_data()\fR runs the encoding process for the context \fIctx\fR,
85 with the output going to the \fI*pdata\fR and \fI*pdata_len\fR.
86 If \fI*pdata\fR is NULL when \fBOSSL_ENCODER_to_data()\fR is called, a buffer will be
87 allocated using \fBOPENSSL_zalloc\fR\|(3), and \fI*pdata\fR will be set to point at
88 the start of that buffer, and \fI*pdata_len\fR will be assigned its length when
89 \&\fBOSSL_ENCODER_to_data()\fR returns.
90 If \fI*pdata\fR is non-NULL when \fBOSSL_ENCODER_to_data()\fR is called, \fI*pdata_len\fR
91 is assumed to have its size. In this case, \fI*pdata\fR will be set to point
92 after the encoded bytes, and \fI*pdata_len\fR will be assigned the number of
93 remaining bytes.
94 .PP
95 \&\fBOSSL_ENCODER_to_bio()\fR runs the encoding process for the context \fIctx\fR, with
96 the output going to the \fBBIO\fR \fIout\fR.
97 .PP
98 \&\fBOSSL_ENCODER_to_fp()\fR does the same thing as \fBOSSL_ENCODER_to_bio()\fR, except
99 that the output is going to the \fBFILE\fR \fIfp\fR.
100 .PP
101 For \fBOSSL_ENCODER_to_bio()\fR and \fBOSSL_ENCODER_to_fp()\fR, the application is
102 required to set up the \fBBIO\fR or \fBFILE\fR properly, for example to have
103 it in text or binary mode as is appropriate for the encoder output type.
104 .SH "RETURN VALUES"
105 .IX Header "RETURN VALUES"
106 \&\fBOSSL_ENCODER_to_bio()\fR, \fBOSSL_ENCODER_to_fp()\fR and \fBOSSL_ENCODER_to_data()\fR
107 return 1 on success, or 0 on failure.
108 .SH EXAMPLES
109 .IX Header "EXAMPLES"
110 To encode a pkey as PKCS#8 with PEM format into a bio:
111 .PP
112 .Vb 4
113 \& OSSL_ENCODER_CTX *ectx;
114 \& const char *format = "PEM";
115 \& const char *structure = "PrivateKeyInfo"; /* PKCS#8 structure */
116 \& const unsigned char *pass = "my password";
117 \&
118 \& ectx = OSSL_ENCODER_CTX_new_for_pkey(pkey,
119 \& OSSL_KEYMGMT_SELECT_KEYPAIR
120 \& | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS,
121 \& format, structure,
122 \& NULL);
123 \& if (ectx == NULL) {
124 \& /* error: no suitable potential encoders found */
125 \& }
126 \& if (pass != NULL)
127 \& OSSL_ENCODER_CTX_set_passphrase(ectx, pass, strlen(pass));
128 \& if (OSSL_ENCODER_to_bio(ectx, bio)) {
129 \& /* pkey was successfully encoded into the bio */
130 \& } else {
131 \& /* encoding failure */
132 \& }
133 \& OSSL_ENCODER_CTX_free(ectx);
134 .Ve
135 .PP
136 To encode a pkey as PKCS#8 with DER format encrypted with
137 AES\-256\-CBC into a buffer:
138 .PP
139 .Vb 6
140 \& OSSL_ENCODER_CTX *ectx;
141 \& const char *format = "DER";
142 \& const char *structure = "PrivateKeyInfo"; /* PKCS#8 structure */
143 \& const unsigned char *pass = "my password";
144 \& unsigned char *data = NULL;
145 \& size_t datalen;
146 \&
147 \& ectx = OSSL_ENCODER_CTX_new_for_pkey(pkey,
148 \& OSSL_KEYMGMT_SELECT_KEYPAIR
149 \& | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS,
150 \& format, structure,
151 \& NULL);
152 \& if (ectx == NULL) {
153 \& /* error: no suitable potential encoders found */
154 \& }
155 \& if (pass != NULL) {
156 \& OSSL_ENCODER_CTX_set_passphrase(ectx, pass, strlen(pass));
157 \& OSSL_ENCODER_CTX_set_cipher(ctx, "AES\-256\-CBC", NULL);
158 \& }
159 \& if (OSSL_ENCODER_to_data(ectx, &data, &datalen)) {
160 \& /*
161 \& * pkey was successfully encoded into a newly allocated
162 \& * data buffer
163 \& */
164 \& } else {
165 \& /* encoding failure */
166 \& }
167 \& OSSL_ENCODER_CTX_free(ectx);
168 .Ve
169 .SH "SEE ALSO"
170 .IX Header "SEE ALSO"
171 \&\fBprovider\fR\|(7), \fBOSSL_ENCODER_CTX\fR\|(3)
172 .SH HISTORY
173 .IX Header "HISTORY"
174 The functions described here were added in OpenSSL 3.0.
175 .SH COPYRIGHT
176 .IX Header "COPYRIGHT"
177 Copyright 2019\-2021 The OpenSSL Project Authors. All Rights Reserved.
178 .PP
179 Licensed under the Apache License 2.0 (the "License"). You may not use
180 this file except in compliance with the License. You can obtain a copy
181 in the file LICENSE in the source distribution or at
182 <https://www.openssl.org/source/license.html>.