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

randombit / botan / 5133556677

31 May 2023 02:11PM UTC coverage: 91.735% (-0.3%) from 92.012%
5133556677

Pull #3568

github

web-flow
Merge de48a2eb6 into 1cbeffafb
Pull Request #3568: Change clang-format AllowShortBlocksOnASingleLine from true to Empty

76059 of 82912 relevant lines covered (91.73%)

12004312.75 hits per line

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

66.1
/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&) {
×
26
      throw Lookup_Error(fmt("Public key algorithm {} has no defined OIDs", algo_name()));
×
27
   }
×
28
}
29

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

34
   std::string fprint;
28,568✔
35

36
   for(size_t i = 0; i != hex_hash.size(); i += 2) {
771,480✔
37
      if(i != 0) {
742,912✔
38
         fprint.push_back(':');
714,344✔
39
      }
40

41
      fprint.push_back(hex_hash[i]);
742,912✔
42
      fprint.push_back(hex_hash[i + 1]);
742,912✔
43
   }
44

45
   return fprint;
28,568✔
46
}
57,136✔
47

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

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

57
   return output;
1,718✔
58
}
×
59

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© 2025 Coveralls, Inc