1OSSL_DECODER_FROM_BIO(3ossl)        OpenSSL       OSSL_DECODER_FROM_BIO(3ossl)
2
3
4

NAME

6       OSSL_DECODER_from_data, OSSL_DECODER_from_bio, OSSL_DECODER_from_fp -
7       Routines to perform a decoding
8

SYNOPSIS

10        #include <openssl/decoder.h>
11
12        int OSSL_DECODER_from_bio(OSSL_DECODER_CTX *ctx, BIO *in);
13        int OSSL_DECODER_from_fp(OSSL_DECODER_CTX *ctx, FILE *fp);
14        int OSSL_DECODER_from_data(OSSL_DECODER_CTX *ctx, const unsigned char **pdata,
15                                   size_t *pdata_len);
16
17       Feature availability macros:
18
19       OSSL_DECODER_from_fp() is only available when OPENSSL_NO_STDIO is
20       undefined.
21

DESCRIPTION

23       OSSL_DECODER_from_data() runs the decoding process for the context ctx,
24       with input coming from *pdata, *pdata_len bytes long.  Both *pdata and
25       *pdata_len must be non-NULL.  When OSSL_DECODER_from_data() returns,
26       *pdata is updated to point at the location after what has been decoded,
27       and *pdata_len to have the number of remaining bytes.
28
29       OSSL_DECODER_from_bio() runs the decoding process for the context ctx,
30       with the input coming from the BIO in.  Should it make a difference,
31       it's recommended to have the BIO set in binary mode rather than text
32       mode.
33
34       OSSL_DECODER_from_fp() does the same thing as OSSL_DECODER_from_bio(),
35       except that the input is coming from the FILE fp.
36

RETURN VALUES

38       OSSL_DECODER_from_bio() and OSSL_DECODER_from_fp() return 1 on success,
39       or 0 on failure.
40

EXAMPLES

42       To decode an RSA key encoded with PEM from a bio:
43
44        OSSL_DECODER_CTX *dctx;
45        EVP_PKEY *pkey = NULL;
46        const char *format = "PEM";   /* NULL for any format */
47        const char *structure = NULL; /* any structure */
48        const char *keytype = "RSA";  /* NULL for any key */
49        const unsigned char *pass = "my password";
50
51        dctx = OSSL_DECODER_CTX_new_for_pkey(&pkey, format, structure,
52                                             keytype,
53                                             OSSL_KEYMGMT_SELECT_KEYPAIR,
54                                             NULL, NULL);
55        if (dctx == NULL) {
56            /* error: no suitable potential decoders found */
57        }
58        if (pass != NULL)
59            OSSL_DECODER_CTX_set_passphrase(dctx, pass, strlen(pass));
60        if (OSSL_DECODER_from_bio(dctx, bio)) {
61            /* pkey is created with the decoded data from the bio */
62        } else {
63            /* decoding failure */
64        }
65        OSSL_DECODER_CTX_free(dctx);
66
67       To decode an EC key encoded with DER from a buffer:
68
69        OSSL_DECODER_CTX *dctx;
70        EVP_PKEY *pkey = NULL;
71        const char *format = "DER";   /* NULL for any format */
72        const char *structure = NULL; /* any structure */
73        const char *keytype = "EC";   /* NULL for any key */
74        const unsigned char *pass = NULL
75        const unsigned char *data = buffer;
76        size_t datalen = sizeof(buffer);
77
78        dctx = OSSL_DECODER_CTX_new_for_pkey(&pkey, format, structure,
79                                             keytype,
80                                             OSSL_KEYMGMT_SELECT_KEYPAIR
81                                             | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS,
82                                             NULL, NULL);
83        if (dctx == NULL) {
84            /* error: no suitable potential decoders found */
85        }
86        if (pass != NULL)
87            OSSL_DECODER_CTX_set_passphrase(dctx, pass, strlen(pass));
88        if (OSSL_DECODER_from_data(dctx, &data, &datalen)) {
89            /* pkey is created with the decoded data from the buffer */
90        } else {
91            /* decoding failure */
92        }
93        OSSL_DECODER_CTX_free(dctx);
94

SEE ALSO

96       provider(7), OSSL_DECODER_CTX(3)
97

HISTORY

99       The functions described here were added in OpenSSL 3.0.
100
102       Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
103
104       Licensed under the Apache License 2.0 (the "License").  You may not use
105       this file except in compliance with the License.  You can obtain a copy
106       in the file LICENSE in the source distribution or at
107       <https://www.openssl.org/source/license.html>.
108
109
110
1113.0.5                             2022-11-01      OSSL_DECODER_FROM_BIO(3ossl)
Impressum