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

randombit / botan / 5111374265

29 May 2023 11:19AM UTC coverage: 92.227% (+0.5%) from 91.723%
5111374265

push

github

randombit
Next release will be 3.1.0. Update release notes

75588 of 81959 relevant lines covered (92.23%)

11886470.91 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/internal/pss_params.h>
9

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

15
namespace Botan {
16

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

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

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

31
PSS_Params::PSS_Params(std::string_view hash_fn, size_t salt_len) :
3,197✔
32
      m_hash(hash_fn, AlgorithmIdentifier::USE_NULL_PARAM),
3,197✔
33
      m_mgf("MGF1", m_hash.BER_encode()),
3,197✔
34
      m_mgf_hash(m_hash),
3,197✔
35
      m_salt_len(salt_len) {}
6,394✔
36

37
PSS_Params::PSS_Params(const uint8_t der[], size_t der_len) {
534✔
38
   BER_Decoder decoder(der, der_len);
534✔
39
   this->decode_from(decoder);
534✔
40
}
534✔
41

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

48
void PSS_Params::encode_into(DER_Encoder& to) const {
3,197✔
49
   const size_t trailer_field = 1;
3,197✔
50

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

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

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

80
   BER_Decoder(m_mgf.parameters()).decode(m_mgf_hash);
534✔
81
}
534✔
82

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