i2d_pu.c 1.0 KB
Newer Older
R
Rich Salz 已提交
1 2
/*
 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3
 *
R
Rich Salz 已提交
4 5 6 7
 * Licensed under the OpenSSL license (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
8 9 10
 */

#include <stdio.h>
11
#include "internal/cryptlib.h"
12 13 14
#include <openssl/bn.h>
#include <openssl/evp.h>
#include <openssl/objects.h>
R
Rich Salz 已提交
15 16 17
#include <openssl/rsa.h>
#include <openssl/dsa.h>
#include <openssl/ec.h>
18

U
Ulf Möller 已提交
19
int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp)
20
{
D
Dr. Stephen Henson 已提交
21
    switch (EVP_PKEY_id(a)) {
22
#ifndef OPENSSL_NO_RSA
23
    case EVP_PKEY_RSA:
D
Dr. Stephen Henson 已提交
24
        return i2d_RSAPublicKey(EVP_PKEY_get0_RSA(a), pp);
25
#endif
26
#ifndef OPENSSL_NO_DSA
27
    case EVP_PKEY_DSA:
D
Dr. Stephen Henson 已提交
28
        return i2d_DSAPublicKey(EVP_PKEY_get0_DSA(a), pp);
B
Bodo Möller 已提交
29
#endif
30
#ifndef OPENSSL_NO_EC
31
    case EVP_PKEY_EC:
D
Dr. Stephen Henson 已提交
32
        return i2o_ECPublicKey(EVP_PKEY_get0_EC_KEY(a), pp);
33
#endif
34 35
    default:
        ASN1err(ASN1_F_I2D_PUBLICKEY, ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
D
Dr. Stephen Henson 已提交
36
        return -1;
37 38
    }
}