]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/asn1/a_i2d_fp.c
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
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
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
, void *x
)
23 if ((b
= BIO_new(BIO_s_file())) == NULL
) {
24 ASN1err(ASN1_F_ASN1_I2D_FP
, 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
, unsigned char *x
)
38 int i
, j
= 0, n
, ret
= 1;
41 b
= OPENSSL_malloc(n
);
43 ASN1err(ASN1_F_ASN1_I2D_BIO
, ERR_R_MALLOC_FAILURE
);
47 p
= (unsigned char *)b
;
51 i
= BIO_write(out
, &(b
[j
]), n
);
67 #ifndef OPENSSL_NO_STDIO
68 int ASN1_item_i2d_fp(const ASN1_ITEM
*it
, FILE *out
, void *x
)
73 if ((b
= BIO_new(BIO_s_file())) == NULL
) {
74 ASN1err(ASN1_F_ASN1_ITEM_I2D_FP
, ERR_R_BUF_LIB
);
77 BIO_set_fp(b
, out
, BIO_NOCLOSE
);
78 ret
= ASN1_item_i2d_bio(it
, b
, x
);
84 int ASN1_item_i2d_bio(const ASN1_ITEM
*it
, BIO
*out
, void *x
)
86 unsigned char *b
= NULL
;
87 int i
, j
= 0, n
, ret
= 1;
89 n
= ASN1_item_i2d(x
, &b
, it
);
91 ASN1err(ASN1_F_ASN1_ITEM_I2D_BIO
, ERR_R_MALLOC_FAILURE
);
96 i
= BIO_write(out
, &(b
[j
]), n
);