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 typedef void AllowSelfReset
;
20 void operator()(Type
* ptr
) const {
25 template <typename Type
, void (*Destroyer
)(Type
*, PRBool
), PRBool freeit
>
26 struct NSSDestroyer1
{
27 typedef void AllowSelfReset
;
28 void operator()(Type
* ptr
) const {
29 Destroyer(ptr
, freeit
);
33 // Define some convenient scopers around NSS pointers.
34 typedef scoped_ptr
<PK11Context
,
35 NSSDestroyer1
<PK11Context
, PK11_DestroyContext
, PR_TRUE
> >
37 typedef scoped_ptr
<PK11SlotInfo
, NSSDestroyer
<PK11SlotInfo
, PK11_FreeSlot
> >
39 typedef scoped_ptr
<PK11SlotList
, NSSDestroyer
<PK11SlotList
, PK11_FreeSlotList
> >
41 typedef scoped_ptr
<PK11SymKey
, NSSDestroyer
<PK11SymKey
, PK11_FreeSymKey
> >
43 typedef scoped_ptr
<SECKEYPublicKey
,
44 NSSDestroyer
<SECKEYPublicKey
, SECKEY_DestroyPublicKey
> >
45 ScopedSECKEYPublicKey
;
46 typedef scoped_ptr
<SECKEYPrivateKey
,
47 NSSDestroyer
<SECKEYPrivateKey
, SECKEY_DestroyPrivateKey
> >
48 ScopedSECKEYPrivateKey
;
49 typedef scoped_ptr
<SECAlgorithmID
,
50 NSSDestroyer1
<SECAlgorithmID
, SECOID_DestroyAlgorithmID
,
53 typedef scoped_ptr
<SECItem
, NSSDestroyer1
<SECItem
, SECITEM_FreeItem
, PR_TRUE
> >
55 typedef scoped_ptr
<PLArenaPool
,
56 NSSDestroyer1
<PLArenaPool
, PORT_FreeArena
, PR_FALSE
> >
61 #endif // CRYPTO_SCOPED_NSS_TYPES_H_