Reduce binary size impact of synthetic delays
[chromium-blink-merge.git] / crypto / nss_util_internal.h
blob262a59a1ba93fa059a0fd8bb2bb61bb49fcbfaf5
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
3 // found in the LICENSE file.
5 #ifndef CRYPTO_NSS_UTIL_INTERNAL_H_
6 #define CRYPTO_NSS_UTIL_INTERNAL_H_
8 #include <secmodt.h>
10 #include "base/callback.h"
11 #include "base/compiler_specific.h"
12 #include "crypto/crypto_export.h"
13 #include "crypto/scoped_nss_types.h"
15 namespace base {
16 class FilePath;
19 // These functions return a type defined in an NSS header, and so cannot be
20 // declared in nss_util.h. Hence, they are declared here.
22 namespace crypto {
24 // Returns a reference to the default NSS key slot for storing
25 // public-key data only (e.g. server certs). Caller must release
26 // returned reference with PK11_FreeSlot.
27 CRYPTO_EXPORT PK11SlotInfo* GetPublicNSSKeySlot() WARN_UNUSED_RESULT;
29 // Returns a reference to the default slot for storing private-key and
30 // mixed private-key/public-key data. Returns a hardware (TPM) NSS
31 // key slot if on ChromeOS and EnableTPMForNSS() has been called
32 // successfully. Caller must release returned reference with
33 // PK11_FreeSlot.
34 CRYPTO_EXPORT PK11SlotInfo* GetPrivateNSSKeySlot() WARN_UNUSED_RESULT;
36 // A helper class that acquires the SECMOD list read lock while the
37 // AutoSECMODListReadLock is in scope.
38 class CRYPTO_EXPORT AutoSECMODListReadLock {
39 public:
40 AutoSECMODListReadLock();
41 ~AutoSECMODListReadLock();
43 private:
44 SECMODListLock* lock_;
45 DISALLOW_COPY_AND_ASSIGN(AutoSECMODListReadLock);
48 #if defined(OS_CHROMEOS)
49 // Prepare per-user NSS slot mapping. It is safe to call this function multiple
50 // times. Returns true if the user was added, or false if it already existed.
51 CRYPTO_EXPORT bool InitializeNSSForChromeOSUser(
52 const std::string& email,
53 const std::string& username_hash,
54 bool is_primary_user,
55 const base::FilePath& path) WARN_UNUSED_RESULT;
57 // Use TPM slot |slot_id| for user. InitializeNSSForChromeOSUser must have been
58 // called first.
59 CRYPTO_EXPORT void InitializeTPMForChromeOSUser(
60 const std::string& username_hash,
61 CK_SLOT_ID slot_id);
63 // Use the software slot as the private slot for user.
64 // InitializeNSSForChromeOSUser must have been called first.
65 CRYPTO_EXPORT void InitializePrivateSoftwareSlotForChromeOSUser(
66 const std::string& username_hash);
68 // Returns a reference to the public slot for user.
69 CRYPTO_EXPORT ScopedPK11Slot GetPublicSlotForChromeOSUser(
70 const std::string& username_hash) WARN_UNUSED_RESULT;
72 // Returns the private slot for |username_hash| if it is loaded. If it is not
73 // loaded and |callback| is non-null, the |callback| will be run once the slot
74 // is loaded.
75 CRYPTO_EXPORT ScopedPK11Slot GetPrivateSlotForChromeOSUser(
76 const std::string& username_hash,
77 const base::Callback<void(ScopedPK11Slot)>& callback) WARN_UNUSED_RESULT;
78 #endif // defined(OS_CHROMEOS)
80 } // namespace crypto
82 #endif // CRYPTO_NSS_UTIL_INTERNAL_H_