Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1086)

Side by Side Diff: crypto/scoped_nss_types.h

Issue 1870233002: Convert crypto to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « crypto/rsa_private_key_unittest.cc ('k') | crypto/scoped_openssl_types.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory>
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 void operator()(Type* ptr) const { 19 void operator()(Type* ptr) const {
20 Destroyer(ptr); 20 Destroyer(ptr);
21 } 21 }
22 }; 22 };
23 23
24 template <typename Type, void (*Destroyer)(Type*, PRBool), PRBool freeit> 24 template <typename Type, void (*Destroyer)(Type*, PRBool), PRBool freeit>
25 struct NSSDestroyer1 { 25 struct NSSDestroyer1 {
26 void operator()(Type* ptr) const { 26 void operator()(Type* ptr) const {
27 Destroyer(ptr, freeit); 27 Destroyer(ptr, freeit);
28 } 28 }
29 }; 29 };
30 30
31 // Define some convenient scopers around NSS pointers. 31 // Define some convenient scopers around NSS pointers.
32 typedef scoped_ptr<PK11Context, 32 typedef std::unique_ptr<
33 NSSDestroyer1<PK11Context, PK11_DestroyContext, PR_TRUE> > 33 PK11Context,
34 NSSDestroyer1<PK11Context, PK11_DestroyContext, PR_TRUE>>
34 ScopedPK11Context; 35 ScopedPK11Context;
35 typedef scoped_ptr<PK11SlotInfo, NSSDestroyer<PK11SlotInfo, PK11_FreeSlot> > 36 typedef std::unique_ptr<PK11SlotInfo, NSSDestroyer<PK11SlotInfo, PK11_FreeSlot>>
36 ScopedPK11Slot; 37 ScopedPK11Slot;
37 typedef scoped_ptr<PK11SlotList, NSSDestroyer<PK11SlotList, PK11_FreeSlotList> > 38 typedef std::unique_ptr<PK11SlotList,
39 NSSDestroyer<PK11SlotList, PK11_FreeSlotList>>
38 ScopedPK11SlotList; 40 ScopedPK11SlotList;
39 typedef scoped_ptr<PK11SymKey, NSSDestroyer<PK11SymKey, PK11_FreeSymKey> > 41 typedef std::unique_ptr<PK11SymKey, NSSDestroyer<PK11SymKey, PK11_FreeSymKey>>
40 ScopedPK11SymKey; 42 ScopedPK11SymKey;
41 typedef scoped_ptr<SECKEYPublicKey, 43 typedef std::unique_ptr<SECKEYPublicKey,
42 NSSDestroyer<SECKEYPublicKey, SECKEY_DestroyPublicKey> > 44 NSSDestroyer<SECKEYPublicKey, SECKEY_DestroyPublicKey>>
43 ScopedSECKEYPublicKey; 45 ScopedSECKEYPublicKey;
44 typedef scoped_ptr<SECKEYPrivateKey, 46 typedef std::unique_ptr<
45 NSSDestroyer<SECKEYPrivateKey, SECKEY_DestroyPrivateKey> > 47 SECKEYPrivateKey,
48 NSSDestroyer<SECKEYPrivateKey, SECKEY_DestroyPrivateKey>>
46 ScopedSECKEYPrivateKey; 49 ScopedSECKEYPrivateKey;
47 typedef scoped_ptr<SECAlgorithmID, 50 typedef std::unique_ptr<
48 NSSDestroyer1<SECAlgorithmID, SECOID_DestroyAlgorithmID, 51 SECAlgorithmID,
49 PR_TRUE> > 52 NSSDestroyer1<SECAlgorithmID, SECOID_DestroyAlgorithmID, PR_TRUE>>
50 ScopedSECAlgorithmID; 53 ScopedSECAlgorithmID;
51 typedef scoped_ptr<SECItem, NSSDestroyer1<SECItem, SECITEM_FreeItem, PR_TRUE> > 54 typedef std::unique_ptr<SECItem,
55 NSSDestroyer1<SECItem, SECITEM_FreeItem, PR_TRUE>>
52 ScopedSECItem; 56 ScopedSECItem;
53 typedef scoped_ptr<PLArenaPool, 57 typedef std::unique_ptr<PLArenaPool,
54 NSSDestroyer1<PLArenaPool, PORT_FreeArena, PR_FALSE> > 58 NSSDestroyer1<PLArenaPool, PORT_FreeArena, PR_FALSE>>
55 ScopedPLArenaPool; 59 ScopedPLArenaPool;
56 60
57 } // namespace crypto 61 } // namespace crypto
58 62
59 #endif // CRYPTO_SCOPED_NSS_TYPES_H_ 63 #endif // CRYPTO_SCOPED_NSS_TYPES_H_
OLDNEW
« no previous file with comments | « crypto/rsa_private_key_unittest.cc ('k') | crypto/scoped_openssl_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698