check_chain_extensions(): Add check that Basic Constraints of CA cert are marked...
[openssl.git] / include / openssl / decoder.h
1 /*
2  * Copyright 2020 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_DECODER_H
11 # define OPENSSL_DECODER_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/decodererr.h>
22 # include <openssl/types.h>
23 # include <openssl/core.h>
24
25 # ifdef __cplusplus
26 extern "C" {
27 # endif
28
29 OSSL_DECODER *OSSL_DECODER_fetch(OPENSSL_CTX *libctx, const char *name,
30                                  const char *properties);
31 int OSSL_DECODER_up_ref(OSSL_DECODER *encoder);
32 void OSSL_DECODER_free(OSSL_DECODER *encoder);
33
34 const OSSL_PROVIDER *OSSL_DECODER_provider(const OSSL_DECODER *encoder);
35 const char *OSSL_DECODER_properties(const OSSL_DECODER *encoder);
36 int OSSL_DECODER_number(const OSSL_DECODER *encoder);
37 int OSSL_DECODER_is_a(const OSSL_DECODER *encoder, const char *name);
38
39 void OSSL_DECODER_do_all_provided(OPENSSL_CTX *libctx,
40                                   void (*fn)(OSSL_DECODER *encoder, void *arg),
41                                   void *arg);
42 void OSSL_DECODER_names_do_all(const OSSL_DECODER *encoder,
43                                void (*fn)(const char *name, void *data),
44                                void *data);
45 const OSSL_PARAM *OSSL_DECODER_gettable_params(OSSL_DECODER *decoder);
46 int OSSL_DECODER_get_params(OSSL_DECODER *decoder, OSSL_PARAM params[]);
47
48 const OSSL_PARAM *OSSL_DECODER_settable_ctx_params(OSSL_DECODER *encoder);
49 OSSL_DECODER_CTX *OSSL_DECODER_CTX_new(void);
50 int OSSL_DECODER_CTX_set_params(OSSL_DECODER_CTX *ctx,
51                                 const OSSL_PARAM params[]);
52 void OSSL_DECODER_CTX_free(OSSL_DECODER_CTX *ctx);
53
54 /* Utilities that help set specific parameters */
55 int OSSL_DECODER_CTX_set_passphrase(OSSL_DECODER_CTX *ctx,
56                                     const unsigned char *kstr,
57                                     size_t klen);
58 int OSSL_DECODER_CTX_set_pem_password_cb(OSSL_DECODER_CTX *ctx,
59                                          pem_password_cb *cb,
60                                          void *cbarg);
61 int OSSL_DECODER_CTX_set_passphrase_cb(OSSL_DECODER_CTX *ctx,
62                                        OSSL_PASSPHRASE_CALLBACK *cb,
63                                        void *cbarg);
64 int OSSL_DECODER_CTX_set_passphrase_ui(OSSL_DECODER_CTX *ctx,
65                                        const UI_METHOD *ui_method,
66                                        void *ui_data);
67
68 /*
69  * Utilities to read the object to decode, with the result sent to cb.
70  * These will discover all provided methods
71  */
72
73 int OSSL_DECODER_CTX_set_input_type(OSSL_DECODER_CTX *ctx,
74                                     const char *input_type);
75 int OSSL_DECODER_CTX_add_decoder(OSSL_DECODER_CTX *ctx, OSSL_DECODER *decoder);
76 int OSSL_DECODER_CTX_add_extra(OSSL_DECODER_CTX *ctx,
77                                OPENSSL_CTX *libctx, const char *propq);
78 int OSSL_DECODER_CTX_num_decoders(OSSL_DECODER_CTX *ctx);
79
80 typedef struct ossl_decoder_instance_st OSSL_DECODER_INSTANCE;
81 OSSL_DECODER *
82 OSSL_DECODER_INSTANCE_decoder(OSSL_DECODER_INSTANCE *decoder_inst);
83 void *OSSL_DECODER_INSTANCE_decoder_ctx(OSSL_DECODER_INSTANCE *decoder_inst);
84
85 typedef int (OSSL_DECODER_CONSTRUCT)(OSSL_DECODER_INSTANCE *decoder_inst,
86                                      const OSSL_PARAM *params,
87                                      void *construct_data);
88 typedef void (OSSL_DECODER_CLEANUP)(void *construct_data);
89
90 int OSSL_DECODER_CTX_set_construct(OSSL_DECODER_CTX *ctx,
91                                    OSSL_DECODER_CONSTRUCT *construct);
92 int OSSL_DECODER_CTX_set_construct_data(OSSL_DECODER_CTX *ctx,
93                                         void *construct_data);
94 int OSSL_DECODER_CTX_set_cleanup(OSSL_DECODER_CTX *ctx,
95                                  OSSL_DECODER_CLEANUP *cleanup);
96 OSSL_DECODER_CONSTRUCT *OSSL_DECODER_CTX_get_construct(OSSL_DECODER_CTX *ctx);
97 void *OSSL_DECODER_CTX_get_construct_data(OSSL_DECODER_CTX *ctx);
98 OSSL_DECODER_CLEANUP *OSSL_DECODER_CTX_get_cleanup(OSSL_DECODER_CTX *ctx);
99
100 int OSSL_DECODER_export(OSSL_DECODER_INSTANCE *decoder_inst,
101                         void *reference, size_t reference_sz,
102                         OSSL_CALLBACK *export_cb, void *export_cbarg);
103
104 int OSSL_DECODER_from_bio(OSSL_DECODER_CTX *ctx, BIO *in);
105 #ifndef OPENSSL_NO_STDIO
106 int OSSL_DECODER_from_fp(OSSL_DECODER_CTX *ctx, FILE *in);
107 #endif
108
109 /*
110  * Create the OSSL_DECODER_CTX with an associated type.  This will perform
111  * an implicit OSSL_DECODER_fetch(), suitable for the object of that type.
112  */
113 OSSL_DECODER_CTX *
114 OSSL_DECODER_CTX_new_by_EVP_PKEY(EVP_PKEY **pkey, const char *input_type,
115                                  OPENSSL_CTX *libctx, const char *propquery);
116
117 # ifdef __cplusplus
118 }
119 # endif
120 #endif