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

randombit / botan / 13257645065

11 Feb 2025 07:10AM UTC coverage: 91.65% (-0.009%) from 91.659%
13257645065

Pull #4647

github

web-flow
Merge b9f3a0603 into f372b5a9e
Pull Request #4647: Avoid using mem_ops.h or assert.h in public headers

94860 of 103502 relevant lines covered (91.65%)

11460675.71 hits per line

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

96.23
/src/lib/asn1/pss_params.cpp
1
/*
2
* (C) 2017 Daniel Neus
3
*     2023 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/pss_params.h>
9

10
#include <botan/assert.h>
11
#include <botan/ber_dec.h>
12
#include <botan/der_enc.h>
13
#include <botan/internal/fmt.h>
14
#include <botan/internal/scan_name.h>
15

16
namespace Botan {
17

18
//static
19
PSS_Params PSS_Params::from_emsa_name(std::string_view emsa_name) {
21✔
20
   SCAN_Name scanner(emsa_name);
21✔
21

22
   if((scanner.algo_name() != "PSS" && scanner.algo_name() != "PSS_Raw") || scanner.arg_count() != 3) {
21✔
23
      throw Invalid_Argument(fmt("PSS_Params::from_emsa_name unexpected param '{}'", emsa_name));
×
24
   }
25

26
   const std::string hash_fn = scanner.arg(0);
21✔
27
   BOTAN_ASSERT_NOMSG(scanner.arg(1) == "MGF1");
21✔
28
   const size_t salt_len = scanner.arg_as_integer(2);
21✔
29
   return PSS_Params(hash_fn, salt_len);
42✔
30
}
21✔
31

32
PSS_Params::PSS_Params(std::string_view hash_fn, size_t salt_len) :
5,482✔
33
      m_hash(hash_fn, AlgorithmIdentifier::USE_NULL_PARAM),
5,482✔
34
      m_mgf("MGF1", m_hash.BER_encode()),
5,482✔
35
      m_mgf_hash(m_hash),
5,482✔
36
      m_salt_len(salt_len) {}
10,964✔
37

38
PSS_Params::PSS_Params(std::span<const uint8_t> der) {
534✔
39
   BER_Decoder decoder(der);
534✔
40
   this->decode_from(decoder);
534✔
41
}
534✔
42

43
std::vector<uint8_t> PSS_Params::serialize() const {
5,482✔
44
   std::vector<uint8_t> output;
5,482✔
45
   DER_Encoder(output).encode(*this);
5,482✔
46
   return output;
5,482✔
47
}
×
48

49
void PSS_Params::encode_into(DER_Encoder& to) const {
5,482✔
50
   const size_t trailer_field = 1;
5,482✔
51

52
   to.start_sequence()
5,482✔
53
      .start_context_specific(0)
5,482✔
54
      .encode(m_hash)
5,482✔
55
      .end_cons()
5,482✔
56
      .start_context_specific(1)
5,482✔
57
      .encode(m_mgf)
5,482✔
58
      .end_cons()
5,482✔
59
      .start_context_specific(2)
5,482✔
60
      .encode(m_salt_len)
5,482✔
61
      .end_cons()
5,482✔
62
      .start_context_specific(3)
5,482✔
63
      .encode(trailer_field)
5,482✔
64
      .end_cons()
5,482✔
65
      .end_cons();
5,482✔
66
}
5,482✔
67

68
void PSS_Params::decode_from(BER_Decoder& from) {
534✔
69
   const AlgorithmIdentifier default_hash("SHA-1", AlgorithmIdentifier::USE_NULL_PARAM);
534✔
70
   const AlgorithmIdentifier default_mgf("MGF1", default_hash.BER_encode());
534✔
71
   const size_t default_salt_len = 20;
534✔
72
   const size_t default_trailer = 1;
534✔
73

74
   from.start_sequence()
1,068✔
75
      .decode_optional(m_hash, ASN1_Type(0), ASN1_Class::ExplicitContextSpecific, default_hash)
534✔
76
      .decode_optional(m_mgf, ASN1_Type(1), ASN1_Class::ExplicitContextSpecific, default_mgf)
534✔
77
      .decode_optional(m_salt_len, ASN1_Type(2), ASN1_Class::ExplicitContextSpecific, default_salt_len)
534✔
78
      .decode_optional(m_trailer_field, ASN1_Type(3), ASN1_Class::ExplicitContextSpecific, default_trailer)
534✔
79
      .end_cons();
534✔
80

81
   BER_Decoder(m_mgf.parameters()).decode(m_mgf_hash);
534✔
82
}
1,068✔
83

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