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_
13 #include "base/memory/scoped_ptr.h"
17 template <typename Type
, void (*Destroyer
)(Type
*)>
19 void operator()(Type
* ptr
) const {
25 template <typename Type
, void (*Destroyer
)(Type
*, PRBool
), PRBool freeit
>
26 struct NSSDestroyer1
{
27 void operator()(Type
* ptr
) const {
29 Destroyer(ptr
, freeit
);
33 // Define some convenient scopers around NSS pointers.
34 typedef scoped_ptr_malloc
<
35 PK11Context
, NSSDestroyer1
<PK11Context
,
37 PR_TRUE
> > ScopedPK11Context
;
38 typedef scoped_ptr_malloc
<
39 PK11SlotInfo
, NSSDestroyer
<PK11SlotInfo
, PK11_FreeSlot
> > ScopedPK11Slot
;
40 typedef scoped_ptr_malloc
<
41 PK11SlotList
, NSSDestroyer
<PK11SlotList
,
42 PK11_FreeSlotList
> > ScopedPK11SlotList
;
43 typedef scoped_ptr_malloc
<
44 PK11SymKey
, NSSDestroyer
<PK11SymKey
, PK11_FreeSymKey
> > ScopedPK11SymKey
;
45 typedef scoped_ptr_malloc
<
46 SECKEYPublicKey
, NSSDestroyer
<SECKEYPublicKey
, SECKEY_DestroyPublicKey
> >
47 ScopedSECKEYPublicKey
;
48 typedef scoped_ptr_malloc
<
49 SECKEYPrivateKey
, NSSDestroyer
<SECKEYPrivateKey
, SECKEY_DestroyPrivateKey
> >
50 ScopedSECKEYPrivateKey
;
51 typedef scoped_ptr_malloc
<
52 SECAlgorithmID
, NSSDestroyer1
<SECAlgorithmID
,
53 SECOID_DestroyAlgorithmID
,
54 PR_TRUE
> > ScopedSECAlgorithmID
;
55 typedef scoped_ptr_malloc
<
56 SECItem
, NSSDestroyer1
<SECItem
,
58 PR_TRUE
> > ScopedSECItem
;
59 typedef scoped_ptr_malloc
<
60 PLArenaPool
, NSSDestroyer1
<PLArenaPool
,
62 PR_FALSE
> > ScopedPLArenaPool
;
66 #endif // CRYPTO_SCOPED_NSS_TYPES_H_