Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit e538f2d

Browse files
committed
Bug 1115906, Part 2: Annotate classes and member functions with override and final, r=keeler
--HG-- extra : rebase_source : 79bb236bef83ed3e884d73e029ac29a5aa999840 extra : source : d14d86bcebd38be80d00a263c3145eb0dbcc53cd
1 parent 825d718 commit e538f2d

15 files changed

Lines changed: 145 additions & 153 deletions

security/manager/ssl/tests/gtest/OCSPCacheTest.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ using namespace mozilla::pkix;
1818
using namespace mozilla::pkix::test;
1919
using namespace mozilla::psm;
2020

21+
template <size_t N>
22+
inline Input
23+
LiteralInput(const char(&valueString)[N])
24+
{
25+
return Input(reinterpret_cast<const uint8_t(&)[N - 1]>(valueString));
26+
}
27+
2128
const int MaxCacheEntries = 1024;
2229

2330
class OCSPCacheTest : public ::testing::Test
@@ -54,15 +61,15 @@ PutAndGet(OCSPCache& cache, const CertID& certID, Result result,
5461
ASSERT_EQ(time, timeOut);
5562
}
5663

57-
TestInput fakeIssuer1("CN=issuer1");
58-
TestInput fakeKey000("key000");
59-
TestInput fakeKey001("key001");
60-
TestInput fakeSerial0000("0000");
64+
Input fakeIssuer1(LiteralInput("CN=issuer1"));
65+
Input fakeKey000(LiteralInput("key000"));
66+
Input fakeKey001(LiteralInput("key001"));
67+
Input fakeSerial0000(LiteralInput("0000"));
6168

6269
TEST_F(OCSPCacheTest, TestPutAndGet)
6370
{
64-
TestInput fakeSerial000("000");
65-
TestInput fakeSerial001("001");
71+
Input fakeSerial000(LiteralInput("000"));
72+
Input fakeSerial001(LiteralInput("001"));
6673

6774
SCOPED_TRACE("");
6875
PutAndGet(cache, CertID(fakeIssuer1, fakeKey000, fakeSerial001),
@@ -105,7 +112,7 @@ TEST_F(OCSPCacheTest, TestVariousGets)
105112
Time timeInPlus512(now);
106113
ASSERT_EQ(Success, timeInPlus512.AddSeconds(512));
107114

108-
static const TestInput fakeSerial0512("0512");
115+
static const Input fakeSerial0512(LiteralInput("0512"));
109116
CertID cert0512(fakeIssuer1, fakeKey000, fakeSerial0512);
110117
ASSERT_TRUE(cache.Get(cert0512, resultOut, timeOut));
111118
ASSERT_EQ(Success, resultOut);
@@ -115,7 +122,7 @@ TEST_F(OCSPCacheTest, TestVariousGets)
115122
ASSERT_EQ(timeInPlus512, timeOut);
116123

117124
// We've never seen this certificate
118-
static const TestInput fakeSerial1111("1111");
125+
static const Input fakeSerial1111(LiteralInput("1111"));
119126
ASSERT_FALSE(cache.Get(CertID(fakeIssuer1, fakeKey000, fakeSerial1111),
120127
resultOut, timeOut));
121128
}
@@ -166,7 +173,7 @@ TEST_F(OCSPCacheTest, TestNoEvictionForRevokedResponses)
166173
ASSERT_EQ(Result::ERROR_REVOKED_CERTIFICATE, resultOut);
167174
ASSERT_EQ(timeIn, timeOut);
168175

169-
TestInput fakeSerial0001("0001");
176+
Input fakeSerial0001(LiteralInput("0001"));
170177
CertID evicted(fakeIssuer1, fakeKey000, fakeSerial0001);
171178
ASSERT_FALSE(cache.Get(evicted, resultOut, timeOut));
172179
}
@@ -186,7 +193,7 @@ TEST_F(OCSPCacheTest, TestEverythingIsRevoked)
186193
PutAndGet(cache, CertID(fakeIssuer1, fakeKey000, fakeSerial),
187194
Result::ERROR_REVOKED_CERTIFICATE, timeIn);
188195
}
189-
static const TestInput fakeSerial1025("1025");
196+
static const Input fakeSerial1025(LiteralInput("1025"));
190197
CertID good(fakeIssuer1, fakeKey000, fakeSerial1025);
191198
// This will "succeed", allowing verification to continue. However,
192199
// nothing was actually put in the cache.
@@ -201,7 +208,7 @@ TEST_F(OCSPCacheTest, TestEverythingIsRevoked)
201208
Time timeOut(Time::uninitialized);
202209
ASSERT_FALSE(cache.Get(good, resultOut, timeOut));
203210

