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

📄 csecureobject.h

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

        $Id: CSecureObject.h,v 1.4 2002/08/06 20:10:37 dallen Exp $
____________________________________________________________________________*/

#ifndef Included_CSecureObject_h	// [
#define Included_CSecureObject_h

#include "pgpClassesConfig.h"

#include "CArray.h"
#include "CErrorState.h"

_PGP_BEGIN

// Class CSecureObject

template <typename T> class CSecureObject SMART_ERROR_INHERIT
{
	NOT_COPYABLE(CSecureObject)

public:
	CSecureObject();
	~CSecureObject();

	operator T *() {return mObject;}
	operator const T *() const {return mObject;}

	T *			operator->() {return mObject;}
	const T *	operator->() const {return mObject;}

	T&			operator*() {return *mObject;}
	const T&	operator*() const {return *mObject;}

	T *	Get() {return mObject;}

	void	FlipBytes();
	void	Wipe() {mBuffer.Wipe();}

private:
	CSecureArray<PGPByte>	mBuffer;	// buffer for object
	T						*mObject;	// pointer to constructed object
};


// Class CSecureObject member functions

template <typename T> 
CSecureObject<T>::CSecureObject() : mBuffer(sizeof(T)), mObject(NULL)
{
	// Use placement new to construct the object on the secure memory.

#if !PGP_EXCEPTIONS
	Status() = mBuffer.Status();

	if (Status().IsntError())
#endif	// !PGP_EXCEPTIONS
		mObject = new(mBuffer.Get()) T;
}

template <typename T> 
CSecureObject<T>::~CSecureObject()
{
	if (IsntNull(mObject))
	{
		// Destuct the object on the secure memory.
		mObject->~T();
		mObject = NULL;
	}
}

template <typename T> 
void 
CSecureObject<T>::FlipBytes()
{
	for (PGPUInt32 i = 0; i < mBuffer.Size(); i++)
	{
		mBuffer[i] = ~mBuffer[i];
	}
}

_PGP_END

#endif	// ] Included_CSecureObject_h

⌨️ 快捷键说明

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