Botan 3.0.0-alpha0
Crypto and TLS for C&
x509_key.h
Go to the documentation of this file.
1/*
2* X.509 Public Key
3* (C) 1999-2010 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_X509_PUBLIC_KEY_H_
9#define BOTAN_X509_PUBLIC_KEY_H_
10
11#include <botan/pk_keys.h>
12#include <botan/data_src.h>
13#include <string>
14#include <vector>
15
16namespace Botan {
17
18/**
19* This namespace contains functions for handling X.509 public keys
20*/
21namespace X509 {
22
23/**
24* BER encode a key
25* @param key the public key to encode
26* @return BER encoding of this key
27*/
28inline std::vector<uint8_t> BER_encode(const Public_Key& key)
29 {
30 return key.subject_public_key();
31 }
32
33/**
34* PEM encode a public key into a string.
35* @param key the key to encode
36* @return PEM encoded key
37*/
38BOTAN_PUBLIC_API(2,0) std::string PEM_encode(const Public_Key& key);
39
40/**
41* Create a public key from a data source.
42* @param source the source providing the DER or PEM encoded key
43* @return new public key object
44*/
46
47#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
48/**
49* Create a public key from a file
50* @param filename pathname to the file to load
51* @return new public key object
52*/
53inline Public_Key* load_key(const std::string& filename)
54 {
55 DataSource_Stream source(filename, true);
56 return X509::load_key(source);
57 }
58#endif
59
60/**
61* Create a public key from a memory region.
62* @param enc the memory region containing the DER or PEM encoded key
63* @return new public key object
64*/
65inline Public_Key* load_key(const std::vector<uint8_t>& enc)
66 {
67 DataSource_Memory source(enc);
68 return X509::load_key(source);
69 }
70
71/**
72* Copy a key.
73* @param key the public key to copy
74* @return new public key object
75*/
76inline Public_Key* copy_key(const Public_Key& key)
77 {
78 DataSource_Memory source(PEM_encode(key));
79 return X509::load_key(source);
80 }
81
82}
83
84}
85
86#endif
std::vector< uint8_t > subject_public_key() const
Definition: pk_keys.cpp:38
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Public_Key * copy_key(const Public_Key &key)
Definition: x509_key.h:76
std::vector< uint8_t > BER_encode(const Public_Key &key)
Definition: x509_key.h:28
Public_Key * load_key(DataSource &source)
Definition: x509_key.cpp:29
std::string PEM_encode(const Public_Key &key)
Definition: x509_key.cpp:20
Definition: alg_id.cpp:13
Definition: bigint.h:1077