⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cpgpkeydb.h

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 H
📖 第 1 页 / 共 2 页
字号:
/*____________________________________________________________________________
		Copyright (C) 2002 PGP Corporation
        All rights reserved.

        $Id: CPGPKeyDB.h,v 1.7 2002/08/06 20:10:19 dallen Exp $
____________________________________________________________________________*/

#ifndef Included_CPGPKeyDB_h	// [
#define Included_CPGPKeyDB_h

#include "pgpKeys.h"
#include "pgpClientLib.h"

#include "CPGPKey.h"

_PGP_BEGIN

// Class CPGPKeyDB

class CPGPKeyDB
{
	NOT_COPYABLE(CPGPKeyDB)

public:
	CPGPKeyDB();
	CPGPKeyDB(PGPContextRef context);
	CPGPKeyDB(PGPContextRef context, PGPOpenKeyDBFileOptions options, 
		PGPFileSpecRef pubKeysFileSpec, PGPFileSpecRef privKeysFileSpec);
	CPGPKeyDB(PGPKeyDBRef keyDB, PGPBoolean weOwn = FALSE);
	~CPGPKeyDB();

	CPGPKeyDB&	operator=(PGPKeyDBRef keySet);

	operator PGPKeyDBRef() const {return mKeyDB;}
	PGPKeyDBRef	Get() const {return mKeyDB;}

	PGPBoolean	IsAttached() const;
	PGPBoolean	WeCreated() const {return mWeCreated;}

	PGPUInt32	Count() const;

	void	Flush();
	void	Import(PGPContextRef pgpContext);

	void	Create(PGPContextRef context);
	void	Open(PGPContextRef context, PGPOpenKeyDBFileOptions options, 
		PGPFileSpecRef pubKeysFileSpec, PGPFileSpecRef privKeysFileSpec);
	void	OpenDefault(PGPContextRef context, 
		PGPOpenKeyDBFileOptions options = kPGPOpenKeyDBFileOptions_None);
	void	Attach(PGPKeyDBRef keyDB, PGPBoolean weOwn = FALSE);
	void	Clear();

private:
	PGPBoolean	mWeCreated;
	PGPKeyDBRef	mKeyDB;
};


// Class CPGPKeySet

class CPGPKeySet
{
	NOT_COPYABLE(CPGPKeySet)

public:
	CPGPKeySet();
	CPGPKeySet(PGPKeyDBRef keyDB, PGPKeySetRef keySet = kInvalidPGPKeySetRef);
	CPGPKeySet(PGPKeyDBObjRef key);
	CPGPKeySet(PGPKeySetRef keySet, PGPBoolean weOwn = FALSE);
	~CPGPKeySet();

	CPGPKeySet&	operator=(PGPKeySetRef keySet);

	operator PGPKeySetRef() const {return mKeySet;}
	PGPKeySetRef	Get() const {return mKeySet;}

	PGPBoolean	IsAttached() const;
	PGPBoolean	WeCreated() const {return mWeCreated;}

	PGPUInt32	Count() const;
	PGPKeyDBRef	KeyDB() const;

	void	Add(PGPKeySetRef keysToAdd);
	void	Add(PGPKeyDBObjRef keyToAdd);

	void	Create(PGPKeyDBRef keyDB, 
		PGPKeySetRef keySet = kInvalidPGPKeySetRef);
	void	CreateEmpty(PGPKeyDBRef keyDB);
	void	CreateOneKeySet(PGPKeyDBObjRef key);
	void	Attach(PGPKeySetRef keySet, PGPBoolean weOwn = FALSE);
	void	Clear();

private:
	PGPBoolean		mWeCreated;
	PGPKeySetRef	mKeySet;
};


// Class CPGPKeyList

class CPGPKeyList
{
	NOT_COPYABLE(CPGPKeyList)

public:
	CPGPKeyList(PGPKeySetRef keySet, PGPKeyOrdering ordering);
	CPGPKeyList(PGPKeyListRef keyList);
	~CPGPKeyList();

