nss_crypto_module_delegate.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2013 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. #ifndef CRYPTO_NSS_CRYPTO_MODULE_DELEGATE_H_
  5. #define CRYPTO_NSS_CRYPTO_MODULE_DELEGATE_H_
  6. #include <string>
  7. #include "base/memory/ref_counted.h"
  8. namespace crypto {
  9. // PK11_SetPasswordFunc is a global setting. An implementation of
  10. // CryptoModuleBlockingPasswordDelegate should be passed using wincx() as the
  11. // user data argument (|wincx|) to relevant NSS functions, which the global
  12. // password handler will call to do the actual work. This delegate should only
  13. // be used in NSS calls on worker threads due to the blocking nature.
  14. class CryptoModuleBlockingPasswordDelegate
  15. : public base::RefCountedThreadSafe<CryptoModuleBlockingPasswordDelegate> {
  16. public:
  17. // Return a value suitable for passing to the |wincx| argument of relevant NSS
  18. // functions. This should be used instead of passing the object pointer
  19. // directly to avoid accidentally casting a pointer to a subclass to void* and
  20. // then casting back to a pointer of the base class
  21. void* wincx() { return this; }
  22. // Requests a password to unlock |slot_name|. The interface is synchronous
  23. // because NSS cannot issue an asynchronous request. |retry| is true if this
  24. // is a request for the retry and we previously returned the wrong password.
  25. // The implementation should set |*cancelled| to true if the user cancelled
  26. // instead of entering a password, otherwise it should return the password the
  27. // user entered.
  28. virtual std::string RequestPassword(const std::string& slot_name, bool retry,
  29. bool* cancelled) = 0;
  30. protected:
  31. friend class base::RefCountedThreadSafe<CryptoModuleBlockingPasswordDelegate>;
  32. virtual ~CryptoModuleBlockingPasswordDelegate() {}
  33. };
  34. } // namespace crypto
  35. #endif // CRYPTO_NSS_CRYPTO_MODULE_DELEGATE_H_