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

randombit / botan / 5123321399

30 May 2023 04:06PM UTC coverage: 92.213% (+0.004%) from 92.209%
5123321399

Pull #3558

github

web-flow
Merge dd72f7389 into 057bcbc35
Pull Request #3558: Add braces around all if/else statements

75602 of 81986 relevant lines covered (92.21%)

11859779.3 hits per line

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

95.65
/src/lib/x509/ocsp_types.cpp
1
/*
2
* OCSP subtypes
3
* (C) 2012 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/ocsp.h>
9

10
#include <botan/ber_dec.h>
11
#include <botan/der_enc.h>
12
#include <botan/hash.h>
13
#include <botan/x509_ext.h>
14

15
namespace Botan::OCSP {
16

17
CertID::CertID(const X509_Certificate& issuer, const BigInt& subject_serial) {
4✔
18
   /*
19
   In practice it seems some responders, including, notably,
20
   ocsp.verisign.com, will reject anything but SHA-1 here
21
   */
22
   auto hash = HashFunction::create_or_throw("SHA-1");
4✔
23

24
   m_hash_id = AlgorithmIdentifier(hash->name(), AlgorithmIdentifier::USE_NULL_PARAM);
4✔
25
   m_issuer_key_hash = unlock(hash->process(issuer.subject_public_key_bitstring()));
8✔
26
   m_issuer_dn_hash = unlock(hash->process(issuer.raw_subject_dn()));
8✔
27
   m_subject_serial = subject_serial;
4✔
28
}
4✔
29

30
bool CertID::is_id_for(const X509_Certificate& issuer, const X509_Certificate& subject) const {
37✔
31
   try {
37✔
32
      if(BigInt::decode(subject.serial_number()) != m_subject_serial) {
111✔
33
         return false;
×
34
      }
35

36
      const std::string hash_algo = m_hash_id.oid().to_formatted_string();
37✔
37
      auto hash = HashFunction::create_or_throw(hash_algo);
37✔
38

39
      if(m_issuer_dn_hash != unlock(hash->process(subject.raw_issuer_dn()))) {
148✔
40
         return false;
41
      }
42

43
      if(m_issuer_key_hash != unlock(hash->process(issuer.subject_public_key_bitstring()))) {
148✔
44
         return false;
45
      }
46
   } catch(...) { return false; }
37✔
47

48
   return true;
37✔
49
}
50

51
void CertID::encode_into(DER_Encoder& to) const {
3✔
52
   to.start_sequence()
3✔
53
      .encode(m_hash_id)
3✔
54
      .encode(m_issuer_dn_hash, ASN1_Type::OctetString)
3✔
55
      .encode(m_issuer_key_hash, ASN1_Type::OctetString)
3✔
56
      .encode(m_subject_serial)
3✔
57
      .end_cons();
3✔
58
}
3✔
59

60
void CertID::decode_from(BER_Decoder& from) {
134✔
61
   from.start_sequence()
264✔
62
      .decode(m_hash_id)
130✔
63
      .decode(m_issuer_dn_hash, ASN1_Type::OctetString)
123✔
64
      .decode(m_issuer_key_hash, ASN1_Type::OctetString)
119✔
65
      .decode(m_subject_serial)
115✔
66
      .end_cons();
104✔
67
}
92✔
68

69
void SingleResponse::encode_into(DER_Encoder& /*to*/) const { throw Not_Implemented("SingleResponse::encode_into"); }
×
70

71
void SingleResponse::decode_from(BER_Decoder& from) {
135✔
72
   BER_Object cert_status;
135✔
73
   Extensions extensions;
135✔
74

75
   from.start_sequence()
194✔
76
      .decode(m_certid)
134✔
77
      .get_next(cert_status)
92✔
78
      .decode(m_thisupdate)
92✔
79
      .decode_optional(m_nextupdate, ASN1_Type(0), ASN1_Class::ContextSpecific | ASN1_Class::Constructed)
155✔
80
      .decode_optional(extensions, ASN1_Type(1), ASN1_Class::ContextSpecific | ASN1_Class::Constructed)
211✔
81
      .end_cons();
75✔
82

83
   /* CertStatus ::= CHOICE {
84
       good        [0]     IMPLICIT NULL,
85
       revoked     [1]     IMPLICIT RevokedInfo,
86
       unknown     [2]     IMPLICIT UnknownInfo }
87

88
   RevokedInfo ::= SEQUENCE {
89
       revocationTime              GeneralizedTime,
90
       revocationReason    [0]     EXPLICIT CRLReason OPTIONAL }
91

92
   UnknownInfo ::= NULL
93

94
   We should verify the expected body and decode the RevokedInfo
95
   */
96
   m_cert_status = static_cast<uint32_t>(cert_status.type());
75✔
97
}
136✔
98

99
}  // namespace Botan::OCSP
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