	operator PGPKeyListRef() const {return mKeyList;}
	CPGPKeyList&	operator=(PGPKeyListRef keyList);

	PGPKeyListRef	Get() const {return mKeyList;}

	PGPBoolean	IsAttached() const;
	PGPBoolean	WeCreated() const {return mWeCreated;}

	void	Assign(PGPKeySetRef keySet, PGPKeyOrdering ordering);
	void	Attach(PGPKeyListRef keyList);
	void	Clear();

private:
	PGPBoolean		mWeCreated;
	PGPKeyListRef	mKeyList;
};


// Class CPGPKeyIter

class CPGPKeyIter
{
	NOT_COPYABLE(CPGPKeyIter)

public:
	CPGPKeyIter(PGPKeyListRef keyList);
	CPGPKeyIter(PGPKeyIterRef keyIter);
	~CPGPKeyIter();

	operator PGPKeyIterRef() const {return mKeyIter;}
	CPGPKeyIter&	operator=(PGPKeyIterRef keyIter);

	PGPKeyIterRef	Get() const {return mKeyIter;}

	PGPBoolean	IsAttached() const;
	PGPBoolean	WeCreated() const {return mWeCreated;}

	PGPUInt32	Count() const;

	void		Key(CPGPKey& key) const;
	void		SubKey(CPGPKey& subKey) const;
	PGPUInt32	Index() const;
	PGPInt32	Seek(PGPKeyDBObjRef key) const;

	PGPBoolean	Move(PGPInt32 relOffset, CPGPKey& key) const;
	PGPBoolean	Next(CPGPKey& key) const;
	PGPBoolean	NextSubKey(CPGPKey& key) const;
	PGPBoolean	Prev(CPGPKey& key) const;
	PGPBoolean	PrevSubKey(CPGPKey& key) const;

	void	Rewind() const;
	void	RewindSubKey() const;

	void	Copy(CPGPKeyIter& keyIter) const;

	void	Assign(PGPKeyListRef keyList);
	void	Attach(PGPKeyIterRef keyIter);
	void	Clear();

private:
	PGPBoolean		mWeCreated;
	PGPKeyIterRef	mKeyIter;
};


// Class CPGPFilter

class CPGPFilter
{
	NOT_COPYABLE(CPGPFilter)

public:
	CPGPFilter();
	CPGPFilter(PGPFilterRef filter);

	~CPGPFilter();

	operator PGPFilterRef() const {return mFilter;}
	CPGPFilter&	operator=(PGPFilterRef filter);

	PGPFilterRef	Get() const {return mFilter;}

	PGPBoolean	IsAttached() const;
	PGPBoolean	WeCreated() const {return mWeCreated;}

	void	Intersect(CPGPFilter& filter);
	void	Union(CPGPFilter& filter);

	void	Attach(PGPFilterRef filter);
	void	NewBooleanFilter(PGPContextRef context, 
		PGPKeyDBObjProperty whichProperty, PGPBoolean match = TRUE);
	void	NewNumericFilter(PGPContextRef context, 
		PGPKeyDBObjProperty whichProperty, PGPUInt32 matchValue, 
		PGPMatchCriterion matchCriteria = kPGPMatchCriterion_Equal);
	void	NewTimeFilter(PGPContextRef context, 
		PGPKeyDBObjProperty whichProperty, PGPTime matchValue, 
		PGPMatchCriterion matchCriteria = kPGPMatchCriterion_Equal);
	void	NewDataFilter(PGPContextRef context, 
		PGPKeyDBObjProperty whichProperty, const void *matchData, 
		PGPSize matchDataSize, PGPMatchCriterion matchCriteria = 
		kPGPMatchCriterion_Equal);
	void	Clear();

private:
	PGPBoolean		mWeCreated;
	PGPFilterRef	mFilter;
};


// Class CPGPKeyDB member functions

