1109998Smarkm/* crypto/pem/pem_oth.c */
2109998Smarkm/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3109998Smarkm * All rights reserved.
4109998Smarkm *
5109998Smarkm * This package is an SSL implementation written
6109998Smarkm * by Eric Young (eay@cryptsoft.com).
7109998Smarkm * The implementation was written so as to conform with Netscapes SSL.
8296465Sdelphij *
9109998Smarkm * This library is free for commercial and non-commercial use as long as
10109998Smarkm * the following conditions are aheared to.  The following conditions
11109998Smarkm * apply to all code found in this distribution, be it the RC4, RSA,
12109998Smarkm * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13109998Smarkm * included with this distribution is covered by the same copyright terms
14109998Smarkm * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15296465Sdelphij *
16109998Smarkm * Copyright remains Eric Young's, and as such any Copyright notices in
17109998Smarkm * the code are not to be removed.
18109998Smarkm * If this package is used in a product, Eric Young should be given attribution
19109998Smarkm * as the author of the parts of the library used.
20109998Smarkm * This can be in the form of a textual message at program startup or
21109998Smarkm * in documentation (online or textual) provided with the package.
22296465Sdelphij *
23109998Smarkm * Redistribution and use in source and binary forms, with or without
24109998Smarkm * modification, are permitted provided that the following conditions
25109998Smarkm * are met:
26109998Smarkm * 1. Redistributions of source code must retain the copyright
27109998Smarkm *    notice, this list of conditions and the following disclaimer.
28109998Smarkm * 2. Redistributions in binary form must reproduce the above copyright
29109998Smarkm *    notice, this list of conditions and the following disclaimer in the
30109998Smarkm *    documentation and/or other materials provided with the distribution.
31109998Smarkm * 3. All advertising materials mentioning features or use of this software
32109998Smarkm *    must display the following acknowledgement:
33109998Smarkm *    "This product includes cryptographic software written by
34109998Smarkm *     Eric Young (eay@cryptsoft.com)"
35109998Smarkm *    The word 'cryptographic' can be left out if the rouines from the library
36109998Smarkm *    being used are not cryptographic related :-).
37296465Sdelphij * 4. If you include any Windows specific code (or a derivative thereof) from
38109998Smarkm *    the apps directory (application code) you must include an acknowledgement:
39109998Smarkm *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40296465Sdelphij *
41109998Smarkm * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42109998Smarkm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43109998Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44109998Smarkm * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45109998Smarkm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46109998Smarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47109998Smarkm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48109998Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49109998Smarkm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50109998Smarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51109998Smarkm * SUCH DAMAGE.
52296465Sdelphij *
53109998Smarkm * The licence and distribution terms for any publically available version or
54109998Smarkm * derivative of this code cannot be changed.  i.e. this code cannot simply be
55109998Smarkm * copied and put under another distribution licence
56109998Smarkm * [including the GNU Public Licence.]
57109998Smarkm */
58109998Smarkm
59109998Smarkm#include <stdio.h>
60109998Smarkm#include "cryptlib.h"
61109998Smarkm#include <openssl/buffer.h>
62109998Smarkm#include <openssl/objects.h>
63109998Smarkm#include <openssl/evp.h>
64109998Smarkm#include <openssl/rand.h>
65109998Smarkm#include <openssl/x509.h>
66109998Smarkm#include <openssl/pem.h>
67109998Smarkm
68109998Smarkm/* Handle 'other' PEMs: not private keys */
69109998Smarkm
70160814Ssimonvoid *PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x,
71296465Sdelphij                        pem_password_cb *cb, void *u)
72296465Sdelphij{
73296465Sdelphij    const unsigned char *p = NULL;
74296465Sdelphij    unsigned char *data = NULL;
75296465Sdelphij    long len;
76296465Sdelphij    char *ret = NULL;
77109998Smarkm
78296465Sdelphij    if (!PEM_bytes_read_bio(&data, &len, NULL, name, bp, cb, u))
79296465Sdelphij        return NULL;
80296465Sdelphij    p = data;
81296465Sdelphij    ret = d2i(x, &p, len);
82296465Sdelphij    if (ret == NULL)
83296465Sdelphij        PEMerr(PEM_F_PEM_ASN1_READ_BIO, ERR_R_ASN1_LIB);
84296465Sdelphij    OPENSSL_free(data);
85296465Sdelphij    return (ret);
86296465Sdelphij}
87