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