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.
5 #ifndef CRYPTO_SCOPED_TEST_SYSTEM_NSS_KEY_SLOT_H_
6 #define CRYPTO_SCOPED_TEST_SYSTEM_NSS_KEY_SLOT_H_
10 #include "crypto/crypto_export.h"
12 // Forward declaration, from <pk11pub.h>
13 typedef struct PK11SlotInfoStr PK11SlotInfo;
17 class ScopedTestNSSDB;
19 // Helper object to override the behavior of `crypto::GetSystemNSSKeySlot()`
20 // to return a slot from a temporary directory (i.e. bypassing the TPM).
21 // This object MUST be created before any call to
22 // `crypto::InitializeTPMTokenAndSystemSlot()`. Note: As noted in
23 // `crypto::ResetSystemSlotForTesting()`, once a fake slot has been configured
24 // for a process, it cannot be undone. As such, only one instance of this object
25 // must be created for a process.
26 class CRYPTO_EXPORT ScopedTestSystemNSSKeySlot {
28 // If `simulate_token_loader` is false, this class only prepares a software
29 // system slot, which will be made available through `GetSystemNSSKeySlot`
30 // when something else (presumably the TpmTokenLoader) calls
31 // `crypto::FinishInitializingTPMTokenAndSystemSlot`. Setting
32 // `simulate_token_loader` to true emulates the "initialization finished"
33 // signal immediately (e.g. in unit tests).
34 ScopedTestSystemNSSKeySlot(bool simulate_token_loader);
36 ScopedTestSystemNSSKeySlot(const ScopedTestSystemNSSKeySlot&) = delete;
37 ScopedTestSystemNSSKeySlot& operator=(const ScopedTestSystemNSSKeySlot&) =
40 ~ScopedTestSystemNSSKeySlot();
42 bool ConstructedSuccessfully() const;
43 PK11SlotInfo* slot() const;
46 std::unique_ptr<ScopedTestNSSDB> test_db_;
51 #endif // CRYPTO_SCOPED_TEST_SYSTEM_NSS_KEY_SLOT_H_