| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "crypto/scoped_test_nss_db.h" | 5 #include "crypto/scoped_test_nss_db.h" |
| 6 | 6 |
| 7 #include <cert.h> | 7 #include <cert.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| 11 #include "crypto/nss_util.h" | 11 #include "crypto/nss_util.h" |
| 12 #include "crypto/nss_util_internal.h" | 12 #include "crypto/nss_util_internal.h" |
| 13 | 13 |
| 14 namespace crypto { | 14 namespace crypto { |
| 15 | 15 |
| 16 ScopedTestNSSDB::ScopedTestNSSDB() { | 16 ScopedTestNSSDB::ScopedTestNSSDB() { |
| 17 EnsureNSSInit(); | 17 EnsureNSSInit(); |
| 18 // NSS is allowed to do IO on the current thread since dispatching | 18 // NSS is allowed to do IO on the current thread since dispatching |
| 19 // to a dedicated thread would still have the affect of blocking | 19 // to a dedicated thread would still have the affect of blocking |
| 20 // the current thread, due to NSS's internal locking requirements | 20 // the current thread, due to NSS's internal locking requirements |
| 21 base::ThreadRestrictions::ScopedAllowIO allow_io; | 21 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 22 | 22 |
| 23 if (!temp_dir_.CreateUniqueTempDir()) | 23 if (!temp_dir_.CreateUniqueTempDir()) |
| 24 return; | 24 return; |
| 25 | 25 |
| 26 const char kTestDescription[] = "Test DB"; | 26 const char kTestDescription[] = "Test DB"; |
| 27 slot_ = OpenSoftwareNSSDB(temp_dir_.path(), kTestDescription); | 27 slot_ = OpenSoftwareNSSDB(temp_dir_.GetPath(), kTestDescription); |
| 28 } | 28 } |
| 29 | 29 |
| 30 ScopedTestNSSDB::~ScopedTestNSSDB() { | 30 ScopedTestNSSDB::~ScopedTestNSSDB() { |
| 31 // Remove trust from any certs in the test DB before closing it. Otherwise NSS | 31 // Remove trust from any certs in the test DB before closing it. Otherwise NSS |
| 32 // may cache verification results even after the test DB is gone. | 32 // may cache verification results even after the test DB is gone. |
| 33 if (slot_) { | 33 if (slot_) { |
| 34 CERTCertList* cert_list = PK11_ListCertsInSlot(slot_.get()); | 34 CERTCertList* cert_list = PK11_ListCertsInSlot(slot_.get()); |
| 35 for (CERTCertListNode* node = CERT_LIST_HEAD(cert_list); | 35 for (CERTCertListNode* node = CERT_LIST_HEAD(cert_list); |
| 36 !CERT_LIST_END(node, cert_list); | 36 !CERT_LIST_END(node, cert_list); |
| 37 node = CERT_LIST_NEXT(node)) { | 37 node = CERT_LIST_NEXT(node)) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 62 SECStatus status = SECMOD_CloseUserDB(slot_.get()); | 62 SECStatus status = SECMOD_CloseUserDB(slot_.get()); |
| 63 if (status != SECSuccess) | 63 if (status != SECSuccess) |
| 64 PLOG(ERROR) << "SECMOD_CloseUserDB failed: " << PORT_GetError(); | 64 PLOG(ERROR) << "SECMOD_CloseUserDB failed: " << PORT_GetError(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 if (!temp_dir_.Delete()) | 67 if (!temp_dir_.Delete()) |
| 68 LOG(ERROR) << "Could not delete temporary directory."; | 68 LOG(ERROR) << "Could not delete temporary directory."; |
| 69 } | 69 } |
| 70 | 70 |
| 71 } // namespace crypto | 71 } // namespace crypto |
| OLD | NEW |