OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CRYPTO_SCOPED_NSS_TYPES_H_ | 5 #ifndef CRYPTO_SCOPED_NSS_TYPES_H_ |
6 #define CRYPTO_SCOPED_NSS_TYPES_H_ | 6 #define CRYPTO_SCOPED_NSS_TYPES_H_ |
7 | 7 |
8 #include <keyhi.h> | 8 #include <keyhi.h> |
9 #include <nss.h> | 9 #include <nss.h> |
10 #include <pk11pub.h> | 10 #include <pk11pub.h> |
11 #include <plarena.h> | 11 #include <plarena.h> |
12 | 12 |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 | 14 |
15 namespace crypto { | 15 namespace crypto { |
16 | 16 |
17 template <typename Type, void (*Destroyer)(Type*)> | 17 template <typename Type, void (*Destroyer)(Type*)> |
18 struct NSSDestroyer { | 18 struct NSSDestroyer { |
19 typedef void AllowSelfReset; | |
20 void operator()(Type* ptr) const { | 19 void operator()(Type* ptr) const { |
21 Destroyer(ptr); | 20 Destroyer(ptr); |
22 } | 21 } |
23 }; | 22 }; |
24 | 23 |
25 template <typename Type, void (*Destroyer)(Type*, PRBool), PRBool freeit> | 24 template <typename Type, void (*Destroyer)(Type*, PRBool), PRBool freeit> |
26 struct NSSDestroyer1 { | 25 struct NSSDestroyer1 { |
27 typedef void AllowSelfReset; | |
28 void operator()(Type* ptr) const { | 26 void operator()(Type* ptr) const { |
29 Destroyer(ptr, freeit); | 27 Destroyer(ptr, freeit); |
30 } | 28 } |
31 }; | 29 }; |
32 | 30 |
33 // Define some convenient scopers around NSS pointers. | 31 // Define some convenient scopers around NSS pointers. |
34 typedef scoped_ptr<PK11Context, | 32 typedef scoped_ptr<PK11Context, |
35 NSSDestroyer1<PK11Context, PK11_DestroyContext, PR_TRUE> > | 33 NSSDestroyer1<PK11Context, PK11_DestroyContext, PR_TRUE> > |
36 ScopedPK11Context; | 34 ScopedPK11Context; |
37 typedef scoped_ptr<PK11SlotInfo, NSSDestroyer<PK11SlotInfo, PK11_FreeSlot> > | 35 typedef scoped_ptr<PK11SlotInfo, NSSDestroyer<PK11SlotInfo, PK11_FreeSlot> > |
(...skipping 14 matching lines...) Expand all Loading... |
52 ScopedSECAlgorithmID; | 50 ScopedSECAlgorithmID; |
53 typedef scoped_ptr<SECItem, NSSDestroyer1<SECItem, SECITEM_FreeItem, PR_TRUE> > | 51 typedef scoped_ptr<SECItem, NSSDestroyer1<SECItem, SECITEM_FreeItem, PR_TRUE> > |
54 ScopedSECItem; | 52 ScopedSECItem; |
55 typedef scoped_ptr<PLArenaPool, | 53 typedef scoped_ptr<PLArenaPool, |
56 NSSDestroyer1<PLArenaPool, PORT_FreeArena, PR_FALSE> > | 54 NSSDestroyer1<PLArenaPool, PORT_FreeArena, PR_FALSE> > |
57 ScopedPLArenaPool; | 55 ScopedPLArenaPool; |
58 | 56 |
59 } // namespace crypto | 57 } // namespace crypto |
60 | 58 |
61 #endif // CRYPTO_SCOPED_NSS_TYPES_H_ | 59 #endif // CRYPTO_SCOPED_NSS_TYPES_H_ |
OLD | NEW |