Reland 189a2ed4d209231d517b0e64a722722dead3f17a Fixes HasEventListener check in Exten...
[chromium-blink-merge.git] / crypto / scoped_nss_types.h
blob8e96e8d4e20ffedb34a529e62ec7e92451bd8c5d
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_SCOPED_NSS_TYPES_H_
6 #define CRYPTO_SCOPED_NSS_TYPES_H_
8 #include <keyhi.h>
9 #include <nss.h>
10 #include <pk11pub.h>
11 #include <plarena.h>
13 #include "base/memory/scoped_ptr.h"
15 namespace crypto {
17 template <typename Type, void (*Destroyer)(Type*)>
18 struct NSSDestroyer {
19 void operator()(Type* ptr) const {
20 Destroyer(ptr);
24 template <typename Type, void (*Destroyer)(Type*, PRBool), PRBool freeit>
25 struct NSSDestroyer1 {
26 void operator()(Type* ptr) const {
27 Destroyer(ptr, freeit);
31 // Define some convenient scopers around NSS pointers.
32 typedef scoped_ptr<PK11Context,
33 NSSDestroyer1<PK11Context, PK11_DestroyContext, PR_TRUE> >
34 ScopedPK11Context;
35 typedef scoped_ptr<PK11SlotInfo, NSSDestroyer<PK11SlotInfo, PK11_FreeSlot> >
36 ScopedPK11Slot;
37 typedef scoped_ptr<PK11SlotList, NSSDestroyer<PK11SlotList, PK11_FreeSlotList> >
38 ScopedPK11SlotList;
39 typedef scoped_ptr<PK11SymKey, NSSDestroyer<PK11SymKey, PK11_FreeSymKey> >
40 ScopedPK11SymKey;
41 typedef scoped_ptr<SECKEYPublicKey,
42 NSSDestroyer<SECKEYPublicKey, SECKEY_DestroyPublicKey> >
43 ScopedSECKEYPublicKey;
44 typedef scoped_ptr<SECKEYPrivateKey,
45 NSSDestroyer<SECKEYPrivateKey, SECKEY_DestroyPrivateKey> >
46 ScopedSECKEYPrivateKey;
47 typedef scoped_ptr<SECAlgorithmID,
48 NSSDestroyer1<SECAlgorithmID, SECOID_DestroyAlgorithmID,
49 PR_TRUE> >
50 ScopedSECAlgorithmID;
51 typedef scoped_ptr<SECItem, NSSDestroyer1<SECItem, SECITEM_FreeItem, PR_TRUE> >
52 ScopedSECItem;
53 typedef scoped_ptr<PLArenaPool,
54 NSSDestroyer1<PLArenaPool, PORT_FreeArena, PR_FALSE> >
55 ScopedPLArenaPool;
57 } // namespace crypto
59 #endif // CRYPTO_SCOPED_NSS_TYPES_H_