2 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
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
11 #include "internal/cryptlib.h"
12 #include <openssl/buffer.h>
13 #include <openssl/asn1.h>
17 # ifndef OPENSSL_NO_STDIO
18 int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, const void *x)
23 if ((b = BIO_new(BIO_s_file())) == NULL) {
24 ERR_raise(ERR_LIB_ASN1, ERR_R_BUF_LIB);
27 BIO_set_fp(b, out, BIO_NOCLOSE);
28 ret = ASN1_i2d_bio(i2d, b, x);
34 int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, const void *x)
38 int i, j = 0, n, ret = 1;
44 b = OPENSSL_malloc(n);
48 p = (unsigned char *)b;
52 i = BIO_write(out, &(b[j]), n);
68 #ifndef OPENSSL_NO_STDIO
69 int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, const void *x)
74 if ((b = BIO_new(BIO_s_file())) == NULL) {
75 ERR_raise(ERR_LIB_ASN1, ERR_R_BUF_LIB);
78 BIO_set_fp(b, out, BIO_NOCLOSE);
79 ret = ASN1_item_i2d_bio(it, b, x);
85 int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, const void *x)
87 unsigned char *b = NULL;
88 int i, j = 0, n, ret = 1;
90 n = ASN1_item_i2d(x, &b, it);
92 ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
97 i = BIO_write(out, &(b[j]), n);
111 BIO *ASN1_item_i2d_mem_bio(const ASN1_ITEM *it, const ASN1_VALUE *val)
115 if (it == NULL || val == NULL) {
116 ERR_raise(ERR_LIB_ASN1, ERR_R_PASSED_NULL_PARAMETER);
120 if ((res = BIO_new(BIO_s_mem())) == NULL)
122 if (ASN1_item_i2d_bio(it, res, val) <= 0) {