Chromium Code Reviews| 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_CRYPTO_MODULE_BLOCKING_PASSWORD_DELEGATE_H_ | 5 #ifndef CRYPTO_NSS_CRYPTO_MODULE_DELEGATE_H_ |
| 6 #define CRYPTO_CRYPTO_MODULE_BLOCKING_PASSWORD_DELEGATE_H_ | 6 #define CRYPTO_NSS_CRYPTO_MODULE_DELEGATE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | |
| 11 #include "crypto/scoped_nss_types.h" | |
| 12 | |
| 10 namespace crypto { | 13 namespace crypto { |
| 11 | 14 |
| 12 // PK11_SetPasswordFunc is a global setting. An implementation of | 15 // PK11_SetPasswordFunc is a global setting. An implementation of |
| 13 // CryptoModuleBlockingPasswordDelegate should be passed as the user data | 16 // CryptoModuleBlockingPasswordDelegate should be passed using wincx() as the |
| 14 // argument (|wincx|) to relevant NSS functions, which the global password | 17 // user data argument (|wincx|) to relevant NSS functions, which the global |
| 15 // handler will call to do the actual work. | 18 // password handler will call to do the actual work. |
| 16 class CryptoModuleBlockingPasswordDelegate { | 19 class CryptoModuleBlockingPasswordDelegate { |
| 17 public: | 20 public: |
| 18 virtual ~CryptoModuleBlockingPasswordDelegate() {} | 21 virtual ~CryptoModuleBlockingPasswordDelegate() {} |
| 19 | 22 |
| 23 // Return a value suitable for passing to the |wincx| argument of relevant NSS | |
| 24 // functions. This should be used instead of passing the object pointer | |
| 25 // directly to avoid accidentally casting a pointer to a subclass to void* and | |
| 26 // then casting back to a pointer of the base class | |
| 27 void* wincx() { return this; } | |
| 28 | |
| 20 // Requests a password to unlock |slot_name|. The interface is | 29 // Requests a password to unlock |slot_name|. The interface is |
| 21 // synchronous because NSS cannot issue an asynchronous | 30 // synchronous because NSS cannot issue an asynchronous |
| 22 // request. |retry| is true if this is a request for the retry | 31 // request. |retry| is true if this is a request for the retry |
| 23 // and we previously returned the wrong password. | 32 // and we previously returned the wrong password. |
| 24 // The implementation should set |*cancelled| to true if the user cancelled | 33 // The implementation should set |*cancelled| to true if the user cancelled |
| 25 // instead of entering a password, otherwise it should return the password the | 34 // instead of entering a password, otherwise it should return the password the |
| 26 // user entered. | 35 // user entered. |
| 27 virtual std::string RequestPassword(const std::string& slot_name, bool retry, | 36 virtual std::string RequestPassword(const std::string& slot_name, bool retry, |
| 28 bool* cancelled) = 0; | 37 bool* cancelled) = 0; |
| 38 | |
| 39 }; | |
| 40 | |
| 41 class NSSCryptoModuleDelegate : public CryptoModuleBlockingPasswordDelegate { | |
|
Ryan Sleevi
2013/11/22 00:03:30
I don't understand why the separate class with the
mattm
2013/11/22 00:30:31
I wasn't entirely sure about this, but it's becaus
| |
| 42 public: | |
| 43 virtual ~NSSCryptoModuleDelegate() {} | |
| 44 | |
| 45 // Initialize the delegate. |callback| is run when initialization is complete. | |
| 46 // |callback| may be run synchronously. Caller must ensure the delegate | |
| 47 // remains alive until |callback| is run. | |
| 48 virtual void Initialize(const base::Closure& callback) = 0; | |
| 49 | |
| 50 // Get the slot to store the generated key. | |
| 51 virtual ScopedPK11Slot RequestSlot() = 0; | |
| 29 }; | 52 }; |
| 30 | 53 |
| 31 } // namespace crypto | 54 } // namespace crypto |
| 32 | 55 |
| 33 #endif // CRYPTO_CRYPTO_MODULE_BLOCKING_PASSWORD_DELEGATE_H_ | 56 #endif // CRYPTO_NSS_CRYPTO_MODULE_DELEGATE_H_ |
| OLD | NEW |