inline 
CPGPKeyDB::CPGPKeyDB() : 
	mWeCreated(FALSE), mKeyDB(kInvalidPGPKeyDBRef)
{
}

inline 
CPGPKeyDB::CPGPKeyDB(PGPContextRef context) : 
	mWeCreated(FALSE), mKeyDB(kInvalidPGPKeyDBRef)
{
	Create(context);
}

inline 
CPGPKeyDB::CPGPKeyDB(
	PGPContextRef			context, 
	PGPOpenKeyDBFileOptions	options, 
	PGPFileSpecRef			pubKeysFileSpec, 
	PGPFileSpecRef			privKeysFileSpec) : 

	mWeCreated(FALSE), mKeyDB(kInvalidPGPKeyDBRef)
{
	Open(context, options, pubKeysFileSpec, privKeysFileSpec);
}

inline 
CPGPKeyDB::CPGPKeyDB(PGPKeyDBRef keyDB, PGPBoolean weOwn) : 
	mWeCreated(FALSE), mKeyDB(kInvalidPGPKeyDBRef)
{
	Attach(keyDB, weOwn);
}

inline 
CPGPKeyDB::~CPGPKeyDB()
{
	try
	{
		Clear();
	}
	catch (CComboError&) { }
}

inline 
CPGPKeyDB& 
CPGPKeyDB::operator=(PGPKeyDBRef keyDB)
{
	Attach(keyDB);
	return *this;
}

inline 
PGPBoolean 
CPGPKeyDB::IsAttached() const
{
	return PGPKeyDBRefIsValid(mKeyDB);
}

inline 
PGPUInt32 
CPGPKeyDB::Count() const
{
	pgpAssert(IsAttached());

	PGPUInt32	count;

	PGPError	pgpErr	= PGPCountKeysInKeyDB(mKeyDB, &count);
	THROW_IF_PGPERROR(pgpErr);

	return count;
}

inline 
void 
CPGPKeyDB::Flush()
{
	pgpAssert(IsAttached());

	PGPError	error	= PGPFlushKeyDB(mKeyDB);
	THROW_IF_PGPERROR(error);
}

inline 
void 
CPGPKeyDB::Import(PGPContextRef pgpContext)
{
	PGPError	pgpErr	= PGPImport(pgpContext, &mKeyDB, 
		PGPOLastOption(pgpContext));
	THROW_IF_PGPERROR(pgpErr);
}

inline 
void 
CPGPKeyDB::Create(PGPContextRef context)
{
	pgpAssert(PGPContextRefIsValid(context));

	Clear();

	PGPError	error	= PGPNewKeyDB(context, &mKeyDB);
	THROW_IF_PGPERROR(error);

	mWeCreated = TRUE;
}

inline 
void 
CPGPKeyDB::Open(
	PGPContextRef			context, 
	PGPOpenKeyDBFileOptions	options, 
	PGPFileSpecRef			pubKeysFileSpec, 
	PGPFileSpecRef			privKeysFileSpec)
{
	Clear();
	
	PGPError	error	= PGPOpenKeyDBFile(context, options, 
		pubKeysFileSpec, privKeysFileSpec, &mKeyDB);
	THROW_IF_PGPERROR(error);

	mWeCreated = TRUE;
}

inline 
void 
CPGPKeyDB::OpenDefault(PGPContextRef context, PGPOpenKeyDBFileOptions options)
{
	Clear();
	
	PGPError	error	= PGPclOpenDefaultKeyrings(context, options, &mKeyDB);
	THROW_IF_PGPERROR(error);

	mWeCreated = TRUE;
}

inline 
void 
CPGPKeyDB::Attach(PGPKeyDBRef keyDB, PGPBoolean weOwn)
{
	if (mKeyDB == keyDB)
		return;

	pgpAssert(PGPKeyDBRefIsValid(keyDB));
	Clear();

	mWeCreated = weOwn;
	mKeyDB = keyDB;
}

