blob: ae9b2cd8a5b7ff8feeacae8152622eeb39a9a913 [file] [log] [blame]
[email protected]190933f2014-07-28 09:56:511// Copyright 2014 The Chromium Authors. All rights reserved.
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_SYSTEM_NSS_KEY_SLOT_H_
6#define CRYPTO_SCOPED_TEST_SYSTEM_NSS_KEY_SLOT_H_
7
thakisd1a18472016-04-08 22:30:418#include <memory>
9
[email protected]190933f2014-07-28 09:56:5110#include "base/macros.h"
[email protected]190933f2014-07-28 09:56:5111#include "crypto/crypto_export.h"
12
[email protected]442233d42014-08-02 07:37:2413// Forward declaration, from <pk11pub.h>
14typedef struct PK11SlotInfoStr PK11SlotInfo;
15
[email protected]190933f2014-07-28 09:56:5116namespace crypto {
17
18class ScopedTestNSSDB;
19
20// Opens a persistent NSS software database in a temporary directory and sets
21// the test system slot to the opened database. This helper should be created in
[email protected]442233d42014-08-02 07:37:2422// tests to fake the system token that is usually provided by the Chaps module.
23// |slot| is exposed through |GetSystemNSSKeySlot| and |IsTPMTokenReady| will
24// return true.
25// |InitializeTPMTokenAndSystemSlot|, which triggers the TPM initialization,
26// does not have to be called if this helper is used.
[email protected]190933f2014-07-28 09:56:5127// At most one instance of this helper must be used at a time.
xhwang3e9ca562015-11-06 18:50:3628class CRYPTO_EXPORT ScopedTestSystemNSSKeySlot {
[email protected]190933f2014-07-28 09:56:5129 public:
davidben6004dc52017-02-03 04:15:2930 ScopedTestSystemNSSKeySlot();
[email protected]190933f2014-07-28 09:56:5131 ~ScopedTestSystemNSSKeySlot();
32
33 bool ConstructedSuccessfully() const;
[email protected]442233d42014-08-02 07:37:2434 PK11SlotInfo* slot() const;
[email protected]190933f2014-07-28 09:56:5135
36 private:
thakisd1a18472016-04-08 22:30:4137 std::unique_ptr<ScopedTestNSSDB> test_db_;
[email protected]190933f2014-07-28 09:56:5138
39 DISALLOW_COPY_AND_ASSIGN(ScopedTestSystemNSSKeySlot);
40};
41
42} // namespace crypto
43
44#endif // CRYPTO_SCOPED_TEST_SYSTEM_NSS_KEY_SLOT_H_