• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 23929724004

03 Apr 2026 01:28AM UTC coverage: 89.466% (-0.06%) from 89.524%
23929724004

Pull #5514

github

web-flow
Merge 31e4d3857 into 042e5bd98
Pull Request #5514: Add BER_Decoder::Limits

105554 of 117982 relevant lines covered (89.47%)

11545936.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.59
/src/lib/pubkey/pk_keys.cpp
1
/*
2
* PK Key Types
3
* (C) 1999-2007 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/pk_keys.h>
9

10
#include <botan/der_enc.h>
11
#include <botan/hash.h>
12
#include <botan/hex.h>
13
#include <botan/pk_ops.h>
14
#include <botan/internal/fmt.h>
15

16
namespace Botan {
17

18
const BigInt& Asymmetric_Key::get_int_field(std::string_view field) const {
4✔
19
   throw Unknown_PK_Field_Name(algo_name(), field);
8✔
20
}
21

22
OID Asymmetric_Key::object_identifier() const {
4,795✔
23
   try {
4,795✔
24
      return OID::from_string(algo_name());
9,590✔
25
   } catch(Lookup_Error&) {
×
26
      throw Lookup_Error(fmt("Public key algorithm {} has no defined OIDs", algo_name()));
×
27
   }
×
28
}
29

30
Signature_Format Asymmetric_Key::_default_x509_signature_format() const {
23,079✔
31
   if(_signature_element_size_for_DER_encoding()) {
23,079✔
32
      return Signature_Format::DerSequence;
33
   } else {
34
      return Signature_Format::Standard;
16,717✔
35
   }
36
}
37

38
std::string create_hex_fingerprint(std::span<const uint8_t> bits, std::string_view hash_name) {
20,195✔
39
   auto hash_fn = HashFunction::create_or_throw(hash_name);
20,195✔
40
   hash_fn->update(bits);
20,195✔
41
   auto digest = hash_fn->final_stdvec();
20,195✔
42
   return format_hex_fingerprint(digest);
20,195✔
43
}
40,390✔
44

45
std::string format_hex_fingerprint(std::span<const uint8_t> bits) {
40,358✔
46
   const std::string hex = hex_encode(bits);
40,358✔
47

48
   std::string fprint;
40,358✔
49
   fprint.reserve(3 * bits.size());
40,358✔
50

51
   for(size_t i = 0; i != hex.size(); i += 2) {
1,089,858✔
52
      if(i != 0) {
1,049,500✔
53
         fprint.push_back(':');
1,009,142✔
54
      }
55

56
      fprint.push_back(hex[i]);
1,049,500✔
57
      fprint.push_back(hex[i + 1]);
1,049,500✔
58
   }
59

60
   return fprint;
40,358✔
61
}
40,358✔
62

63
std::vector<uint8_t> Public_Key::subject_public_key() const {
3,716✔
64
   std::vector<uint8_t> output;
3,716✔
65

66
   DER_Encoder(output)
3,716✔
67
      .start_sequence()
3,716✔
68
      .encode(algorithm_identifier())
7,432✔
69
      .encode(public_key_bits(), ASN1_Type::BitString)
7,432✔
70
      .end_cons();
3,716✔
71

72
   return output;
3,716✔
73
}
×
74

75
secure_vector<uint8_t> Private_Key::private_key_info() const {
1,627✔
76
   const size_t PKCS8_VERSION = 0;
1,627✔
77

78
   return DER_Encoder()
1,627✔
79
      .start_sequence()
1,627✔
80
      .encode(PKCS8_VERSION)
1,627✔
81
      .encode(pkcs8_algorithm_identifier())
3,254✔
82
      .encode(private_key_bits(), ASN1_Type::OctetString)
3,254✔
83
      .end_cons()
1,627✔
84
      .get_contents();
3,254✔
85
}
86

87
secure_vector<uint8_t> Private_Key::raw_private_key_bits() const {
1✔
88
   throw Not_Implemented(algo_name() + " does not implement raw_private_key_bits");
3✔
89
}
90

91
/*
92
* Hash of the X.509 subjectPublicKey encoding
93
*/
94
std::string Public_Key::fingerprint_public(std::string_view hash_algo) const {
16✔
95
   return create_hex_fingerprint(subject_public_key(), hash_algo);
32✔
96
}
97

98
/*
99
* Hash of the PKCS #8 encoding for this key object
100
*/
101
std::string Private_Key::fingerprint_private(std::string_view hash_algo) const {
16✔
102
   return create_hex_fingerprint(private_key_bits(), hash_algo);
32✔
103
}
104

105
std::unique_ptr<PK_Ops::Encryption> Public_Key::create_encryption_op(RandomNumberGenerator& /*rng*/,
×
106
                                                                     std::string_view /*params*/,
107
                                                                     std::string_view /*provider*/) const {
108
   throw Lookup_Error(fmt("{} does not support encryption", algo_name()));
×
109
}
110

111
std::unique_ptr<PK_Ops::KEM_Encryption> Public_Key::create_kem_encryption_op(std::string_view /*params*/,
×
112
                                                                             std::string_view /*provider*/) const {
113
   throw Lookup_Error(fmt("{} does not support KEM encryption", algo_name()));
×
114
}
115

116
std::unique_ptr<PK_Ops::Verification> Public_Key::create_verification_op(std::string_view /*params*/,
×
117
                                                                         std::string_view /*provider*/) const {
118
   throw Lookup_Error(fmt("{} does not support verification", algo_name()));
×
119
}
120

121
std::unique_ptr<PK_Ops::Verification> Public_Key::create_x509_verification_op(const AlgorithmIdentifier& /*params*/,
×
122
                                                                              std::string_view /*provider*/) const {
123
   throw Lookup_Error(fmt("{} does not support X.509 verification", algo_name()));
×
124
}
125

126
std::unique_ptr<PK_Ops::Decryption> Private_Key::create_decryption_op(RandomNumberGenerator& /*rng*/,
×
127
                                                                      std::string_view /*params*/,
128
                                                                      std::string_view /*provider*/) const {
129
   throw Lookup_Error(fmt("{} does not support decryption", algo_name()));
×
130
}
131

132
std::unique_ptr<PK_Ops::KEM_Decryption> Private_Key::create_kem_decryption_op(RandomNumberGenerator& /*rng*/,
×
133
                                                                              std::string_view /*params*/,
134
                                                                              std::string_view /*provider*/) const {
135
   throw Lookup_Error(fmt("{} does not support KEM decryption", algo_name()));
×
136
}
137

138
std::unique_ptr<PK_Ops::Signature> Private_Key::create_signature_op(RandomNumberGenerator& /*rng*/,
×
139
                                                                    std::string_view /*params*/,
140
                                                                    std::string_view /*provider*/) const {
141
   throw Lookup_Error(fmt("{} does not support signatures", algo_name()));
×
142
}
143

144
std::unique_ptr<PK_Ops::Key_Agreement> Private_Key::create_key_agreement_op(RandomNumberGenerator& /*rng*/,
×
145
                                                                            std::string_view /*params*/,
146
                                                                            std::string_view /*provider*/) const {
147
   throw Lookup_Error(fmt("{} does not support key agreement", algo_name()));
×
148
}
149

150
}  // namespace Botan
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc