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

📄 cpgpdiskuser.h

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

        $Id: CPGPdiskUser.h,v 1.5 2002/08/06 20:09:36 dallen Exp $
____________________________________________________________________________*/

#ifndef Included_CPGPdiskUser_h	// [
#define Included_CPGPdiskUser_h

#include "CList.h"

#include "Crypto.h"
#include "CPGPKey.h"

_PGP_BEGIN

// Types

template <typename T> class CSecureArray;

class CPGPKey;
class CPGPKeyID;
class CString;

class CCipherContext;
class CPGPdiskContext;
class CSecureArray;

struct OnDiskUserInfo;
struct OnDiskUserWithPub;
struct OnDiskUserWithSym;


// Class CPGPdiskUser

class CPGPdiskUser : public CListableObject<CPGPdiskUser>
{
public:
	CPGPdiskUser(const CPGPdiskContext *pContext);
	CPGPdiskUser(const CPGPdiskUser& user);
	~CPGPdiskUser();

	CPGPdiskUser&	operator=(const CPGPdiskUser& user);

	PGPBoolean		operator==(const CPGPdiskUser& user) const
	{
		return IsEqual(user);
	}

	PGPBoolean		operator!=(const CPGPdiskUser& user) const
	{
		return !IsEqual(user);
	}

	const CPGPdiskContext *	Context() const;

	PGPBoolean	IsEqual(const CPGPdiskUser& user) const;

	PGPBoolean	IsAssigned() const;
	PGPBoolean	HasPublicKey() const;
	PGPBoolean	HasSymmetricKey() const;
	PGPBoolean	IsReadOnly() const;
	PGPBoolean	IsLocked() const;
	PGPBoolean	IsAdminUser() const;
	PGPBoolean	IsDisabled() const;
	PGPBoolean	IsCipheringEnabled() const;

	PGPBoolean	CanSetReadOnly() const;
	PGPBoolean	CanSetLocked() const;
	PGPBoolean	CanSetUserName() const;

	void		GetUserName(CString& userName) const;
	PGPUInt32	GetSizeForExport() const;
	void		GetPGPKeyID(CPGPKeyID& keyID) const;
	void		GetPGPSubKeyID(CPGPKeyID& subKeyID) const;

	void		GetCipherContext(CCipherContext& context) const;

	void	SetIsReadOnly(PGPBoolean isReadOnly);
	void	SetIsLocked(PGPBoolean isLocked);
	void	SetIsAdminUser(PGPBoolean isAdminUser);
	void	SetIsDisabled(PGPBoolean isDisabled);
	void	SetUserName(const char *userName);

	void	EnableCiphering(const char *passphrase, int passkeylen,
		PGPdiskEncryptionAlgorithm algorithm, 
		const Crypto::PassphraseSalt& salt);
	void	DisableCiphering();

	void	ChangeCipher(const CCipherContext& newCipher, 
		const char *passphrase = NULL);
	void	ChangePassphrase(const char *newPassphrase);

	void	Create(const CCipherContext& cipher, const CPGPKey& pubKey, 
		PGPBoolean readOnly = FALSE, PGPBoolean locked = FALSE);
	void	Create(const CCipherContext& cipher, const char *userName, 
		const char *passphrase, PGPBoolean readOnly = FALSE);

	void	Import(const void *buf, PGPUInt32 size);
	void	Export(void *buf, PGPUInt32 availSize) const;

	void	ImportRawSymmetricKey(const Crypto::PassphraseKeyInfo& keyInfo, 
		const char *userName, PGPBoolean readOnly = FALSE);

	void	ImportRawPublicKey(const PGPKeyID& keyID, 
		const PGPKeyID& subKeyID, const PGPByte *pEncryptedKey, 
		PGPSize lengthEncKey, const Crypto::CheckBytes& checkBytes, 
		PGPBoolean readOnly = FALSE, PGPBoolean locked = FALSE);

	void	ImportRawPublicKey(const PGPByte *pKeyID, PGPSize keyIDLength, 
		const PGPByte *pEncryptedKey, PGPSize lengthEncKey, 
		const Crypto::CheckBytes& checkBytes, 
		PGPPublicKeyAlgorithm pubAlgorithm, PGPBoolean readOnly = FALSE, 
		PGPBoolean locked = FALSE);

	void	Assign(const CPGPdiskUser& user);
	void	Clear();

private:
	const CPGPdiskContext	*mPContext;

	CArray<PGPUInt8>	mUserBytes;
	PGPBoolean			mIsAssigned;

	CCipherContext	*mPCipher;
	PGPBoolean		mCipheringEnabled;

	mutable CPGPKeyID	mKeyID;
	mutable CPGPKeyID	mSubKeyID;
	mutable CPGPKey		mPGPKey;
	mutable CPGPKey		mPGPSubKey;
	mutable PGPBoolean	mPGPKeyPresent;

	OnDiskUserInfo *	GetAsUserInfo() const
	{
		return reinterpret_cast<OnDiskUserInfo *>(mUserBytes.Get());
	}

	OnDiskUserWithPub *	GetAsUserWithPub() const
	{
		return reinterpret_cast<OnDiskUserWithPub *>(mUserBytes.Get());
	}

	OnDiskUserWithSym *	GetAsUserWithSym() const
	{
		return reinterpret_cast<OnDiskUserWithSym *>(mUserBytes.Get());
	}

	void	Init();
	void	ImportPublicKey() const;

	void	VerifyPubKeyCheckBytes(const void *compareData,
		const void *compareMainData, 
		const Crypto::CheckBytes& checkBytes, 
		const CCipherContext& cipher) const;

	void	GeneratePubKeyCheckBytes(const void *compareData, 
		const CCipherContext& cipher, Crypto::CheckBytes& checkBytes) const;

	void	DecryptUsingPublicKey(const CPGPKey& pubMainKey, const CPGPKey& pubKey, 
		const char *passphrase, int passkeylen, const PGPByte *pEncryptedKey, 
		PGPSize encryptedDataSize, const Crypto::PassphraseSalt& salt, 
		const Crypto::CheckBytes& checkBytes, CCipherContext& cipher) const;

	void	EncryptUsingPublicKey(const CPGPKey& pubKey, 
		const CCipherContext& cipher, CSecureArray<PGPByte>& encryptedKey, 
		PGPUInt32& encryptedKeySize, Crypto::CheckBytes& checkBytes) const;
};

_PGP_END

#endif	// ] Included_CPGPdiskUser_h

⌨️ 快捷键说明

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