2016-01-25 18:14:18 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef scoped_ptrs_h__
|
|
|
|
#define scoped_ptrs_h__
|
|
|
|
|
2016-07-20 10:39:08 +03:00
|
|
|
#include <memory>
|
2016-04-27 15:51:59 +03:00
|
|
|
#include "cert.h"
|
2016-01-25 18:14:18 +03:00
|
|
|
#include "keyhi.h"
|
2016-04-27 15:51:59 +03:00
|
|
|
#include "pk11pub.h"
|
2016-01-25 18:14:18 +03:00
|
|
|
|
|
|
|
struct ScopedDelete {
|
2016-04-27 15:51:59 +03:00
|
|
|
void operator()(CERTCertificate* cert) { CERT_DestroyCertificate(cert); }
|
2016-11-16 16:06:23 +03:00
|
|
|
void operator()(CERTCertificateList* list) {
|
|
|
|
CERT_DestroyCertificateList(list);
|
|
|
|
}
|
2016-11-23 08:01:07 +03:00
|
|
|
void operator()(CERTCertList* list) { CERT_DestroyCertList(list); }
|
2016-04-27 15:51:59 +03:00
|
|
|
void operator()(CERTSubjectPublicKeyInfo* spki) {
|
|
|
|
SECKEY_DestroySubjectPublicKeyInfo(spki);
|
|
|
|
}
|
2016-01-25 18:14:18 +03:00
|
|
|
void operator()(PK11SlotInfo* slot) { PK11_FreeSlot(slot); }
|
2016-04-26 19:00:11 +03:00
|
|
|
void operator()(PK11SymKey* key) { PK11_FreeSymKey(key); }
|
2017-02-08 08:00:53 +03:00
|
|
|
void operator()(PRFileDesc* fd) { PR_Close(fd); }
|
2016-04-27 15:51:59 +03:00
|
|
|
void operator()(SECAlgorithmID* id) { SECOID_DestroyAlgorithmID(id, true); }
|
|
|
|
void operator()(SECItem* item) { SECITEM_FreeItem(item, true); }
|
2016-01-25 18:14:18 +03:00
|
|
|
void operator()(SECKEYPublicKey* key) { SECKEY_DestroyPublicKey(key); }
|
|
|
|
void operator()(SECKEYPrivateKey* key) { SECKEY_DestroyPrivateKey(key); }
|
2017-02-28 15:52:02 +03:00
|
|
|
void operator()(SECKEYPrivateKeyList* list) {
|
|
|
|
SECKEY_DestroyPrivateKeyList(list);
|
|
|
|
}
|
2016-01-25 18:14:18 +03:00
|
|
|
};
|
|
|
|
|
2016-08-19 12:20:21 +03:00
|
|
|
template <class T>
|
2016-01-25 18:14:18 +03:00
|
|
|
struct ScopedMaybeDelete {
|
2016-08-19 12:20:21 +03:00
|
|
|
void operator()(T* ptr) {
|
|
|
|
if (ptr) {
|
|
|
|
ScopedDelete del;
|
|
|
|
del(ptr);
|
|
|
|
}
|
|
|
|
}
|
2016-01-25 18:14:18 +03:00
|
|
|
};
|
|
|
|
|
2016-08-19 12:20:21 +03:00
|
|
|
#define SCOPED(x) typedef std::unique_ptr<x, ScopedMaybeDelete<x> > Scoped##x
|
2016-01-25 18:14:18 +03:00
|
|
|
|
2016-04-27 15:51:59 +03:00
|
|
|
SCOPED(CERTCertificate);
|
2016-11-16 16:06:23 +03:00
|
|
|
SCOPED(CERTCertificateList);
|
2016-11-23 08:01:07 +03:00
|
|
|
SCOPED(CERTCertList);
|
2016-04-27 15:51:59 +03:00
|
|
|
SCOPED(CERTSubjectPublicKeyInfo);
|
2016-01-25 18:14:18 +03:00
|
|
|
SCOPED(PK11SlotInfo);
|
2016-04-26 19:00:11 +03:00
|
|
|
SCOPED(PK11SymKey);
|
2017-02-08 08:00:53 +03:00
|
|
|
SCOPED(PRFileDesc);
|
2016-04-27 15:51:59 +03:00
|
|
|
SCOPED(SECAlgorithmID);
|
|
|
|
SCOPED(SECItem);
|
2016-01-25 18:14:18 +03:00
|
|
|
SCOPED(SECKEYPublicKey);
|
|
|
|
SCOPED(SECKEYPrivateKey);
|
2017-02-28 15:52:02 +03:00
|
|
|
SCOPED(SECKEYPrivateKeyList);
|
2016-01-25 18:14:18 +03:00
|
|
|
|
|
|
|
#undef SCOPED
|
|
|
|
|
2017-02-13 16:27:06 +03:00
|
|
|
#endif // scoped_ptrs_h__
|