encoder.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. #ifndef OPENSSL_ENCODER_H
  10. # define OPENSSL_ENCODER_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/encodererr.h>
  19. # include <openssl/types.h>
  20. # include <openssl/core.h>
  21. # ifdef __cplusplus
  22. extern "C" {
  23. # endif
  24. OSSL_ENCODER *OSSL_ENCODER_fetch(OSSL_LIB_CTX *libctx, const char *name,
  25. const char *properties);
  26. int OSSL_ENCODER_up_ref(OSSL_ENCODER *encoder);
  27. void OSSL_ENCODER_free(OSSL_ENCODER *encoder);
  28. const OSSL_PROVIDER *OSSL_ENCODER_get0_provider(const OSSL_ENCODER *encoder);
  29. const char *OSSL_ENCODER_get0_properties(const OSSL_ENCODER *encoder);
  30. const char *OSSL_ENCODER_get0_name(const OSSL_ENCODER *kdf);
  31. const char *OSSL_ENCODER_get0_description(const OSSL_ENCODER *kdf);
  32. int OSSL_ENCODER_is_a(const OSSL_ENCODER *encoder, const char *name);
  33. void OSSL_ENCODER_do_all_provided(OSSL_LIB_CTX *libctx,
  34. void (*fn)(OSSL_ENCODER *encoder, void *arg),
  35. void *arg);
  36. int OSSL_ENCODER_names_do_all(const OSSL_ENCODER *encoder,
  37. void (*fn)(const char *name, void *data),
  38. void *data);
  39. const OSSL_PARAM *OSSL_ENCODER_gettable_params(OSSL_ENCODER *encoder);
  40. int OSSL_ENCODER_get_params(OSSL_ENCODER *encoder, OSSL_PARAM params[]);
  41. const OSSL_PARAM *OSSL_ENCODER_settable_ctx_params(OSSL_ENCODER *encoder);
  42. OSSL_ENCODER_CTX *OSSL_ENCODER_CTX_new(void);
  43. int OSSL_ENCODER_CTX_set_params(OSSL_ENCODER_CTX *ctx,
  44. const OSSL_PARAM params[]);
  45. void OSSL_ENCODER_CTX_free(OSSL_ENCODER_CTX *ctx);
  46. /* Utilities that help set specific parameters */
  47. int OSSL_ENCODER_CTX_set_passphrase(OSSL_ENCODER_CTX *ctx,
  48. const unsigned char *kstr, size_t klen);
  49. int OSSL_ENCODER_CTX_set_pem_password_cb(OSSL_ENCODER_CTX *ctx,
  50. pem_password_cb *cb, void *cbarg);
  51. int OSSL_ENCODER_CTX_set_passphrase_cb(OSSL_ENCODER_CTX *ctx,
  52. OSSL_PASSPHRASE_CALLBACK *cb,
  53. void *cbarg);
  54. int OSSL_ENCODER_CTX_set_passphrase_ui(OSSL_ENCODER_CTX *ctx,
  55. const UI_METHOD *ui_method,
  56. void *ui_data);
  57. int OSSL_ENCODER_CTX_set_cipher(OSSL_ENCODER_CTX *ctx,
  58. const char *cipher_name,
  59. const char *propquery);
  60. int OSSL_ENCODER_CTX_set_selection(OSSL_ENCODER_CTX *ctx, int selection);
  61. int OSSL_ENCODER_CTX_set_output_type(OSSL_ENCODER_CTX *ctx,
  62. const char *output_type);
  63. int OSSL_ENCODER_CTX_set_output_structure(OSSL_ENCODER_CTX *ctx,
  64. const char *output_structure);
  65. /* Utilities to add encoders */
  66. int OSSL_ENCODER_CTX_add_encoder(OSSL_ENCODER_CTX *ctx, OSSL_ENCODER *encoder);
  67. int OSSL_ENCODER_CTX_add_extra(OSSL_ENCODER_CTX *ctx,
  68. OSSL_LIB_CTX *libctx, const char *propq);
  69. int OSSL_ENCODER_CTX_get_num_encoders(OSSL_ENCODER_CTX *ctx);
  70. typedef struct ossl_encoder_instance_st OSSL_ENCODER_INSTANCE;
  71. OSSL_ENCODER *
  72. OSSL_ENCODER_INSTANCE_get_encoder(OSSL_ENCODER_INSTANCE *encoder_inst);
  73. void *
  74. OSSL_ENCODER_INSTANCE_get_encoder_ctx(OSSL_ENCODER_INSTANCE *encoder_inst);
  75. const char *
  76. OSSL_ENCODER_INSTANCE_get_output_type(OSSL_ENCODER_INSTANCE *encoder_inst);
  77. const char *
  78. OSSL_ENCODER_INSTANCE_get_output_structure(OSSL_ENCODER_INSTANCE *encoder_inst);
  79. typedef const void *OSSL_ENCODER_CONSTRUCT(OSSL_ENCODER_INSTANCE *encoder_inst,
  80. void *construct_data);
  81. typedef void OSSL_ENCODER_CLEANUP(void *construct_data);
  82. int OSSL_ENCODER_CTX_set_construct(OSSL_ENCODER_CTX *ctx,
  83. OSSL_ENCODER_CONSTRUCT *construct);
  84. int OSSL_ENCODER_CTX_set_construct_data(OSSL_ENCODER_CTX *ctx,
  85. void *construct_data);
  86. int OSSL_ENCODER_CTX_set_cleanup(OSSL_ENCODER_CTX *ctx,
  87. OSSL_ENCODER_CLEANUP *cleanup);
  88. /* Utilities to output the object to encode */
  89. int OSSL_ENCODER_to_bio(OSSL_ENCODER_CTX *ctx, BIO *out);
  90. #ifndef OPENSSL_NO_STDIO
  91. int OSSL_ENCODER_to_fp(OSSL_ENCODER_CTX *ctx, FILE *fp);
  92. #endif
  93. int OSSL_ENCODER_to_data(OSSL_ENCODER_CTX *ctx, unsigned char **pdata,
  94. size_t *pdata_len);
  95. /*
  96. * Create the OSSL_ENCODER_CTX with an associated type. This will perform
  97. * an implicit OSSL_ENCODER_fetch(), suitable for the object of that type.
  98. * This is more useful than calling OSSL_ENCODER_CTX_new().
  99. */
  100. OSSL_ENCODER_CTX *OSSL_ENCODER_CTX_new_for_pkey(const EVP_PKEY *pkey,
  101. int selection,
  102. const char *output_type,
  103. const char *output_struct,
  104. const char *propquery);
  105. # ifdef __cplusplus
  106. }
  107. # endif
  108. #endif