Rename all getters to use get/get0 in name
[openssl.git] / include / openssl / encoder.h
1 /*
2  * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 #ifndef OPENSSL_ENCODER_H
11 # define OPENSSL_ENCODER_H
12 # pragma once
13
14 # include <openssl/opensslconf.h>
15
16 # ifndef OPENSSL_NO_STDIO
17 #  include <stdio.h>
18 # endif
19 # include <stdarg.h>
20 # include <stddef.h>
21 # include <openssl/encodererr.h>
22 # include <openssl/types.h>
23 # include <openssl/core.h>
24
25 # ifdef __cplusplus
26 extern "C" {
27 # endif
28
29 OSSL_ENCODER *OSSL_ENCODER_fetch(OSSL_LIB_CTX *libctx, const char *name,
30                                  const char *properties);
31 int OSSL_ENCODER_up_ref(OSSL_ENCODER *encoder);
32 void OSSL_ENCODER_free(OSSL_ENCODER *encoder);
33
34 const OSSL_PROVIDER *OSSL_ENCODER_get0_provider(const OSSL_ENCODER *encoder);
35 const char *OSSL_ENCODER_get0_properties(const OSSL_ENCODER *encoder);
36 int OSSL_ENCODER_get_number(const OSSL_ENCODER *encoder);
37 const char *OSSL_ENCODER_get0_name(const OSSL_ENCODER *kdf);
38 const char *OSSL_ENCODER_get0_description(const OSSL_ENCODER *kdf);
39 int OSSL_ENCODER_is_a(const OSSL_ENCODER *encoder, const char *name);
40
41 void OSSL_ENCODER_do_all_provided(OSSL_LIB_CTX *libctx,
42                                   void (*fn)(OSSL_ENCODER *encoder, void *arg),
43                                   void *arg);
44 int OSSL_ENCODER_names_do_all(const OSSL_ENCODER *encoder,
45                               void (*fn)(const char *name, void *data),
46                               void *data);
47 const OSSL_PARAM *OSSL_ENCODER_gettable_params(OSSL_ENCODER *encoder);
48 int OSSL_ENCODER_get_params(OSSL_ENCODER *encoder, OSSL_PARAM params[]);
49
50 const OSSL_PARAM *OSSL_ENCODER_settable_ctx_params(OSSL_ENCODER *encoder);
51 OSSL_ENCODER_CTX *OSSL_ENCODER_CTX_new(void);
52 int OSSL_ENCODER_CTX_set_params(OSSL_ENCODER_CTX *ctx,
53                                 const OSSL_PARAM params[]);
54 void OSSL_ENCODER_CTX_free(OSSL_ENCODER_CTX *ctx);
55
56 /* Utilities that help set specific parameters */
57 int OSSL_ENCODER_CTX_set_passphrase(OSSL_ENCODER_CTX *ctx,
58                                     const unsigned char *kstr, size_t klen);
59 int OSSL_ENCODER_CTX_set_pem_password_cb(OSSL_ENCODER_CTX *ctx,
60                                          pem_password_cb *cb, void *cbarg);
61 int OSSL_ENCODER_CTX_set_passphrase_cb(OSSL_ENCODER_CTX *ctx,
62                                        OSSL_PASSPHRASE_CALLBACK *cb,
63                                        void *cbarg);
64 int OSSL_ENCODER_CTX_set_passphrase_ui(OSSL_ENCODER_CTX *ctx,
65                                        const UI_METHOD *ui_method,
66                                        void *ui_data);
67 int OSSL_ENCODER_CTX_set_cipher(OSSL_ENCODER_CTX *ctx,
68                                 const char *cipher_name,
69                                 const char *propquery);
70 int OSSL_ENCODER_CTX_set_selection(OSSL_ENCODER_CTX *ctx, int selection);
71 int OSSL_ENCODER_CTX_set_output_type(OSSL_ENCODER_CTX *ctx,
72                                      const char *output_type);
73 int OSSL_ENCODER_CTX_set_output_structure(OSSL_ENCODER_CTX *ctx,
74                                           const char *output_structure);
75
76 /* Utilities to add encoders */
77 int OSSL_ENCODER_CTX_add_encoder(OSSL_ENCODER_CTX *ctx, OSSL_ENCODER *encoder);
78 int OSSL_ENCODER_CTX_add_extra(OSSL_ENCODER_CTX *ctx,
79                                OSSL_LIB_CTX *libctx, const char *propq);
80 int OSSL_ENCODER_CTX_get_num_encoders(OSSL_ENCODER_CTX *ctx);
81
82 typedef struct ossl_encoder_instance_st OSSL_ENCODER_INSTANCE;
83 OSSL_ENCODER *
84 OSSL_ENCODER_INSTANCE_get_encoder(OSSL_ENCODER_INSTANCE *encoder_inst);
85 void *
86 OSSL_ENCODER_INSTANCE_get_encoder_ctx(OSSL_ENCODER_INSTANCE *encoder_inst);
87 const char *
88 OSSL_ENCODER_INSTANCE_get_input_type(OSSL_ENCODER_INSTANCE *encoder_inst);
89 const char *
90 OSSL_ENCODER_INSTANCE_get_output_type(OSSL_ENCODER_INSTANCE *encoder_inst);
91 const char *
92 OSSL_ENCODER_INSTANCE_get_output_structure(OSSL_ENCODER_INSTANCE *encoder_inst);
93
94 typedef const void *OSSL_ENCODER_CONSTRUCT(OSSL_ENCODER_INSTANCE *encoder_inst,
95                                            void *construct_data);
96 typedef void OSSL_ENCODER_CLEANUP(void *construct_data);
97
98 int OSSL_ENCODER_CTX_set_construct(OSSL_ENCODER_CTX *ctx,
99                                    OSSL_ENCODER_CONSTRUCT *construct);
100 int OSSL_ENCODER_CTX_set_construct_data(OSSL_ENCODER_CTX *ctx,
101                                         void *construct_data);
102 int OSSL_ENCODER_CTX_set_cleanup(OSSL_ENCODER_CTX *ctx,
103                                  OSSL_ENCODER_CLEANUP *cleanup);
104
105 /* Utilities to output the object to encode */
106 int OSSL_ENCODER_to_bio(OSSL_ENCODER_CTX *ctx, BIO *out);
107 #ifndef OPENSSL_NO_STDIO
108 int OSSL_ENCODER_to_fp(OSSL_ENCODER_CTX *ctx, FILE *fp);
109 #endif
110 int OSSL_ENCODER_to_data(OSSL_ENCODER_CTX *ctx, unsigned char **pdata,
111                          size_t *pdata_len);
112
113 /*
114  * Create the OSSL_ENCODER_CTX with an associated type.  This will perform
115  * an implicit OSSL_ENCODER_fetch(), suitable for the object of that type.
116  * This is more useful than calling OSSL_ENCODER_CTX_new().
117  */
118 OSSL_ENCODER_CTX *OSSL_ENCODER_CTX_new_for_pkey(const EVP_PKEY *pkey,
119                                                 int selection,
120                                                 const char *output_type,
121                                                 const char *output_struct,
122                                                 const char *propquery);
123
124 # ifdef __cplusplus
125 }
126 # endif
127 #endif