LEFT | RIGHT |
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 /* vim: set ts=2 et sw=2 tw=80: */ | 2 /* vim: set ts=2 et sw=2 tw=80: */ |
3 /* This Source Code Form is subject to the terms of the Mozilla Public | 3 /* This Source Code Form is subject to the terms of the Mozilla Public |
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, | 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ | 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | 6 |
7 #ifndef gtest_utils_h__ | 7 #ifndef scoped_ptrs_h__ |
8 #define gtest_utils_h__ | 8 #define scoped_ptrs_h__ |
9 | 9 |
10 namespace nss_test { | 10 namespace nss_test { |
11 | 11 |
12 void ScopedDelete(PK11SlotInfo* slot) { PK11_FreeSlot(slot); } | 12 void ScopedDelete(PK11SlotInfo* slot) { PK11_FreeSlot(slot); } |
13 void ScopedDelete(SECItem* item) { SECITEM_FreeItem(item, true); } | 13 void ScopedDelete(SECItem* item) { SECITEM_FreeItem(item, true); } |
14 void ScopedDelete(SECKEYPublicKey* key) { SECKEY_DestroyPublicKey(key); } | 14 void ScopedDelete(SECKEYPublicKey* key) { SECKEY_DestroyPublicKey(key); } |
15 void ScopedDelete(SECKEYPrivateKey* key) { SECKEY_DestroyPrivateKey(key); } | 15 void ScopedDelete(SECKEYPrivateKey* key) { SECKEY_DestroyPrivateKey(key); } |
16 void ScopedDelete(CERTSubjectPublicKeyInfo* spki) { | 16 void ScopedDelete(CERTSubjectPublicKeyInfo* spki) { |
17 SECKEY_DestroySubjectPublicKeyInfo(spki); | 17 SECKEY_DestroySubjectPublicKeyInfo(spki); |
18 } | 18 } |
19 | 19 |
20 template<class T> | 20 template<class T> |
21 struct ScopedMaybeDelete { | 21 struct ScopedMaybeDelete { |
22 void operator()(T* ptr) { if (ptr) ScopedDelete(ptr); } | 22 void operator()(T* ptr) { if (ptr) ScopedDelete(ptr); } |
23 }; | 23 }; |
24 | 24 |
25 template<class T> | 25 template<class T> |
26 using ScopedUniquePtr = std::unique_ptr<T, ScopedMaybeDelete<T>>; | 26 using ScopedUniquePtr = std::unique_ptr<T, ScopedMaybeDelete<T>>; |
27 | 27 |
28 using ScopedPK11SlotInfo = ScopedUniquePtr<PK11SlotInfo>; | 28 using ScopedPK11SlotInfo = ScopedUniquePtr<PK11SlotInfo>; |
29 using ScopedSECItem = ScopedUniquePtr<SECItem>; | 29 using ScopedSECItem = ScopedUniquePtr<SECItem>; |
30 using ScopedSECKEYPublicKey = ScopedUniquePtr<SECKEYPublicKey>; | 30 using ScopedSECKEYPublicKey = ScopedUniquePtr<SECKEYPublicKey>; |
31 using ScopedSECKEYPrivateKey = ScopedUniquePtr<SECKEYPrivateKey>; | 31 using ScopedSECKEYPrivateKey = ScopedUniquePtr<SECKEYPrivateKey>; |
32 using ScopedCERTSubjectPublicKeyInfo = ScopedUniquePtr<CERTSubjectPublicKeyInfo>
; | 32 using ScopedCERTSubjectPublicKeyInfo = ScopedUniquePtr<CERTSubjectPublicKeyInfo>
; |
33 | 33 |
34 } // namespace nss_test | 34 } // namespace nss_test |
35 | 35 |
36 #endif | 36 #endif |
LEFT | RIGHT |