# provider-encoder(7ssl) - man - phpMan

[PROVIDER-ENCODER(7SSL)](https://www.chedong.com/phpMan.php/man/PROVIDER-ENCODER/7SSL/markdown)                         OpenSSL                        [PROVIDER-ENCODER(7SSL)](https://www.chedong.com/phpMan.php/man/PROVIDER-ENCODER/7SSL/markdown)



## NAME
       provider-encoder - The OSSL_ENCODER library <-> provider functions

## SYNOPSIS
        #include <openssl/core_dispatch.h>

        /*
         * None of these are actual functions, but are displayed like this for
         * the function signatures for functions that are offered as function
         * pointers in OSSL_DISPATCH arrays.
         */

        /* Encoder parameter accessor and descriptor */
        const OSSL_PARAM *OSSL_FUNC_encoder_gettable_params(void *provctx);
        int OSSL_FUNC_encoder_get_params(OSSL_PARAM params[]);

        /* Functions to construct / destruct / manipulate the encoder context */
        void *OSSL_FUNC_encoder_newctx(void *provctx);
        void OSSL_FUNC_encoder_freectx(void *ctx);
        int OSSL_FUNC_encoder_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
        const OSSL_PARAM *OSSL_FUNC_encoder_settable_ctx_params(void *provctx);

        /* Functions to check selection support */
        int OSSL_FUNC_encoder_does_selection(void *provctx, int selection);

        /* Functions to encode object data */
        int OSSL_FUNC_encoder_encode(void *ctx, OSSL_CORE_BIO *out,
                                     const void *obj_raw,
                                     const OSSL_PARAM obj_abstract[],
                                     int selection,
                                     OSSL_PASSPHRASE_CALLBACK *cb,
                                     void *cbarg);

        /* Functions to import and free a temporary object to be encoded */
        void *OSSL_FUNC_encoder_import_object(void *ctx, int selection,
                                              const OSSL_PARAM params[]);
        void OSSL_FUNC_encoder_free_object(void *obj);

## DESCRIPTION
       _We_ _use_ _the_ _wide_ _term_ _"encode"_ _in_ _this_ _manual._  _This_ _includes_ _but_ _is_ _not_ _limited_ _to_
       _serialization._

       The ENCODER operation is a generic method to encode a provider-native object (_obj_raw_) or an
       object abstraction (_object_abstract_, see [**provider-object**(7)](https://www.chedong.com/phpMan.php/man/provider-object/7/markdown)) into an encoded form, and write
       the result to the given OSSL_CORE_BIO.  If the caller wants to get the encoded stream to
       memory, it should provide a **BIO**___**s**___**[mem**(3)](https://www.chedong.com/phpMan.php/man/mem/3/markdown) **BIO**.

       The encoder doesn't need to know more about the **OSSL**___**CORE**___**BIO** pointer than being able to pass
       it to the appropriate BIO upcalls (see "Core functions" in [**provider-base**(7)](https://www.chedong.com/phpMan.php/man/provider-base/7/markdown)).

       The ENCODER implementation may be part of a chain, where data is passed from one to the next.
       For example, there may be an implementation to encode an object to DER (that object is
       assumed to be provider-native and thereby passed via _obj_raw_), and another one that encodes
       DER to PEM (that one would receive the DER encoding via _obj_abstract_).

       The encoding using the **OSSL**___**[PARAM**(3)](https://www.chedong.com/phpMan.php/man/PARAM/3/markdown) array form allows a encoder to be used for data that's
       been exported from another provider, and thereby allow them to exist independently of each
       other.

       The encoding using a provider side object can only be safely used with provider data coming
       from the same provider, for example keys with the KEYMGMT provider.

       All "functions" mentioned here are passed as function pointers between _libcrypto_ and the
       provider in **OSSL**___**DISPATCH** arrays via **OSSL**___**ALGORITHM** arrays that are returned by the
       provider's **provider**___**query**___**operation()** function (see "Provider Functions" in
       [**provider-base**(7)](https://www.chedong.com/phpMan.php/man/provider-base/7/markdown)).

       All these "functions" have a corresponding function type definition named
       **OSSL**___**FUNC**___**{name}**___**fn**, and a helper function to retrieve the function pointer from an
       **OSSL**___**DISPATCH** element named **OSSL**___**FUNC**___**{name}**.  For example, the "function"
       **OSSL**___**FUNC**___**encoder**___**encode()** has these:

        typedef int
            (OSSL_FUNC_encoder_encode_fn)(void *ctx, OSSL_CORE_BIO *out,
                                          const void *obj_raw,
                                          const OSSL_PARAM obj_abstract[],
                                          int selection,
                                          OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg);
        static ossl_inline OSSL_FUNC_encoder_encode_fn
            OSSL_FUNC_encoder_encode(const OSSL_DISPATCH *opf);

       **OSSL**___**DISPATCH** arrays are indexed by numbers that are provided as macros in
       **openssl-core**___**[dispatch.h**(7)](https://www.chedong.com/phpMan.php/man/dispatch.h/7/markdown), as follows:

        OSSL_FUNC_encoder_get_params          OSSL_FUNC_ENCODER_GET_PARAMS
        OSSL_FUNC_encoder_gettable_params     OSSL_FUNC_ENCODER_GETTABLE_PARAMS

        OSSL_FUNC_encoder_newctx              OSSL_FUNC_ENCODER_NEWCTX
        OSSL_FUNC_encoder_freectx             OSSL_FUNC_ENCODER_FREECTX
        OSSL_FUNC_encoder_set_ctx_params      OSSL_FUNC_ENCODER_SET_CTX_PARAMS
        OSSL_FUNC_encoder_settable_ctx_params OSSL_FUNC_ENCODER_SETTABLE_CTX_PARAMS

        OSSL_FUNC_encoder_does_selection      OSSL_FUNC_ENCODER_DOES_SELECTION

        OSSL_FUNC_encoder_encode              OSSL_FUNC_ENCODER_ENCODE

        OSSL_FUNC_encoder_import_object       OSSL_FUNC_ENCODER_IMPORT_OBJECT
        OSSL_FUNC_encoder_free_object         OSSL_FUNC_ENCODER_FREE_OBJECT

### Names and properties
       The name of an implementation should match the type of object it handles.  For example, an
       implementation that encodes an RSA key should be named "RSA".  Likewise, an implementation
       that further encodes DER should be named "DER".

       Properties can be used to further specify details about an implementation:

       output
           This property is used to specify what type of output the implementation produces.

           This property is _mandatory_.

           OpenSSL providers recognize the following output types:

           text
               An implementation with that output type outputs human readable text, making that
               implementation suitable for "-text" output in diverse [**openssl**(1)](https://www.chedong.com/phpMan.php/man/openssl/1/markdown) commands.

           pem An implementation with that output type outputs PEM formatted data.

           der An implementation with that output type outputs DER formatted data.

           msblob
               An implementation with that output type outputs MSBLOB formatted data.

           pvk An implementation with that output type outputs PVK formatted data.

       structure
           This property is used to specify the structure that is used for the encoded object.  An
           example could be "pkcs8", to specify explicitly that an object (presumably an asymmetric
           key pair, in this case) will be wrapped in a PKCS#8 structure as part of the encoding.

           This property is _optional_.

       The possible values of both these properties is open ended.  A provider may very well specify
       output types and structures that libcrypto doesn't know anything about.

### Subset selections
       Sometimes, an object has more than one subset of data that is interesting to treat separately
       or together.  It's possible to specify what subsets are to be encoded, with a set of bits
       _selection_ that are passed in an **int**.

       This set of bits depend entirely on what kind of provider-side object is passed.  For
       example, those bits are assumed to be the same as those used with [**provider-keymgmt**(7)](https://www.chedong.com/phpMan.php/man/provider-keymgmt/7/markdown) (see
       "Key Objects" in [**provider-keymgmt**(7)](https://www.chedong.com/phpMan.php/man/provider-keymgmt/7/markdown)) when the object is an asymmetric keypair.

       ENCODER implementations are free to regard the _selection_ as a set of hints, but must do so
       with care.  In the end, the output must make sense, and if there's a corresponding decoder,
       the resulting decoded object must match the original object that was encoded.

       **OSSL**___**FUNC**___**encoder**___**does**___**selection()** should tell if a particular implementation supports any of
       the combinations given by _selection_.

### Context functions
       **OSSL**___**FUNC**___**encoder**___**newctx()** returns a context to be used with the rest of the functions.

       **OSSL**___**FUNC**___**encoder**___**freectx()** frees the given _ctx_, if it was created by
       **OSSL**___**FUNC**___**encoder**___**newctx()**.

       **OSSL**___**FUNC**___**encoder**___**set**___**ctx**___**params()** sets context data according to parameters from _params_ that
       it recognises.  Unrecognised parameters should be ignored.  Passing NULL for _params_ should
       return true.

       **OSSL**___**FUNC**___**encoder**___**settable**___**ctx**___**params()** returns a constant **OSSL**___**PARAM** array describing the
       parameters that **OSSL**___**FUNC**___**encoder**___**set**___**ctx**___**params()** can handle.

       See **OSSL**___**[PARAM**(3)](https://www.chedong.com/phpMan.php/man/PARAM/3/markdown) for further details on the parameters structure used by
       **OSSL**___**FUNC**___**encoder**___**set**___**ctx**___**params()** and **OSSL**___**FUNC**___**encoder**___**settable**___**ctx**___**params()**.

### Import functions
       A provider-native object may be associated with a foreign provider, and may therefore be
       unsuitable for direct use with a given ENCODER implementation.  Provided that the foreign
       provider's implementation to handle the object has a function to export that object in
       **OSSL**___**[PARAM**(3)](https://www.chedong.com/phpMan.php/man/PARAM/3/markdown) array form, the ENCODER implementation should be able to import that array and
       create a suitable object to be passed to **OSSL**___**FUNC**___**encoder**___**encode()**'s _obj_raw_.

       **OSSL**___**FUNC**___**encoder**___**import**___**object()** should import the subset of _params_ given with _selection_ to
       create a provider-native object that can be passed as _obj_raw_ to **OSSL**___**FUNC**___**encoder**___**encode()**.

       **OSSL**___**FUNC**___**encoder**___**free**___**object()** should free the object that was created with
       **OSSL**___**FUNC**___**encoder**___**import**___**object()**.

### Encoding functions
       **OSSL**___**FUNC**___**encoder**___**encode()** should take a provider-native object (in _obj_raw_) or an object
       abstraction (in _obj_abstract_), and should output the object in encoded form to the
       **OSSL**___**CORE**___**BIO**.  The _selection_ bits, if relevant, should determine in greater detail what will
       be output.  The encoding functions also take an **OSSL**___**PASSPHRASE**___**CALLBACK** function pointer
       along with a pointer to application data _cbarg_, which should be used when a pass phrase
       prompt is needed.

### Encoder operation parameters
       Operation parameters currently recognised by built-in encoders are as follows:

       "cipher" (**OSSL**___**ENCODER**___**PARAM**___**CIPHER**) <UTF8 string>
           The name of the encryption cipher to be used when generating encrypted encoding.  This is
           used when encoding private keys, as well as other objects that need protection.

           If this name is invalid for the encoding implementation, the implementation should refuse
           to perform the encoding, i.e.  **OSSL**___**FUNC**___**encoder**___**encode**___**data()** and
           **OSSL**___**FUNC**___**encoder**___**encode**___**object()** should return an error.

       "properties" (**OSSL**___**ENCODER**___**PARAM**___**PROPERTIES**) <UTF8 string>
           The properties to be queried when trying to fetch the algorithm given with the "cipher"
           parameter.  This must be given together with the "cipher" parameter to be considered
           valid.

           The encoding implementation isn't obligated to use this value.  However, it is
           recommended that implementations that do not handle property strings return an error on
           receiving this parameter unless its value NULL or the empty string.

       "save-parameters" (**OSSL**___**ENCODER**___**PARAM**___**SAVE**___**PARAMETERS**) <integer>
           If set to 0 disables saving of key domain parameters. Default is 1.  It currently has an
           effect only on DSA keys.

       Parameters currently recognised by the built-in pass phrase callback:

       "info" (**OSSL**___**PASSPHRASE**___**PARAM**___**INFO**) <UTF8 string>
           A string of information that will become part of the pass phrase prompt.  This could be
           used to give the user information on what kind of object it's being prompted for.

## RETURN VALUES
       **OSSL**___**FUNC**___**encoder**___**newctx()** returns a pointer to a context, or NULL on failure.

       **OSSL**___**FUNC**___**encoder**___**set**___**ctx**___**params()** returns 1, unless a recognised parameter was invalid or
       caused an error, for which 0 is returned.

       **OSSL**___**FUNC**___**encoder**___**settable**___**ctx**___**params()** returns a pointer to an array of constant **OSSL**___**PARAM**
       elements.

       **OSSL**___**FUNC**___**encoder**___**does**___**selection()** returns 1 if the encoder implementation supports any of
       the _selection_ bits, otherwise 0.

       **OSSL**___**FUNC**___**encoder**___**encode()** returns 1 on success, or 0 on failure.

## SEE ALSO
       [**provider**(7)](https://www.chedong.com/phpMan.php/man/provider/7/markdown)

## HISTORY
       The ENCODER interface was introduced in OpenSSL 3.0.

## COPYRIGHT
       Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.

       Licensed under the Apache License 2.0 (the "License").  You may not use this file except in
       compliance with the License.  You can obtain a copy in the file LICENSE in the source
       distribution or at <<https://www.openssl.org/source/license.html>>.



3.0.2                                        2026-04-07                       [PROVIDER-ENCODER(7SSL)](https://www.chedong.com/phpMan.php/man/PROVIDER-ENCODER/7SSL/markdown)
