Coverage Report

Created: 2025-07-11 06:15

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