inline 
void 
CPGPKeyDB::Clear()
{
	if (WeCreated())
		PGPFreeKeyDB(mKeyDB);

	mWeCreated = FALSE;
	mKeyDB = kInvalidPGPKeyDBRef;
}


// Class CPGPKeySet member functions

inline 
CPGPKeySet::CPGPKeySet() : 
	mWeCreated(FALSE), mKeySet(kInvalidPGPKeySetRef)
{
}

inline 
CPGPKeySet::CPGPKeySet(PGPKeyDBRef keyDB, PGPKeySetRef keySet) : 
	mWeCreated(FALSE), mKeySet(kInvalidPGPKeySetRef)
{
	Create(keyDB, keySet);
}

inline 
CPGPKeySet::CPGPKeySet(PGPKeyDBObjRef key) : 
	mWeCreated(FALSE), mKeySet(kInvalidPGPKeySetRef)
{
	CreateOneKeySet(key);
}

inline 
CPGPKeySet::CPGPKeySet(PGPKeySetRef keySet, PGPBoolean weOwn) : 
	mWeCreated(FALSE), mKeySet(kInvalidPGPKeySetRef)
{
	Attach(keySet, weOwn);
}

inline 
CPGPKeySet::~CPGPKeySet()
{
	try
	{
		Clear();
	}
	catch (CComboError&) { }
}

inline 
CPGPKeySet& 
CPGPKeySet::operator=(PGPKeySetRef keySet)
{
	Attach(keySet);
	return *this;
}

inline 
PGPBoolean 
CPGPKeySet::IsAttached() const
{
	return PGPKeySetRefIsValid(mKeySet);
}

inline 
PGPUInt32 
CPGPKeySet::Count() const
{
	pgpAssert(IsAttached());

	PGPUInt32	count;

	PGPError	pgpErr	= PGPCountKeys(mKeySet, &count);
	THROW_IF_PGPERROR(pgpErr);

	return count;
}

inline 
PGPKeyDBRef 
CPGPKeySet::KeyDB() const
{
	return PGPPeekKeySetKeyDB(mKeySet);
}

inline 
void 
CPGPKeySet::Add(PGPKeySetRef keysToAdd)
{
	pgpAssert(IsAttached());

	PGPError	pgpErr	= PGPAddKeys(keysToAdd, mKeySet);
	THROW_IF_PGPERROR(pgpErr);
}

inline 
void 
CPGPKeySet::Add(PGPKeyDBObjRef keyToAdd)
{
	pgpAssert(IsAttached());

	PGPError	pgpErr	= PGPAddKey(keyToAdd, mKeySet);
	THROW_IF_PGPERROR(pgpErr);
}

inline 
void 
CPGPKeySet::Create(PGPKeyDBRef keyDB, PGPKeySetRef keySet)
{
	pgpAssert(PGPKeyDBRefIsValid(keyDB));

	Clear();
	PGPError	pgpErr	= kPGPError_NoErr;

	if (PGPKeySetRefIsValid(keySet))
		pgpErr = PGPCopyKeys(keySet, keyDB, &mKeySet);
	else
		pgpErr = PGPNewKeySet(keyDB, &mKeySet);

	THROW_IF_PGPERROR(pgpErr);

	mWeCreated = TRUE;
}

inline 
void 
CPGPKeySet::CreateEmpty(PGPKeyDBRef keyDB)
{
	pgpAssert(PGPKeyDBRefIsValid(keyDB));

	Clear();

	PGPError	pgpErr	= PGPNewEmptyKeySet(keyDB, &mKeySet);
	THROW_IF_PGPERROR(pgpErr);

	mWeCreated = TRUE;
}

inline 
void 
CPGPKeySet::CreateOneKeySet(PGPKeyDBObjRef key)
{
	pgpAssert(PGPKeyDBObjRefIsValid(key));

	Clear();

	PGPError	pgpErr	= PGPNewOneKeySet(key, &mKeySet);
	THROW_IF_PGPERROR(pgpErr);

	mWeCreated = TRUE;
}

inline 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -