/src/botan/build/include/public/botan/x509_key.h
Line | Count | Source |
1 | | /* |
2 | | * X.509 Public Key |
3 | | * (C) 1999-2010,2023 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/data_src.h> |
12 | | #include <botan/pk_keys.h> |
13 | | #include <memory> |
14 | | #include <string> |
15 | | #include <vector> |
16 | | |
17 | | namespace Botan::X509 { |
18 | | |
19 | | /** |
20 | | * BER encode a key |
21 | | * @param key the public key to encode |
22 | | * @return BER encoding of this key |
23 | | */ |
24 | 0 | inline std::vector<uint8_t> BER_encode(const Public_Key& key) { |
25 | 0 | return key.subject_public_key(); |
26 | 0 | } |
27 | | |
28 | | /** |
29 | | * PEM encode a public key into a string. |
30 | | * @param key the key to encode |
31 | | * @return PEM encoded key |
32 | | */ |
33 | | BOTAN_PUBLIC_API(2, 0) std::string PEM_encode(const Public_Key& key); |
34 | | |
35 | | /** |
36 | | * Create a public key from a data source. |
37 | | * @param source the source providing the DER or PEM encoded key |
38 | | * @return new public key object |
39 | | */ |
40 | | BOTAN_PUBLIC_API(3, 0) std::unique_ptr<Public_Key> load_key(DataSource& source); |
41 | | |
42 | | #if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM) |
43 | | /** |
44 | | * Create a public key from a file |
45 | | * @param filename pathname to the file to load |
46 | | * @return new public key object |
47 | | */ |
48 | 0 | inline std::unique_ptr<Public_Key> load_key(std::string_view filename) { |
49 | 0 | DataSource_Stream source(filename, true); |
50 | 0 | return X509::load_key(source); |
51 | 0 | } |
52 | | #endif |
53 | | |
54 | | /** |
55 | | * Create a public key from a memory region. |
56 | | * @param enc the memory region containing the DER or PEM encoded key |
57 | | * @return new public key object |
58 | | */ |
59 | 20.5k | inline std::unique_ptr<Public_Key> load_key(const std::vector<uint8_t>& enc) { |
60 | 20.5k | DataSource_Memory source(enc); |
61 | 20.5k | return X509::load_key(source); |
62 | 20.5k | } |
63 | | |
64 | | /** |
65 | | * Create a public key from a memory region. |
66 | | * @param enc the memory region containing the DER or PEM encoded key |
67 | | * @return new public key object |
68 | | */ |
69 | 0 | inline std::unique_ptr<Public_Key> load_key(std::span<const uint8_t> enc) { |
70 | 0 | DataSource_Memory source(enc); |
71 | 0 | return X509::load_key(source); |
72 | 0 | } |
73 | | |
74 | | /** |
75 | | * Copy a key. |
76 | | * @param key the public key to copy |
77 | | * @return new public key object |
78 | | */ |
79 | 0 | inline std::unique_ptr<Public_Key> copy_key(const Public_Key& key) { |
80 | 0 | DataSource_Memory source(PEM_encode(key)); |
81 | 0 | return X509::load_key(source); |
82 | 0 | } |
83 | | |
84 | | } // namespace Botan::X509 |
85 | | |
86 | | #endif |