]> git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/encode_decode/encoder_lib.c
Rename OSSL_SERIALIZER / OSSL_DESERIALIZER to OSSL_ENCODE / OSSL_DECODE
[thirdparty/openssl.git] / crypto / encode_decode / encoder_lib.c
1 /*
2 * Copyright 2019 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 #include <openssl/bio.h>
11 #include <openssl/encoder.h>
12 #include "encoder_local.h"
13
14 int OSSL_ENCODER_to_bio(OSSL_ENCODER_CTX *ctx, BIO *out)
15 {
16 return ctx->do_output(ctx, out);
17 }
18
19 #ifndef OPENSSL_NO_STDIO
20 static BIO *bio_from_file(FILE *fp)
21 {
22 BIO *b;
23
24 if ((b = BIO_new(BIO_s_file())) == NULL) {
25 ERR_raise(ERR_LIB_OSSL_ENCODER, ERR_R_BUF_LIB);
26 return NULL;
27 }
28 BIO_set_fp(b, fp, BIO_NOCLOSE);
29 return b;
30 }
31
32 int OSSL_ENCODER_to_fp(OSSL_ENCODER_CTX *ctx, FILE *fp)
33 {
34 BIO *b = bio_from_file(fp);
35 int ret = 0;
36
37 if (b != NULL)
38 ret = OSSL_ENCODER_to_bio(ctx, b);
39
40 BIO_free(b);
41 return ret;
42 }
43 #endif