[go: nahoru, domu]

blob: 3a90a10c7dd4765f6e62ae42363477841b23bc17 [file] [log] [blame]
Avi Drissman201a9a832022-09-13 19:39:251// Copyright 2013 The Chromium Authors
mattm@chromium.org99e5e9522013-12-16 13:05:272// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CRYPTO_NSS_CRYPTO_MODULE_DELEGATE_H_
6#define CRYPTO_NSS_CRYPTO_MODULE_DELEGATE_H_
7
8#include <string>
9
mattm436ccfe2017-06-19 20:24:0810#include "base/memory/ref_counted.h"
11
mattm@chromium.org99e5e9522013-12-16 13:05:2712namespace crypto {
13
14// PK11_SetPasswordFunc is a global setting. An implementation of
15// CryptoModuleBlockingPasswordDelegate should be passed using wincx() as the
16// user data argument (|wincx|) to relevant NSS functions, which the global
17// password handler will call to do the actual work. This delegate should only
18// be used in NSS calls on worker threads due to the blocking nature.
mattm436ccfe2017-06-19 20:24:0819class CryptoModuleBlockingPasswordDelegate
20 : public base::RefCountedThreadSafe<CryptoModuleBlockingPasswordDelegate> {
mattm@chromium.org99e5e9522013-12-16 13:05:2721 public:
mattm@chromium.org99e5e9522013-12-16 13:05:2722
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
29 // Requests a password to unlock |slot_name|. The interface is synchronous
30 // because NSS cannot issue an asynchronous request. |retry| is true if this
31 // is a request for the retry and we previously returned the wrong password.
32 // The implementation should set |*cancelled| to true if the user cancelled
33 // instead of entering a password, otherwise it should return the password the
34 // user entered.
35 virtual std::string RequestPassword(const std::string& slot_name, bool retry,
36 bool* cancelled) = 0;
mattm436ccfe2017-06-19 20:24:0837
38 protected:
39 friend class base::RefCountedThreadSafe<CryptoModuleBlockingPasswordDelegate>;
40
41 virtual ~CryptoModuleBlockingPasswordDelegate() {}
mattm@chromium.org99e5e9522013-12-16 13:05:2742};
43
mattm@chromium.org99e5e9522013-12-16 13:05:2744} // namespace crypto
45
46#endif // CRYPTO_NSS_CRYPTO_MODULE_DELEGATE_H_