204-
static const TestInput fakeSerial1026("1026");
211+
static const Input fakeSerial1026(LiteralInput("1026"));
205212
CertID revoked(fakeIssuer1, fakeKey000, fakeSerial1026);
206213
// This will fail, causing verification to fail.
207214
Time timeInPlus1026(timeIn);
@@ -217,8 +224,8 @@ TEST_F(OCSPCacheTest, VariousIssuers)
217224
{
218225
SCOPED_TRACE("");
219226
Time timeIn(now);
220-
static const TestInput fakeIssuer2("CN=issuer2");
221-
static const TestInput fakeSerial001("001");
227+
static const Input fakeIssuer2(LiteralInput("CN=issuer2"));
228+
static const Input fakeSerial001(LiteralInput("001"));
222229
CertID subject(fakeIssuer1, fakeKey000, fakeSerial001);
223230
PutAndGet(cache, subject, Success, now);
224231
Result resultOut;

security/pkix/include/pkix/Input.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Reader;
5050
//
5151
// Note that in the example, GoodExample has the same performance
5252
// characteristics as WorseExample, but with much better safety guarantees.
53-
class Input
53+
class Input final
5454
{
5555
public:
5656
typedef uint16_t size_type;
@@ -142,7 +142,7 @@ InputsAreEqual(const Input& a, const Input& b)
142142
//
143143
// In general, Reader allows for one byte of lookahead and no backtracking.
144144
// However, the Match* functions internally may have more lookahead.
145-
class Reader
145+
class Reader final
146146
{
147147
public:
148148
Reader()
@@ -284,7 +284,7 @@ class Reader
284284

285285
bool AtEnd() const { return input == end; }
286286

287-
class Mark
287+
class Mark final
288288
{
289289
private:
290290
friend class Reader;

security/pkix/include/pkix/ScopedPtr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace mozilla { namespace pkix {
3232
// Similar to boost::scoped_ptr and std::unique_ptr. Does not support copying
3333
// or assignment.
3434
template <typename T, void (&Destroyer)(T*)>
35-
class ScopedPtr
35+
class ScopedPtr final
3636
{
3737
public:
3838
explicit ScopedPtr(T* value = nullptr) : mValue(value) { }

security/pkix/include/pkix/Time.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace mozilla { namespace pkix {
3939
// OCSP. This type has second-level precision. The time zone is always UTC.
4040
//
4141
// Pass by value, not by reference.
42-
class Time
42+
class Time final
4343
{
4444
public:
4545
// Construct an uninitilized instance.

security/pkix/include/pkix/pkixtypes.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ enum class SignatureAlgorithm
7373
unsupported_algorithm = 19,
7474
};
7575

76-
struct SignedDataWithSignature
76+
struct SignedDataWithSignature final
7777
{
7878
public:
7979
Input data;
@@ -107,7 +107,8 @@ enum class KeyPurposeId {
107107
id_kp_OCSPSigning = 9, // id-kp-OCSPSigning
108108
};
109109

110-
struct CertPolicyId {
110+
struct CertPolicyId final
111+
{
111112
uint16_t numBytes;
112113
static const uint16_t MAX_BYTES = 24;
113114
uint8_t bytes[MAX_BYTES];
@@ -135,7 +136,7 @@ enum class TrustLevel {
135136
// field from the issuer's certificate. serialNumber is the entire DER-encoded
136137
// serial number from the subject certificate (the certificate for which we are
137138
// checking the revocation status).
138-
struct CertID
139+
struct CertID final
139140
{
140141
public:
141142
CertID(Input issuer, Input issuerSubjectPublicKeyInfo, Input serialNumber)

security/pkix/lib/pkixbuild.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ TrustDomain::IssuerChecker::~IssuerChecker() { }
4343

4444
// The implementation of TrustDomain::IssuerTracker is in a subclass only to
4545
// hide the implementation from external users.
46-
class PathBuildingStep : public TrustDomain::IssuerChecker
46+
class PathBuildingStep final : public TrustDomain::IssuerChecker
4747
{
4848
public:
4949
PathBuildingStep(TrustDomain& trustDomain, const BackCert& subject,
@@ -66,7 +66,7 @@ class PathBuildingStep : public TrustDomain::IssuerChecker
6666

6767
Result Check(Input potentialIssuerDER,
6868
/*optional*/ const Input* additionalNameConstraints,
69-
/*out*/ bool& keepGoing);
69+
/*out*/ bool& keepGoing) override;
7070

7171
Result CheckResult() const;
7272

security/pkix/lib/pkixocsp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ enum class CertStatus : uint8_t {
3939
Unknown = der::CONTEXT_SPECIFIC | 2
4040
};
4141

42-
class Context
42+
class Context final
4343
{
4444
public:
4545
Context(TrustDomain& trustDomain, const CertID& certID, Time time,

security/pkix/lib/pkixutil.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace mozilla { namespace pkix {
3838
// Each BackCert contains pointers to all the given certificate's extensions
3939
// so that we can parse the extension block once and then process the
4040
// extensions in an order that may be different than they appear in the cert.
41-
class BackCert
41+
class BackCert final
4242
{
4343
public:
4444
// certDER and childCert must be valid for the lifetime of BackCert.
@@ -147,7 +147,7 @@ class BackCert
147147
void operator=(const BackCert&) = delete;
148148
};
149149

150-
class NonOwningDERArray : public DERArray
150+
class NonOwningDERArray final : public DERArray
151151
{
152152
public:
153153
NonOwningDERArray()
@@ -157,9 +157,9 @@ class NonOwningDERArray : public DERArray
157157
// numItems before accessing i.
158158
}
159159

160-
virtual size_t GetLength() const { return numItems; }
160+
size_t GetLength() const override { return numItems; }
161161

162-
virtual const Input* GetDER(size_t i) const
162+
const Input* GetDER(size_t i) const override
163163
{
164164
return i < numItems ? &items[i] : nullptr;
165165
}

0 commit comments

Comments
 (0)