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

randombit / botan / 11844561993

14 Nov 2024 07:58PM UTC coverage: 91.178% (+0.1%) from 91.072%
11844561993

Pull #4435

github

web-flow
Merge 81dcb29da into e430f157a
Pull Request #4435: Test duration values ​​are now presented in seconds with six digits of precision. Tests without time measurements have been edited.

91856 of 100744 relevant lines covered (91.18%)

9311006.71 hits per line

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

89.13
/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
            result.start_timer();
13✔
46

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

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

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

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

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

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

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

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

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

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

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

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