/src/botan/build/include/botan/x509_key.h
Line | Count | Source (jump to first uncovered line) |
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 | | |
16 | | namespace Botan { |
17 | | |
18 | | /** |
19 | | * This namespace contains functions for handling X.509 public keys |
20 | | */ |
21 | | namespace X509 { |
22 | | |
23 | | /** |
24 | | * BER encode a key |
25 | | * @param key the public key to encode |
26 | | * @return BER encoding of this key |
27 | | */ |
28 | | inline std::vector<uint8_t> BER_encode(const Public_Key& key) |
29 | 0 | { |
30 | 0 | return key.subject_public_key(); |
31 | 0 | } |
32 | | |
33 | | /** |
34 | | * PEM encode a public key into a string. |
35 | | * @param key the key to encode |
36 | | * @return PEM encoded key |
37 | | */ |
38 | | BOTAN_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 | | */ |
45 | | BOTAN_PUBLIC_API(2,0) Public_Key* load_key(DataSource& source); |
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 | | */ |
53 | | inline Public_Key* load_key(const std::string& filename) |
54 | 0 | { |
55 | 0 | DataSource_Stream source(filename, true); |
56 | 0 | return X509::load_key(source); |
57 | 0 | } |
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 | | */ |
65 | | inline Public_Key* load_key(const std::vector<uint8_t>& enc) |
66 | 10.6k | { |
67 | 10.6k | DataSource_Memory source(enc); |
68 | 10.6k | return X509::load_key(source); |
69 | 10.6k | } |
70 | | |
71 | | /** |
72 | | * Copy a key. |
73 | | * @param key the public key to copy |
74 | | * @return new public key object |
75 | | */ |
76 | | inline Public_Key* copy_key(const Public_Key& key) |
77 | 0 | { |
78 | 0 | DataSource_Memory source(PEM_encode(key)); |
79 | 0 | return X509::load_key(source); |
80 | 0 | } |
81 | | |
82 | | } |
83 | | |
84 | | } |
85 | | |
86 | | #endif |