serializer_lib.c 1009 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. #include <openssl/bio.h>
  10. #include <openssl/serializer.h>
  11. #include "serializer_local.h"
  12. int OSSL_SERIALIZER_to_bio(OSSL_SERIALIZER_CTX *ctx, BIO *out)
  13. {
  14. return ctx->do_output(ctx, out);
  15. }
  16. #ifndef OPENSSL_NO_STDIO
  17. static BIO *bio_from_file(FILE *fp)
  18. {
  19. BIO *b;
  20. if ((b = BIO_new(BIO_s_file())) == NULL) {
  21. ERR_raise(ERR_LIB_OSSL_SERIALIZER, ERR_R_BUF_LIB);
  22. return NULL;
  23. }
  24. BIO_set_fp(b, fp, BIO_NOCLOSE);
  25. return b;
  26. }
  27. int OSSL_SERIALIZER_to_fp(OSSL_SERIALIZER_CTX *ctx, FILE *fp)
  28. {
  29. BIO *b = bio_from_file(fp);
  30. int ret = 0;
  31. if (b != NULL)
  32. ret = OSSL_SERIALIZER_to_bio(ctx, b);
  33. BIO_free(b);
  34. return ret;
  35. }
  36. #endif