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

randombit / botan / 5123321399

30 May 2023 04:06PM UTC coverage: 92.213% (+0.004%) from 92.209%
5123321399

Pull #3558

github

web-flow
Merge dd72f7389 into 057bcbc35
Pull Request #3558: Add braces around all if/else statements

75602 of 81986 relevant lines covered (92.21%)

11859779.3 hits per line

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

68.42
/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/internal/fmt.h>
14
#include <botan/internal/pk_ops.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 {
2,228✔
23
   try {
2,228✔
24
      return OID::from_string(algo_name());
4,456✔
25
   } catch(Lookup_Error&) { throw Lookup_Error(fmt("Public key algorithm {} has no defined OIDs", algo_name())); }
×
26
}
27

28
std::string create_hex_fingerprint(const uint8_t bits[], size_t bits_len, std::string_view hash_name) {
28,572✔
29
   auto hash_fn = HashFunction::create_or_throw(hash_name);
28,572✔
30
   const std::string hex_hash = hex_encode(hash_fn->process(bits, bits_len));
57,144✔
31

32
   std::string fprint;
28,572✔
33

34
   for(size_t i = 0; i != hex_hash.size(); i += 2) {
771,588✔
35
      if(i != 0) {
743,016✔
36
         fprint.push_back(':');
714,444✔
37
      }
38

39
      fprint.push_back(hex_hash[i]);
743,016✔
40
      fprint.push_back(hex_hash[i + 1]);
743,016✔
41
   }
42

43
   return fprint;
28,572✔
44
}
57,144✔
45

46
std::vector<uint8_t> Public_Key::subject_public_key() const {
1,718✔
47
   std::vector<uint8_t> output;
1,718✔
48

49
   DER_Encoder(output)
1,718✔
50
      .start_sequence()
1,718✔
51
      .encode(algorithm_identifier())
3,436✔
52
      .encode(public_key_bits(), ASN1_Type::BitString)
3,436✔
53
      .end_cons();
1,718✔
54

55
   return output;
1,718✔
56
}
×
57

58
secure_vector<uint8_t> Private_Key::private_key_info() const {
725✔
59
   const size_t PKCS8_VERSION = 0;
725✔
60

61
   return DER_Encoder()
725✔
62
      .start_sequence()
725✔
63
      .encode(PKCS8_VERSION)
725✔
64
      .encode(pkcs8_algorithm_identifier())
1,450✔
65
      .encode(private_key_bits(), ASN1_Type::OctetString)
1,450✔
66
      .end_cons()
725✔
67
      .get_contents();
1,450✔
68
}
69

70
secure_vector<uint8_t> Private_Key::raw_private_key_bits() const {
×
71
   throw Not_Implemented(algo_name() + " does not implement raw_private_key_bits");
×
72
}
73

74
/*
75
* Hash of the X.509 subjectPublicKey encoding
76
*/
77
std::string Public_Key::fingerprint_public(std::string_view hash_algo) const {
8✔
78
   return create_hex_fingerprint(subject_public_key(), hash_algo);
16✔
79
}
80

81
/*
82
* Hash of the PKCS #8 encoding for this key object
83
*/
84
std::string Private_Key::fingerprint_private(std::string_view hash_algo) const {
16✔
85
   return create_hex_fingerprint(private_key_bits(), hash_algo);
32✔
86
}
87

88
std::unique_ptr<PK_Ops::Encryption> Public_Key::create_encryption_op(RandomNumberGenerator& /*rng*/,
×
89
                                                                     std::string_view /*params*/,
90
                                                                     std::string_view /*provider*/) const {
91
   throw Lookup_Error(fmt("{} does not support encryption", algo_name()));
×
92
}
93

94
std::unique_ptr<PK_Ops::KEM_Encryption> Public_Key::create_kem_encryption_op(std::string_view /*params*/,
×
95
                                                                             std::string_view /*provider*/) const {
96
   throw Lookup_Error(fmt("{} does not support KEM encryption", algo_name()));
×
97
}
98

99
std::unique_ptr<PK_Ops::Verification> Public_Key::create_verification_op(std::string_view /*params*/,
×
100
                                                                         std::string_view /*provider*/) const {
101
   throw Lookup_Error(fmt("{} does not support verification", algo_name()));
×
102
}
103

104
std::unique_ptr<PK_Ops::Verification> Public_Key::create_x509_verification_op(const AlgorithmIdentifier& /*params*/,
1✔
105
                                                                              std::string_view /*provider*/) const {
106
   throw Lookup_Error(fmt("{} does not support X.509 verification", algo_name()));
2✔
107
}
108

109
std::unique_ptr<PK_Ops::Decryption> Private_Key::create_decryption_op(RandomNumberGenerator& /*rng*/,
×
110
                                                                      std::string_view /*params*/,
111
                                                                      std::string_view /*provider*/) const {
112
   throw Lookup_Error(fmt("{} does not support decryption", algo_name()));
×
113
}
114

115
std::unique_ptr<PK_Ops::KEM_Decryption> Private_Key::create_kem_decryption_op(RandomNumberGenerator& /*rng*/,
×
116
                                                                              std::string_view /*params*/,
117
                                                                              std::string_view /*provider*/) const {
118
   throw Lookup_Error(fmt("{} does not support KEM decryption", algo_name()));
×
119
}
120

121
std::unique_ptr<PK_Ops::Signature> Private_Key::create_signature_op(RandomNumberGenerator& /*rng*/,
×
122
                                                                    std::string_view /*params*/,
123
                                                                    std::string_view /*provider*/) const {
124
   throw Lookup_Error(fmt("{} does not support signatures", algo_name()));
×
125
}
126

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

133
}  // 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