]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/pem/pem_local.h
81d1718e327481e0684b2b03236cdb175146dfd8
2 * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
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
11 * TODO(v3.0): the IMPLEMENT macros in include/openssl/pem.h should be
15 #include <openssl/pem.h>
16 #include <openssl/encoder.h>
18 /* Alternative IMPLEMENT macros for provided encoders */
20 # define IMPLEMENT_PEM_provided_write_body_vars(type, asn1) \
22 const char *pq = OSSL_ENCODER_##asn1##_TO_PEM_PQ; \
23 OSSL_ENCODER_CTX *ctx = OSSL_ENCODER_CTX_new_by_##type(x, pq); \
25 if (ctx != NULL && OSSL_ENCODER_CTX_get_encoder(ctx) == NULL) { \
26 OSSL_ENCODER_CTX_free(ctx); \
29 # define IMPLEMENT_PEM_provided_write_body_pass() \
31 if (kstr == NULL && cb == NULL) { \
36 cb = PEM_def_callback; \
41 if (OSSL_ENCODER_CTX_set_cipher(ctx, EVP_CIPHER_name(enc), \
45 && !OSSL_ENCODER_CTX_set_passphrase(ctx, kstr, klen)) \
48 && !OSSL_ENCODER_CTX_set_passphrase_cb(ctx, \
54 OSSL_ENCODER_CTX_free(ctx); \
57 # define IMPLEMENT_PEM_provided_write_body_main(type, outtype) \
58 ret = OSSL_ENCODER_to_##outtype(ctx, out); \
59 OSSL_ENCODER_CTX_free(ctx); \
61 # define IMPLEMENT_PEM_provided_write_body_fallback(str, asn1, \
64 return PEM_ASN1_##writename((i2d_of_void *)i2d_##asn1, str, out, \
65 x, NULL, NULL, 0, NULL, NULL)
66 # define IMPLEMENT_PEM_provided_write_body_fallback_cb(str, asn1, \
69 return PEM_ASN1_##writename((i2d_of_void *)i2d_##asn1, str, out, \
70 x, enc, kstr, klen, cb, u)
72 # define IMPLEMENT_PEM_provided_write_to(name, type, str, asn1, \
73 OUTTYPE, outtype, writename) \
74 PEM_write_fnsig(name, type, OUTTYPE, writename) \
76 IMPLEMENT_PEM_provided_write_body_vars(type, asn1); \
77 IMPLEMENT_PEM_provided_write_body_main(type, outtype); \
78 IMPLEMENT_PEM_provided_write_body_fallback(str, asn1, \
83 # define IMPLEMENT_PEM_provided_write_cb_to(name, type, str, asn1, \
84 OUTTYPE, outtype, writename) \
85 PEM_write_cb_fnsig(name, type, OUTTYPE, writename) \
87 IMPLEMENT_PEM_provided_write_body_vars(type, asn1); \
88 IMPLEMENT_PEM_provided_write_body_pass(); \
89 IMPLEMENT_PEM_provided_write_body_main(type, outtype); \
90 IMPLEMENT_PEM_provided_write_body_fallback_cb(str, asn1, \
94 # ifdef OPENSSL_NO_STDIO
96 # define IMPLEMENT_PEM_provided_write_fp(name, type, str, asn1)
97 # define IMPLEMENT_PEM_provided_write_cb_fp(name, type, str, asn1)
101 # define IMPLEMENT_PEM_provided_write_fp(name, type, str, asn1) \
102 IMPLEMENT_PEM_provided_write_to(name, type, str, asn1, FILE, fp, write)
103 # define IMPLEMENT_PEM_provided_write_cb_fp(name, type, str, asn1) \
104 IMPLEMENT_PEM_provided_write_cb_to(name, type, str, asn1, FILE, fp, write)
108 # define IMPLEMENT_PEM_provided_write_bio(name, type, str, asn1) \
109 IMPLEMENT_PEM_provided_write_to(name, type, str, asn1, BIO, bio, write_bio)
110 # define IMPLEMENT_PEM_provided_write_cb_bio(name, type, str, asn1) \
111 IMPLEMENT_PEM_provided_write_cb_to(name, type, str, asn1, BIO, bio, write_bio)
113 # define IMPLEMENT_PEM_provided_write(name, type, str, asn1) \
114 IMPLEMENT_PEM_provided_write_bio(name, type, str, asn1) \
115 IMPLEMENT_PEM_provided_write_fp(name, type, str, asn1)
117 # define IMPLEMENT_PEM_provided_write_cb(name, type, str, asn1) \
118 IMPLEMENT_PEM_provided_write_cb_bio(name, type, str, asn1) \
119 IMPLEMENT_PEM_provided_write_cb_fp(name, type, str, asn1)
121 # define IMPLEMENT_PEM_provided_rw(name, type, str, asn1) \
122 IMPLEMENT_PEM_read(name, type, str, asn1) \
123 IMPLEMENT_PEM_provided_write(name, type, str, asn1)
125 # define IMPLEMENT_PEM_provided_rw_cb(name, type, str, asn1) \
126 IMPLEMENT_PEM_read(name, type, str, asn1) \
127 IMPLEMENT_PEM_provided_write_cb(name, type, str, asn1)