serializer.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright 2019-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. #ifndef OPENSSL_SERIALIZER_H
  10. # define OPENSSL_SERIALIZER_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/serializererr.h>
  19. # include <openssl/types.h>
  20. # include <openssl/core.h>
  21. # ifdef __cplusplus
  22. extern "C" {
  23. # endif
  24. OSSL_SERIALIZER *OSSL_SERIALIZER_fetch(OPENSSL_CTX *libctx,
  25. const char *name,
  26. const char *properties);
  27. int OSSL_SERIALIZER_up_ref(OSSL_SERIALIZER *ser);
  28. void OSSL_SERIALIZER_free(OSSL_SERIALIZER *ser);
  29. const OSSL_PROVIDER *OSSL_SERIALIZER_provider(const OSSL_SERIALIZER *ser);
  30. const char *OSSL_SERIALIZER_properties(const OSSL_SERIALIZER *ser);
  31. int OSSL_SERIALIZER_number(const OSSL_SERIALIZER *ser);
  32. int OSSL_SERIALIZER_is_a(const OSSL_SERIALIZER *ser,
  33. const char *name);
  34. void OSSL_SERIALIZER_do_all_provided(OPENSSL_CTX *libctx,
  35. void (*fn)(OSSL_SERIALIZER *ser,
  36. void *arg),
  37. void *arg);
  38. void OSSL_SERIALIZER_names_do_all(const OSSL_SERIALIZER *ser,
  39. void (*fn)(const char *name, void *data),
  40. void *data);
  41. const OSSL_PARAM *OSSL_SERIALIZER_settable_ctx_params(OSSL_SERIALIZER *ser);
  42. OSSL_SERIALIZER_CTX *OSSL_SERIALIZER_CTX_new(OSSL_SERIALIZER *ser);
  43. const OSSL_SERIALIZER *
  44. OSSL_SERIALIZER_CTX_get_serializer(OSSL_SERIALIZER_CTX *ctx);
  45. int OSSL_SERIALIZER_CTX_set_params(OSSL_SERIALIZER_CTX *ctx,
  46. const OSSL_PARAM params[]);
  47. void OSSL_SERIALIZER_CTX_free(OSSL_SERIALIZER_CTX *ctx);
  48. /* Utilities that help set specific parameters */
  49. int OSSL_SERIALIZER_CTX_set_cipher(OSSL_SERIALIZER_CTX *ctx,
  50. const char *cipher_name,
  51. const char *propquery);
  52. int OSSL_SERIALIZER_CTX_set_passphrase(OSSL_SERIALIZER_CTX *ctx,
  53. const unsigned char *kstr,
  54. size_t klen);
  55. int OSSL_SERIALIZER_CTX_set_passphrase_cb(OSSL_SERIALIZER_CTX *ctx,
  56. pem_password_cb *cb, void *cbarg);
  57. int OSSL_SERIALIZER_CTX_set_passphrase_ui(OSSL_SERIALIZER_CTX *ctx,
  58. const UI_METHOD *ui_method,
  59. void *ui_data);
  60. /* Utilities to output the object to serialize */
  61. int OSSL_SERIALIZER_to_bio(OSSL_SERIALIZER_CTX *ctx, BIO *out);
  62. #ifndef OPENSSL_NO_STDIO
  63. int OSSL_SERIALIZER_to_fp(OSSL_SERIALIZER_CTX *ctx, FILE *fp);
  64. #endif
  65. /*
  66. * Create the OSSL_SERIALIZER_CTX with an associated type. This will perform
  67. * an implicit OSSL_SERIALIZER_fetch(), suitable for the object of that type.
  68. * This is more useful than calling OSSL_SERIALIZER_CTX_new().
  69. */
  70. OSSL_SERIALIZER_CTX *OSSL_SERIALIZER_CTX_new_by_EVP_PKEY(const EVP_PKEY *pkey,
  71. const char *propquery);
  72. /*
  73. * These macros define the last argument to pass to
  74. * OSSL_SERIALIZER_CTX_new_by_TYPE().
  75. */
  76. # define OSSL_SERIALIZER_PUBKEY_TO_PEM_PQ "format=pem,type=public"
  77. # define OSSL_SERIALIZER_PrivateKey_TO_PEM_PQ "format=pem,type=private"
  78. # define OSSL_SERIALIZER_Parameters_TO_PEM_PQ "format=pem,type=parameters"
  79. # define OSSL_SERIALIZER_PUBKEY_TO_DER_PQ "format=der,type=public"
  80. # define OSSL_SERIALIZER_PrivateKey_TO_DER_PQ "format=der,type=private"
  81. # define OSSL_SERIALIZER_Parameters_TO_DER_PQ "format=der,type=parameters"
  82. /* Corresponding macros for text output */
  83. # define OSSL_SERIALIZER_PUBKEY_TO_TEXT_PQ "format=text,type=public"
  84. # define OSSL_SERIALIZER_PrivateKey_TO_TEXT_PQ "format=text,type=private"
  85. # define OSSL_SERIALIZER_Parameters_TO_TEXT_PQ "format=text,type=parameters"
  86. # ifdef __cplusplus
  87. }
  88. # endif
  89. #endif