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

randombit / botan / 5112587681

29 May 2023 01:55PM UTC coverage: 92.211% (-0.01%) from 92.221%
5112587681

push

github

randombit
Merge GH #3560 Update CI builder to use the macOS 13 image

75573 of 81957 relevant lines covered (92.21%)

12015603.28 hits per line

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

79.31
/src/lib/pk_pad/emsa_raw/emsa_raw.cpp
1
/*
2
* EMSA-Raw
3
* (C) 1999-2007 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/internal/emsa_raw.h>
9

10
#include <botan/exceptn.h>
11

12
namespace Botan {
13

14
std::string EMSA_Raw::name() const {
3✔
15
   if(m_expected_size > 0)
3✔
16
      return "Raw(" + std::to_string(m_expected_size) + ")";
×
17
   return "Raw";
3✔
18
}
19

20
/*
21
* EMSA-Raw Encode Operation
22
*/
23
void EMSA_Raw::update(const uint8_t input[], size_t length) { m_message += std::make_pair(input, length); }
814✔
24

25
/*
26
* Return the raw (unencoded) data
27
*/
28
std::vector<uint8_t> EMSA_Raw::raw_data() {
814✔
29
   if(m_expected_size && m_message.size() != m_expected_size)
814✔
30
      throw Invalid_Argument("EMSA_Raw was configured to use a " + std::to_string(m_expected_size) +
×
31
                             " byte hash but instead was used for a " + std::to_string(m_message.size()) + " hash");
×
32

33
   std::vector<uint8_t> output;
814✔
34
   std::swap(m_message, output);
814✔
35
   return output;
814✔
36
}
37

38
/*
39
* EMSA-Raw Encode Operation
40
*/
41
std::vector<uint8_t> EMSA_Raw::encoding_of(const std::vector<uint8_t>& msg,
385✔
42
                                           size_t /*output_bits*/,
43
                                           RandomNumberGenerator& /*rng*/) {
44
   if(m_expected_size && msg.size() != m_expected_size)
385✔
45
      throw Invalid_Argument("EMSA_Raw was configured to use a " + std::to_string(m_expected_size) +
×
46
                             " byte hash but instead was used for a " + std::to_string(msg.size()) + " hash");
×
47

48
   return msg;
385✔
49
}
50

51
/*
52
* EMSA-Raw Verify Operation
53
*/
54
bool EMSA_Raw::verify(const std::vector<uint8_t>& coded, const std::vector<uint8_t>& raw, size_t /*key_bits*/) {
429✔
55
   if(m_expected_size && raw.size() != m_expected_size)
429✔
56
      return false;
57

58
   if(coded.size() == raw.size())
429✔
59
      return (coded == raw);
20✔
60

61
   if(coded.size() > raw.size())
409✔
62
      return false;
63

64
   // handle zero padding differences
65
   const size_t leading_zeros_expected = raw.size() - coded.size();
389✔
66

67
   bool same_modulo_leading_zeros = true;
389✔
68

69
   for(size_t i = 0; i != leading_zeros_expected; ++i)
6,434✔
70
      if(raw[i])
6,045✔
71
         same_modulo_leading_zeros = false;
270✔
72

73
   if(!constant_time_compare(coded.data(), raw.data() + leading_zeros_expected, coded.size()))
389✔
74
      same_modulo_leading_zeros = false;
×
75

76
   return same_modulo_leading_zeros;
77
}
78

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