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

randombit / botan / 5134090420

31 May 2023 03:12PM UTC coverage: 91.721% (-0.3%) from 91.995%
5134090420

push

github

randombit
Merge GH #3565 Disable noisy/pointless pylint warnings

76048 of 82912 relevant lines covered (91.72%)

11755290.1 hits per line

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

88.64
/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
#if defined(BOTAN_HAS_HASH_ID) && defined(BOTAN_HAS_ASN1)
18

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

38
         std::vector<Test::Result> results;
1✔
39

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

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

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

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

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

57
               result.test_eq("Dummy hash is expected size", bits.size() - pkcs_id.size(), dummy_hash.size());
13✔
58

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

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

68
               result.test_eq("Encoded ID matches hardcoded", encoded_id, pkcs_id);
26✔
69

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

74
            results.push_back(result);
13✔
75
         }
13✔
76

77
         return results;
1✔
78
      }
1✔
79
};
80

81
BOTAN_REGISTER_TEST("pubkey", "pkcs_hash_id", PKCS_HashID_Test);
82
#endif
83

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

© 2025 Coveralls, Inc