pneubeck@chromium.org | 190933f | 2014-07-28 09:56:51 | [diff] [blame] | 1 | // 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 | #include "crypto/scoped_test_system_nss_key_slot.h" |
| 6 | |
Michael Ershov | 6b5e418 | 2021-09-28 13:46:32 | [diff] [blame] | 7 | #include "crypto/nss_util.h" |
pneubeck@chromium.org | 190933f | 2014-07-28 09:56:51 | [diff] [blame] | 8 | #include "crypto/nss_util_internal.h" |
| 9 | #include "crypto/scoped_test_nss_db.h" |
| 10 | |
| 11 | namespace crypto { |
| 12 | |
Michael Ershov | 6b5e418 | 2021-09-28 13:46:32 | [diff] [blame] | 13 | ScopedTestSystemNSSKeySlot::ScopedTestSystemNSSKeySlot( |
| 14 | bool simulate_token_loader) |
pneubeck@chromium.org | 190933f | 2014-07-28 09:56:51 | [diff] [blame] | 15 | : test_db_(new ScopedTestNSSDB) { |
| 16 | if (!test_db_->is_open()) |
| 17 | return; |
Michael Ershov | 6b5e418 | 2021-09-28 13:46:32 | [diff] [blame] | 18 | |
| 19 | PrepareSystemSlotForTesting( // IN-TEST |
pneubeck@chromium.org | 190933f | 2014-07-28 09:56:51 | [diff] [blame] | 20 | ScopedPK11Slot(PK11_ReferenceSlot(test_db_->slot()))); |
Michael Ershov | 6b5e418 | 2021-09-28 13:46:32 | [diff] [blame] | 21 | |
| 22 | if (simulate_token_loader) |
| 23 | FinishInitializingTPMTokenAndSystemSlot(); |
pneubeck@chromium.org | 190933f | 2014-07-28 09:56:51 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | ScopedTestSystemNSSKeySlot::~ScopedTestSystemNSSKeySlot() { |
Michael Ershov | 6b5e418 | 2021-09-28 13:46:32 | [diff] [blame] | 27 | ResetSystemSlotForTesting(); // IN-TEST |
pneubeck@chromium.org | 190933f | 2014-07-28 09:56:51 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | bool ScopedTestSystemNSSKeySlot::ConstructedSuccessfully() const { |
| 31 | return test_db_->is_open(); |
| 32 | } |
| 33 | |
pneubeck@chromium.org | 442233d4 | 2014-08-02 07:37:24 | [diff] [blame] | 34 | PK11SlotInfo* ScopedTestSystemNSSKeySlot::slot() const { |
| 35 | return test_db_->slot(); |
| 36 | } |
| 37 | |
pneubeck@chromium.org | 190933f | 2014-07-28 09:56:51 | [diff] [blame] | 38 | } // namespace crypto |