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

📄 cpgptlscontext.h

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

        $Id: CPGPtlsContext.h,v 1.3 2002/08/06 20:10:20 dallen Exp $
____________________________________________________________________________*/

#ifndef Included_CPGPtlsContext_h	// [
#define Included_CPGPtlsContext_h

#include "pgpTLS.h"

_PGP_BEGIN

// Class CPGPtlsContext

class CPGPtlsContext
{
	NOT_COPYABLE(CPGPtlsContext);

public:
	CPGPtlsContext();
	CPGPtlsContext(PGPContextRef pgpContext);
	CPGPtlsContext(PGPtlsContextRef tlsContext);

	~CPGPtlsContext();

	operator PGPtlsContextRef() const {return mTLSContext;}
	CPGPtlsContext&	operator=(PGPtlsContextRef tlsContext);

	PGPtlsContextRef	Get() const {return mTLSContext;}

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

	void	Attach(PGPtlsContextRef tlsContext);
	void	Create(PGPContextRef pgpContext);
	void	Clear();

private:
	PGPBoolean			mWeCreated;
	PGPtlsContextRef	mTLSContext;
};


// Class CPGPtlsContext member functions

inline 
CPGPtlsContext::CPGPtlsContext() :
	mWeCreated(FALSE), mTLSContext(kInvalidPGPtlsContextRef)
{
}

inline 
CPGPtlsContext::CPGPtlsContext(PGPContextRef pgpContext) :
	mWeCreated(FALSE), mTLSContext(kInvalidPGPtlsContextRef)
{
	Create(pgpContext);
}

inline 
CPGPtlsContext::CPGPtlsContext(PGPtlsContextRef tlsContext) :
	mWeCreated(FALSE), mTLSContext(kInvalidPGPtlsContextRef)
{
	Attach(tlsContext);
}

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

inline 
CPGPtlsContext& 
CPGPtlsContext::operator=(PGPtlsContextRef tlsContext)
{
	Attach(tlsContext);
	return *this;
}

inline 
PGPBoolean 
CPGPtlsContext::IsAttached() const
{
	return PGPtlsContextRefIsValid(mTLSContext);
}

inline 
void 
CPGPtlsContext::Attach(PGPtlsContextRef tlsContext)
{
	if (mTLSContext == tlsContext)
		return;

	Clear();
	pgpAssert(PGPtlsContextRefIsValid(tlsContext));

	mTLSContext = tlsContext;
	mWeCreated = FALSE;
}

inline 
void 
CPGPtlsContext::Create(PGPContextRef pgpContext)
{
	pgpAssert(PGPContextRefIsValid(pgpContext));
	Clear();

	PGPError	pgpErr	= PGPNewTLSContext(pgpContext, &mTLSContext);
	THROW_IF_PGPERROR(pgpErr);

	mWeCreated = TRUE;
}

inline 
void 
CPGPtlsContext::Clear()
{
	if (WeCreated())
		PGPFreeTLSContext(mTLSContext);

	mTLSContext = kInvalidPGPtlsContextRef;
}

_PGP_END

#endif	// ] Included_CPGPtlsContext_h

⌨️ 快捷键说明

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