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/serializer.h>
12#include "serializer_local.h"
13
14int OSSL_SERIALIZER_to_bio(OSSL_SERIALIZER_CTX *ctx, BIO *out)
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) {
25 ERR_raise(ERR_LIB_OSSL_SERIALIZER, ERR_R_BUF_LIB);
26 return NULL;
27 }
28 BIO_set_fp(b, fp, BIO_NOCLOSE);
29 return b;
30}
31
32int OSSL_SERIALIZER_to_fp(OSSL_SERIALIZER_CTX *ctx, FILE *fp)
33{
34 BIO *b = bio_from_file(fp);
35 int ret = 0;
36
37 if (b != NULL)
38 ret = OSSL_SERIALIZER_to_bio(ctx, b);
39
40 BIO_free(b);
41 return ret;
42}
43#endif
44