source: EcnlProtoTool/trunk/openssl-1.1.0e/crypto/asn1/a_i2d_fp.c@ 331

Last change on this file since 331 was 331, checked in by coas-nagasima, 6 years ago

prototoolに関連するプロジェクトをnewlibからmuslを使うよう変更・更新
ntshellをnewlibの下位の実装から、muslのsyscallの実装に変更・更新
以下のOSSをアップデート
・mruby-1.3.0
・musl-1.1.18
・onigmo-6.1.3
・tcc-0.9.27
以下のOSSを追加
・openssl-1.1.0e
・curl-7.57.0
・zlib-1.2.11
以下のmrbgemsを追加
・iij/mruby-digest
・iij/mruby-env
・iij/mruby-errno
・iij/mruby-iijson
・iij/mruby-ipaddr
・iij/mruby-mock
・iij/mruby-require
・iij/mruby-tls-openssl

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc
File size: 2.2 KB
Line 
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 <stdio.h>
11#include "internal/cryptlib.h"
12#include <openssl/buffer.h>
13#include <openssl/asn1.h>
14
15#ifndef NO_OLD_ASN1
16
17# ifndef OPENSSL_NO_STDIO
18int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x)
19{
20 BIO *b;
21 int ret;
22
23 if ((b = BIO_new(BIO_s_file())) == NULL) {
24 ASN1err(ASN1_F_ASN1_I2D_FP, ERR_R_BUF_LIB);
25 return (0);
26 }
27 BIO_set_fp(b, out, BIO_NOCLOSE);
28 ret = ASN1_i2d_bio(i2d, b, x);
29 BIO_free(b);
30 return (ret);
31}
32# endif
33
34int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x)
35{
36 char *b;
37 unsigned char *p;
38 int i, j = 0, n, ret = 1;
39
40 n = i2d(x, NULL);
41 b = OPENSSL_malloc(n);
42 if (b == NULL) {
43 ASN1err(ASN1_F_ASN1_I2D_BIO, ERR_R_MALLOC_FAILURE);
44 return (0);
45 }
46
47 p = (unsigned char *)b;
48 i2d(x, &p);
49
50 for (;;) {
51 i = BIO_write(out, &(b[j]), n);
52 if (i == n)
53 break;
54 if (i <= 0) {
55 ret = 0;
56 break;
57 }
58 j += i;
59 n -= i;
60 }
61 OPENSSL_free(b);
62 return (ret);
63}
64
65#endif
66
67#ifndef OPENSSL_NO_STDIO
68int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x)
69{
70 BIO *b;
71 int ret;
72
73 if ((b = BIO_new(BIO_s_file())) == NULL) {
74 ASN1err(ASN1_F_ASN1_ITEM_I2D_FP, ERR_R_BUF_LIB);
75 return (0);
76 }
77 BIO_set_fp(b, out, BIO_NOCLOSE);
78 ret = ASN1_item_i2d_bio(it, b, x);
79 BIO_free(b);
80 return (ret);
81}
82#endif
83
84int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x)
85{
86 unsigned char *b = NULL;
87 int i, j = 0, n, ret = 1;
88
89 n = ASN1_item_i2d(x, &b, it);
90 if (b == NULL) {
91 ASN1err(ASN1_F_ASN1_ITEM_I2D_BIO, ERR_R_MALLOC_FAILURE);
92 return (0);
93 }
94
95 for (;;) {
96 i = BIO_write(out, &(b[j]), n);
97 if (i == n)
98 break;
99 if (i <= 0) {
100 ret = 0;
101 break;
102 }
103 j += i;
104 n -= i;
105 }
106 OPENSSL_free(b);
107 return (ret);
108}
Note: See TracBrowser for help on using the repository browser.