decoder.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright 2020-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. #ifndef OPENSSL_DECODER_H
  10. # define OPENSSL_DECODER_H
  11. # pragma once
  12. # include <openssl/opensslconf.h>
  13. # ifndef OPENSSL_NO_STDIO
  14. # include <stdio.h>
  15. # endif
  16. # include <stdarg.h>
  17. # include <stddef.h>
  18. # include <openssl/decodererr.h>
  19. # include <openssl/types.h>
  20. # include <openssl/core.h>
  21. # ifdef __cplusplus
  22. extern "C" {
  23. # endif
  24. OSSL_DECODER *OSSL_DECODER_fetch(OSSL_LIB_CTX *libctx, const char *name,
  25. const char *properties);
  26. int OSSL_DECODER_up_ref(OSSL_DECODER *encoder);
  27. void OSSL_DECODER_free(OSSL_DECODER *encoder);
  28. const OSSL_PROVIDER *OSSL_DECODER_get0_provider(const OSSL_DECODER *encoder);
  29. const char *OSSL_DECODER_get0_properties(const OSSL_DECODER *encoder);
  30. const char *OSSL_DECODER_get0_name(const OSSL_DECODER *decoder);
  31. const char *OSSL_DECODER_get0_description(const OSSL_DECODER *decoder);
  32. int OSSL_DECODER_is_a(const OSSL_DECODER *encoder, const char *name);
  33. void OSSL_DECODER_do_all_provided(OSSL_LIB_CTX *libctx,
  34. void (*fn)(OSSL_DECODER *encoder, void *arg),
  35. void *arg);
  36. int OSSL_DECODER_names_do_all(const OSSL_DECODER *encoder,
  37. void (*fn)(const char *name, void *data),
  38. void *data);
  39. const OSSL_PARAM *OSSL_DECODER_gettable_params(OSSL_DECODER *decoder);
  40. int OSSL_DECODER_get_params(OSSL_DECODER *decoder, OSSL_PARAM params[]);
  41. const OSSL_PARAM *OSSL_DECODER_settable_ctx_params(OSSL_DECODER *encoder);
  42. OSSL_DECODER_CTX *OSSL_DECODER_CTX_new(void);
  43. int OSSL_DECODER_CTX_set_params(OSSL_DECODER_CTX *ctx,
  44. const OSSL_PARAM params[]);
  45. void OSSL_DECODER_CTX_free(OSSL_DECODER_CTX *ctx);
  46. /* Utilities that help set specific parameters */
  47. int OSSL_DECODER_CTX_set_passphrase(OSSL_DECODER_CTX *ctx,
  48. const unsigned char *kstr, size_t klen);
  49. int OSSL_DECODER_CTX_set_pem_password_cb(OSSL_DECODER_CTX *ctx,
  50. pem_password_cb *cb, void *cbarg);
  51. int OSSL_DECODER_CTX_set_passphrase_cb(OSSL_DECODER_CTX *ctx,
  52. OSSL_PASSPHRASE_CALLBACK *cb,
  53. void *cbarg);
  54. int OSSL_DECODER_CTX_set_passphrase_ui(OSSL_DECODER_CTX *ctx,
  55. const UI_METHOD *ui_method,
  56. void *ui_data);
  57. /*
  58. * Utilities to read the object to decode, with the result sent to cb.
  59. * These will discover all provided methods
  60. */
  61. int OSSL_DECODER_CTX_set_selection(OSSL_DECODER_CTX *ctx, int selection);
  62. int OSSL_DECODER_CTX_set_input_type(OSSL_DECODER_CTX *ctx,
  63. const char *input_type);
  64. int OSSL_DECODER_CTX_set_input_structure(OSSL_DECODER_CTX *ctx,
  65. const char *input_structure);
  66. int OSSL_DECODER_CTX_add_decoder(OSSL_DECODER_CTX *ctx, OSSL_DECODER *decoder);
  67. int OSSL_DECODER_CTX_add_extra(OSSL_DECODER_CTX *ctx,
  68. OSSL_LIB_CTX *libctx, const char *propq);
  69. int OSSL_DECODER_CTX_get_num_decoders(OSSL_DECODER_CTX *ctx);
  70. typedef struct ossl_decoder_instance_st OSSL_DECODER_INSTANCE;
  71. OSSL_DECODER *
  72. OSSL_DECODER_INSTANCE_get_decoder(OSSL_DECODER_INSTANCE *decoder_inst);
  73. void *
  74. OSSL_DECODER_INSTANCE_get_decoder_ctx(OSSL_DECODER_INSTANCE *decoder_inst);
  75. const char *
  76. OSSL_DECODER_INSTANCE_get_input_type(OSSL_DECODER_INSTANCE *decoder_inst);
  77. const char *
  78. OSSL_DECODER_INSTANCE_get_input_structure(OSSL_DECODER_INSTANCE *decoder_inst,
  79. int *was_set);
  80. typedef int OSSL_DECODER_CONSTRUCT(OSSL_DECODER_INSTANCE *decoder_inst,
  81. const OSSL_PARAM *params,
  82. void *construct_data);
  83. typedef void OSSL_DECODER_CLEANUP(void *construct_data);
  84. int OSSL_DECODER_CTX_set_construct(OSSL_DECODER_CTX *ctx,
  85. OSSL_DECODER_CONSTRUCT *construct);
  86. int OSSL_DECODER_CTX_set_construct_data(OSSL_DECODER_CTX *ctx,
  87. void *construct_data);
  88. int OSSL_DECODER_CTX_set_cleanup(OSSL_DECODER_CTX *ctx,
  89. OSSL_DECODER_CLEANUP *cleanup);
  90. OSSL_DECODER_CONSTRUCT *OSSL_DECODER_CTX_get_construct(OSSL_DECODER_CTX *ctx);
  91. void *OSSL_DECODER_CTX_get_construct_data(OSSL_DECODER_CTX *ctx);
  92. OSSL_DECODER_CLEANUP *OSSL_DECODER_CTX_get_cleanup(OSSL_DECODER_CTX *ctx);
  93. int OSSL_DECODER_export(OSSL_DECODER_INSTANCE *decoder_inst,
  94. void *reference, size_t reference_sz,
  95. OSSL_CALLBACK *export_cb, void *export_cbarg);
  96. int OSSL_DECODER_from_bio(OSSL_DECODER_CTX *ctx, BIO *in);
  97. #ifndef OPENSSL_NO_STDIO
  98. int OSSL_DECODER_from_fp(OSSL_DECODER_CTX *ctx, FILE *in);
  99. #endif
  100. int OSSL_DECODER_from_data(OSSL_DECODER_CTX *ctx, const unsigned char **pdata,
  101. size_t *pdata_len);
  102. /*
  103. * Create the OSSL_DECODER_CTX with an associated type. This will perform
  104. * an implicit OSSL_DECODER_fetch(), suitable for the object of that type.
  105. */
  106. OSSL_DECODER_CTX *
  107. OSSL_DECODER_CTX_new_for_pkey(EVP_PKEY **pkey,
  108. const char *input_type,
  109. const char *input_struct,
  110. const char *keytype, int selection,
  111. OSSL_LIB_CTX *libctx, const char *propquery);
  112. # ifdef __cplusplus
  113. }
  114. # endif
  115. #endif