xref: /aosp_15_r20/external/cronet/crypto/scoped_test_nss_db.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CRYPTO_SCOPED_TEST_NSS_DB_H_
6 #define CRYPTO_SCOPED_TEST_NSS_DB_H_
7 
8 #include "base/files/scoped_temp_dir.h"
9 #include "crypto/crypto_export.h"
10 #include "crypto/scoped_nss_types.h"
11 
12 namespace crypto {
13 
14 // Opens a persistent NSS database in a temporary directory.
15 // Prior NSS version 3.15.1, because of http://bugzil.la/875601 , the opened DB
16 // will not be closed automatically.
17 class CRYPTO_EXPORT ScopedTestNSSDB {
18  public:
19   ScopedTestNSSDB();
20 
21   ScopedTestNSSDB(const ScopedTestNSSDB&) = delete;
22   ScopedTestNSSDB& operator=(const ScopedTestNSSDB&) = delete;
23 
24   ~ScopedTestNSSDB();
25 
is_open()26   bool is_open() const { return !!slot_; }
slot()27   PK11SlotInfo* slot() const { return slot_.get(); }
28 
29  private:
30   // Removes trust from all certificates found in |slot_|.
31   void RemoveTrustFromAllCerts();
32 
33   base::ScopedTempDir temp_dir_;
34   ScopedPK11Slot slot_;
35 };
36 
37 }  // namespace crypto
38 
39 #endif  // CRYPTO_SCOPED_TEST_NSS_DB_H_
40