]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/asn1/a_i2d_fp.c
e718bf4cb150684792d0081756ccee8035939ef1
2 * Copyright 1995-2016 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 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
, const void *x
)
38 int i
, j
= 0, n
, ret
= 1;
44 b
= OPENSSL_malloc(n
);
46 ASN1err(ASN1_F_ASN1_I2D_BIO
, ERR_R_MALLOC_FAILURE
);
50 p
= (unsigned char *)b
;
54 i
= BIO_write(out
, &(b
[j
]), n
);
70 #ifndef OPENSSL_NO_STDIO
71 int ASN1_item_i2d_fp(const ASN1_ITEM
*it
, FILE *out
, const void *x
)
76 if ((b
= BIO_new(BIO_s_file())) == NULL
) {
77 ASN1err(ASN1_F_ASN1_ITEM_I2D_FP
, ERR_R_BUF_LIB
);
80 BIO_set_fp(b
, out
, BIO_NOCLOSE
);
81 ret
= ASN1_item_i2d_bio(it
, b
, x
);
87 int ASN1_item_i2d_bio(const ASN1_ITEM
*it
, BIO
*out
, const void *x
)
89 unsigned char *b
= NULL
;
90 int i
, j
= 0, n
, ret
= 1;
92 n
= ASN1_item_i2d(x
, &b
, it
);
94 ASN1err(ASN1_F_ASN1_ITEM_I2D_BIO
, ERR_R_MALLOC_FAILURE
);
99 i
= BIO_write(out
, &(b
[j
]), n
);