1 // Copyright (c) 2011 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_
14 #include "base/memory/scoped_ptr.h"
18 template <typename Type
, void (*Destroyer
)(Type
*)>
20 void operator()(Type
* ptr
) const {
26 template <typename Type
, void (*Destroyer
)(Type
*, PRBool
), PRBool freeit
>
27 struct NSSDestroyer1
{
28 void operator()(Type
* ptr
) const {
30 Destroyer(ptr
, freeit
);
34 // Define some convenient scopers around NSS pointers.
35 typedef scoped_ptr_malloc
<
36 PK11Context
, NSSDestroyer1
<PK11Context
,
38 PR_TRUE
> > ScopedPK11Context
;
39 typedef scoped_ptr_malloc
<
40 PK11SlotInfo
, NSSDestroyer
<PK11SlotInfo
, PK11_FreeSlot
> > ScopedPK11Slot
;
41 typedef scoped_ptr_malloc
<
42 PK11SymKey
, NSSDestroyer
<PK11SymKey
, PK11_FreeSymKey
> > ScopedPK11SymKey
;
43 typedef scoped_ptr_malloc
<
44 SECKEYPublicKey
, NSSDestroyer
<SECKEYPublicKey
, SECKEY_DestroyPublicKey
> >
45 ScopedSECKEYPublicKey
;
46 typedef scoped_ptr_malloc
<
47 SECKEYPrivateKey
, NSSDestroyer
<SECKEYPrivateKey
, SECKEY_DestroyPrivateKey
> >
48 ScopedSECKEYPrivateKey
;
49 typedef scoped_ptr_malloc
<
50 SECAlgorithmID
, NSSDestroyer1
<SECAlgorithmID
,
51 SECOID_DestroyAlgorithmID
,
52 PR_TRUE
> > ScopedSECAlgorithmID
;
53 typedef scoped_ptr_malloc
<
54 SECItem
, NSSDestroyer1
<SECItem
,
56 PR_TRUE
> > ScopedSECItem
;
57 typedef scoped_ptr_malloc
<
58 PLArenaPool
, NSSDestroyer1
<PLArenaPool
,
60 PR_FALSE
> > ScopedPLArenaPool
;
64 #endif // CRYPTO_SCOPED_NSS_TYPES_H_