OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CRYPTO_NSS_UTIL_H_ | 5 #ifndef CRYPTO_NSS_UTIL_H_ |
6 #define CRYPTO_NSS_UTIL_H_ | 6 #define CRYPTO_NSS_UTIL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "crypto/crypto_export.h" | 10 #include "crypto/crypto_export.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 // Convert a NSS PRTime value into a base::Time object. | 121 // Convert a NSS PRTime value into a base::Time object. |
122 // We use a int64 instead of PRTime here to avoid depending on NSPR headers. | 122 // We use a int64 instead of PRTime here to avoid depending on NSPR headers. |
123 CRYPTO_EXPORT base::Time PRTimeToBaseTime(int64 prtime); | 123 CRYPTO_EXPORT base::Time PRTimeToBaseTime(int64 prtime); |
124 | 124 |
125 // Convert a base::Time object into a PRTime value. | 125 // Convert a base::Time object into a PRTime value. |
126 // We use a int64 instead of PRTime here to avoid depending on NSPR headers. | 126 // We use a int64 instead of PRTime here to avoid depending on NSPR headers. |
127 CRYPTO_EXPORT int64 BaseTimeToPRTime(base::Time time); | 127 CRYPTO_EXPORT int64 BaseTimeToPRTime(base::Time time); |
128 | 128 |
129 #if defined(USE_NSS) | 129 #if defined(USE_NSS) |
130 // Exposed for unittests only. | 130 // Exposed for unittests only. |
131 // TODO(mattm): when https://bugzilla.mozilla.org/show_bug.cgi?id=588269 is | 131 // TODO(mattm): When NSS 3.14 is the minimum version required, |
132 // fixed, switch back to using a separate userdb for each test. (Maybe refactor | 132 // switch back to using a separate user DB for each test. |
133 // to provide a ScopedTestNSSDB instead of open/close methods.) | 133 // Because of https://bugzilla.mozilla.org/show_bug.cgi?id=588269 , the |
134 CRYPTO_EXPORT bool OpenTestNSSDB(); | 134 // opened user DB is not automatically closed. |
135 // NOTE: due to NSS bug 588269, mentioned above, there is no CloseTestNSSDB. | 135 class CRYPTO_EXPORT_PRIVATE ScopedTestNSSDB { |
| 136 public: |
| 137 ScopedTestNSSDB(); |
| 138 ~ScopedTestNSSDB(); |
| 139 |
| 140 bool is_open() { return is_open_; } |
| 141 |
| 142 private: |
| 143 bool is_open_; |
| 144 DISALLOW_COPY_AND_ASSIGN(ScopedTestNSSDB); |
| 145 }; |
136 | 146 |
137 // NSS has a bug which can cause a deadlock or stall in some cases when writing | 147 // NSS has a bug which can cause a deadlock or stall in some cases when writing |
138 // to the certDB and keyDB. It also has a bug which causes concurrent key pair | 148 // to the certDB and keyDB. It also has a bug which causes concurrent key pair |
139 // generations to scribble over each other. To work around this, we synchronize | 149 // generations to scribble over each other. To work around this, we synchronize |
140 // writes to the NSS databases with a global lock. The lock is hidden beneath a | 150 // writes to the NSS databases with a global lock. The lock is hidden beneath a |
141 // function for easy disabling when the bug is fixed. Callers should allow for | 151 // function for easy disabling when the bug is fixed. Callers should allow for |
142 // it to return NULL in the future. | 152 // it to return NULL in the future. |
143 // | 153 // |
144 // See https://bugzilla.mozilla.org/show_bug.cgi?id=564011 | 154 // See https://bugzilla.mozilla.org/show_bug.cgi?id=564011 |
145 base::Lock* GetNSSWriteLock(); | 155 base::Lock* GetNSSWriteLock(); |
146 | 156 |
147 // A helper class that acquires the NSS write Lock while the AutoNSSWriteLock | 157 // A helper class that acquires the NSS write Lock while the AutoNSSWriteLock |
148 // is in scope. | 158 // is in scope. |
149 class CRYPTO_EXPORT AutoNSSWriteLock { | 159 class CRYPTO_EXPORT AutoNSSWriteLock { |
150 public: | 160 public: |
151 AutoNSSWriteLock(); | 161 AutoNSSWriteLock(); |
152 ~AutoNSSWriteLock(); | 162 ~AutoNSSWriteLock(); |
153 private: | 163 private: |
154 base::Lock *lock_; | 164 base::Lock *lock_; |
155 DISALLOW_COPY_AND_ASSIGN(AutoNSSWriteLock); | 165 DISALLOW_COPY_AND_ASSIGN(AutoNSSWriteLock); |
156 }; | 166 }; |
157 | 167 |
158 #endif // defined(USE_NSS) | 168 #endif // defined(USE_NSS) |
159 | 169 |
160 } // namespace crypto | 170 } // namespace crypto |
161 | 171 |
162 #endif // CRYPTO_NSS_UTIL_H_ | 172 #endif // CRYPTO_NSS_UTIL_H_ |
OLD | NEW |