chromeos: bluetooth: add BluetoothNodeClient
[chromium-blink-merge.git] / crypto / scoped_nss_types.h
blob9bb9968864052ecdf74ce47bf1aa4e58e67c43ce
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_
7 #pragma once
9 #include <keyhi.h>
10 #include <nss.h>
11 #include <pk11pub.h>
12 #include <plarena.h>
14 #include "base/memory/scoped_ptr.h"
16 namespace crypto {
18 template <typename Type, void (*Destroyer)(Type*)>
19 struct NSSDestroyer {
20 void operator()(Type* ptr) const {
21 if (ptr)
22 Destroyer(ptr);
26 template <typename Type, void (*Destroyer)(Type*, PRBool), PRBool freeit>
27 struct NSSDestroyer1 {
28 void operator()(Type* ptr) const {
29 if (ptr)
30 Destroyer(ptr, freeit);
34 // Define some convenient scopers around NSS pointers.
35 typedef scoped_ptr_malloc<
36 PK11Context, NSSDestroyer1<PK11Context,
37 PK11_DestroyContext,
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,
55 SECITEM_FreeItem,
56 PR_TRUE> > ScopedSECItem;
57 typedef scoped_ptr_malloc<
58 PLArenaPool, NSSDestroyer1<PLArenaPool,
59 PORT_FreeArena,
60 PR_FALSE> > ScopedPLArenaPool;
62 } // namespace crypto
64 #endif // CRYPTO_SCOPED_NSS_TYPES_H_