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

randombit / botan / 23225340130

18 Mar 2026 01:53AM UTC coverage: 89.677% (-0.001%) from 89.678%
23225340130

push

github

web-flow
Merge pull request #5456 from randombit/jack/clang-tidy-22

Fix various warnings from clang-tidy 22

104438 of 116460 relevant lines covered (89.68%)

11819947.55 hits per line

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

93.02
/src/tests/test_hash_id.cpp
1
/*
2
* (C) 2017 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "tests.h"
8

9
#if defined(BOTAN_HAS_HASH_ID) && defined(BOTAN_HAS_ASN1)
10
   #include <botan/asn1_obj.h>
11
   #include <botan/der_enc.h>
12
   #include <botan/internal/hash_id.h>
13
#endif
14

15
namespace Botan_Tests {
16

17
namespace {
18

19
#if defined(BOTAN_HAS_HASH_ID) && defined(BOTAN_HAS_ASN1)
20

21
class PKCS_HashID_Test final : public Test {
1✔
22
   public:
23
      std::vector<Test::Result> run() override {
1✔
24
         const std::vector<std::pair<std::string, size_t>> hash_id_fns = {
1✔
25
            {"MD5", 16},
1✔
26
            {"RIPEMD-160", 20},
1✔
27
            {"SHA-1", 20},
1✔
28
            {"SHA-224", 28},
1✔
29
            {"SHA-256", 32},
1✔
30
            {"SHA-384", 48},
1✔
31
            {"SHA-512", 64},
1✔
32
            {"SHA-512-256", 32},
1✔
33
            {"SHA-3(224)", 28},
1✔
34
            {"SHA-3(256)", 32},
1✔
35
            {"SHA-3(384)", 48},
1✔
36
            {"SHA-3(512)", 64},
1✔
37
            {"SM3", 32},
1✔
38
         };
14✔
39

40
         std::vector<Test::Result> results;
1✔
41

42
         for(const auto& hash_info : hash_id_fns) {
14✔
43
            const std::string hash_fn = hash_info.first;
13✔
44
            const size_t hash_len = hash_info.second;
13✔
45

46
            Test::Result result("PKCS hash id for " + hash_fn);
13✔
47

48
            try {
13✔
49
               const std::vector<uint8_t> pkcs_id = Botan::pkcs_hash_id(hash_fn);
13✔
50

51
               const Botan::OID oid = Botan::OID::from_string(hash_fn);
13✔
52
               const Botan::AlgorithmIdentifier alg(oid, Botan::AlgorithmIdentifier::USE_NULL_PARAM);
13✔
53
               const std::vector<uint8_t> dummy_hash(hash_len);
13✔
54

55
               std::vector<uint8_t> bits;
13✔
56
               Botan::DER_Encoder der(bits);
13✔
57
               der.start_sequence().encode(alg).encode(dummy_hash, Botan::ASN1_Type::OctetString).end_cons();
13✔
58

59
               result.test_sz_eq("Dummy hash is expected size", bits.size() - pkcs_id.size(), dummy_hash.size());
13✔
60

61
               for(size_t i = pkcs_id.size(); i != bits.size(); ++i) {
477✔
62
                  if(bits[i] != 0) {
464✔
63
                     result.test_failure("Dummy hash had nonzero value");
×
64
                     break;
65
                  }
66
               }
67

68
               std::vector<uint8_t> encoded_id(bits.begin(), bits.begin() + pkcs_id.size());
13✔
69

70
               result.test_bin_eq("Encoded ID matches hardcoded", encoded_id, pkcs_id);
13✔
71

72
            } catch(Botan::Exception& e) {
52✔
73
               result.test_failure(e.what());
×
74
            }
×
75

76
            results.push_back(result);
13✔
77
         }
13✔
78

79
         return results;
1✔
80
      }
15✔
81
};
82

83
BOTAN_REGISTER_TEST("pubkey", "pkcs_hash_id", PKCS_HashID_Test);
84
#endif
85

86
}  // namespace
87

88
}  // namespace Botan_Tests
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