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

randombit / botan / 5079590438

25 May 2023 12:28PM UTC coverage: 92.228% (+0.5%) from 91.723%
5079590438

Pull #3502

github

Pull Request #3502: Apply clang-format to the codebase

75589 of 81959 relevant lines covered (92.23%)

12139530.51 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,560✔
29
   auto hash_fn = HashFunction::create_or_throw(hash_name);
28,560✔
30
   const std::string hex_hash = hex_encode(hash_fn->process(bits, bits_len));
57,120✔
31

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

34
   for(size_t i = 0; i != hex_hash.size(); i += 2) {
771,264✔
35
      if(i != 0)
742,704✔
36
         fprint.push_back(':');
714,144✔
37

38
      fprint.push_back(hex_hash[i]);
742,704✔
39
      fprint.push_back(hex_hash[i + 1]);
742,704✔
40
   }
41

42
   return fprint;
28,560✔
43
}
57,120✔
44

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

132
}
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