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

randombit / botan / 13156603211

05 Feb 2025 11:43AM UTC coverage: 91.232% (+0.005%) from 91.227%
13156603211

Pull #4635

github

web-flow
Merge b8e756721 into 623aacddb
Pull Request #4635: Use span instead of vector as arguments to EMSA

94195 of 103248 relevant lines covered (91.23%)

11460182.05 hits per line

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

70.97
/src/lib/pk_pad/emsa_raw/emsa_raw.cpp
1
/*
2
* EMSA-Raw
3
* (C) 1999-2007,2025 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
#include <botan/mem_ops.h>
12
#include <botan/internal/ct_utils.h>
13
#include <botan/internal/fmt.h>
14

15
namespace Botan {
16

17
std::string EMSA_Raw::name() const {
3✔
18
   if(m_expected_size > 0) {
3✔
19
      return fmt("Raw({})", m_expected_size);
×
20
   }
21
   return "Raw";
3✔
22
}
23

24
/*
25
* EMSA-Raw Encode Operation
26
*/
27
void EMSA_Raw::update(const uint8_t input[], size_t length) {
3,804✔
28
   m_message += std::make_pair(input, length);
3,804✔
29
}
3,804✔
30

31
/*
32
* Return the raw (unencoded) data
33
*/
34
std::vector<uint8_t> EMSA_Raw::raw_data() {
3,804✔
35
   if(m_expected_size && m_message.size() != m_expected_size) {
3,804✔
36
      throw Invalid_Argument(
×
37
         fmt("EMSA_Raw was configured to use a {} byte hash but instead was used for a {} byte hash",
×
38
             m_expected_size,
×
39
             m_message.size()));
×
40
   }
41

42
   std::vector<uint8_t> output;
3,804✔
43
   std::swap(m_message, output);
3,804✔
44
   return output;
3,804✔
45
}
46

47
/*
48
* EMSA-Raw Encode Operation
49
*/
50
std::vector<uint8_t> EMSA_Raw::encoding_of(std::span<const uint8_t> msg,
450✔
51
                                           size_t /*output_bits*/,
52
                                           RandomNumberGenerator& /*rng*/) {
53
   if(m_expected_size && msg.size() != m_expected_size) {
450✔
54
      throw Invalid_Argument(
×
55
         fmt("EMSA_Raw was configured to use a {} byte hash but instead was used for a {} byte hash",
×
56
             m_expected_size,
×
57
             msg.size()));
×
58
   }
59

60
   return std::vector<uint8_t>(msg.begin(), msg.end());
450✔
61
}
62

63
/*
64
* EMSA-Raw Verify Operation
65
*/
66
bool EMSA_Raw::verify(std::span<const uint8_t> coded, std::span<const uint8_t> raw, size_t /*key_bits*/) {
3,341✔
67
   if(m_expected_size && raw.size() != m_expected_size) {
3,341✔
68
      return false;
69
   }
70

71
   if(raw.size() > coded.size()) {
3,341✔
72
      // handle zero padding differences
73
      const size_t expected_lz = raw.size() - coded.size();
778✔
74
      auto zeros_ok = CT::all_zeros(raw.data(), expected_lz);
778✔
75
      auto contents_ok = CT::is_equal(coded.data(), raw.data() + expected_lz, coded.size());
778✔
76
      return (zeros_ok & contents_ok).as_bool();
778✔
77
   }
78

79
   return constant_time_compare(coded, raw);
2,563✔
80
}
81

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

© 2026 Coveralls, Inc