1 /*
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (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/asn1.h>
11
12 #include <openssl/bio.h>
13 #include <openssl/err.h>
14 #include <openssl/mem.h>
15
16
ASN1_item_i2d_fp(const ASN1_ITEM * it,FILE * out,void * x)17 int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x) {
18 BIO *b = BIO_new_fp(out, BIO_NOCLOSE);
19 if (b == NULL) {
20 OPENSSL_PUT_ERROR(ASN1, ERR_R_BUF_LIB);
21 return 0;
22 }
23 int ret = ASN1_item_i2d_bio(it, b, x);
24 BIO_free(b);
25 return ret;
26 }
27
ASN1_item_i2d_bio(const ASN1_ITEM * it,BIO * out,void * x)28 int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x) {
29 unsigned char *b = NULL;
30 int n = ASN1_item_i2d(reinterpret_cast<ASN1_VALUE *>(x), &b, it);
31 if (b == NULL) {
32 return 0;
33 }
34
35 int ret = BIO_write_all(out, b, n);
36 OPENSSL_free(b);
37 return ret;
38 }
39