1 // Copyright 2012 The Chromium Authors
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_SCOPED_NSS_TYPES_H_
6 #define CRYPTO_SCOPED_NSS_TYPES_H_
19 template <typename Type, void (*Destroyer)(Type*)>
21 void operator()(Type* ptr) const { Destroyer(ptr); }
24 template <typename Type, void (*Destroyer)(Type*, PRBool), PRBool freeit>
25 struct NSSDestroyer1 {
26 void operator()(Type* ptr) const { Destroyer(ptr, freeit); }
29 // Define some convenient scopers around NSS pointers.
30 typedef std::unique_ptr<
32 NSSDestroyer1<PK11Context, PK11_DestroyContext, PR_TRUE>>
34 typedef std::unique_ptr<PK11SlotInfo, NSSDestroyer<PK11SlotInfo, PK11_FreeSlot>>
36 typedef std::unique_ptr<PK11SlotList,
37 NSSDestroyer<PK11SlotList, PK11_FreeSlotList>>
39 typedef std::unique_ptr<
41 NSSDestroyer<SECKEYPublicKeyList, SECKEY_DestroyPublicKeyList>>
42 ScopedSECKEYPublicKeyList;
43 typedef std::unique_ptr<PK11SymKey, NSSDestroyer<PK11SymKey, PK11_FreeSymKey>>
45 typedef std::unique_ptr<SECKEYPublicKey,
46 NSSDestroyer<SECKEYPublicKey, SECKEY_DestroyPublicKey>>
47 ScopedSECKEYPublicKey;
48 typedef std::unique_ptr<
50 NSSDestroyer<SECKEYPrivateKey, SECKEY_DestroyPrivateKey>>
51 ScopedSECKEYPrivateKey;
52 typedef std::unique_ptr<
54 NSSDestroyer1<SECAlgorithmID, SECOID_DestroyAlgorithmID, PR_TRUE>>
56 typedef std::unique_ptr<SECItem,
57 NSSDestroyer1<SECItem, SECITEM_FreeItem, PR_TRUE>>
59 typedef std::unique_ptr<PLArenaPool,
60 NSSDestroyer1<PLArenaPool, PORT_FreeArena, PR_FALSE>>
62 typedef std::unique_ptr<
63 CERTSubjectPublicKeyInfo,
64 NSSDestroyer<CERTSubjectPublicKeyInfo, SECKEY_DestroySubjectPublicKeyInfo>>
65 ScopedCERTSubjectPublicKeyInfo;
66 typedef std::unique_ptr<CERTCertList,
67 NSSDestroyer<CERTCertList, CERT_DestroyCertList>>
72 #endif // CRYPTO_SCOPED_NSS_TYPES_H_