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

📄 pgpdialogs.cpp

📁 vc环境下的pgp源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
		optionList = pgpBuildOptionListArgs(context, FALSE, firstOption, args);
		va_end( args );
	
		err = pgpPassphraseDialog( context, optionList );
	
		PGPFreeOptionList( optionList );
	}
	else
	{
		va_start( args, firstOption );
		pgpFreeVarArgOptionList( firstOption, args );
		va_end( args );
		
		err = kPGPError_BadParams;
	}
	
	return( err );
}

	PGPError
PGPConventionalDecryptionPassphraseDialog(
	PGPContextRef		context,
	PGPOptionListRef	firstOption,
	...)
{
	PGPError	err = kPGPError_NoErr;
	va_list		args;

	pgpAssert( pgpContextIsValid( context ) );
	
	if( pgpContextIsValid( context ) )
	{
		PGPOptionListRef	optionList;
		
		va_start( args, firstOption );
		optionList = pgpBuildOptionListArgs(context, FALSE, firstOption, args);
		va_end( args );
	
		err = pgpPassphraseDialog( context, optionList );
	
		PGPFreeOptionList( optionList );
	}
	else
	{
		va_start( args, firstOption );
		pgpFreeVarArgOptionList( firstOption, args );
		va_end( args );
		
		err = kPGPError_BadParams;
	}
	
	return( err );
}

static const PGPOptionType sOptionsOptionSet[] =
{
	kCommonAllowedOptions,
	kPGPOptionType_DialogPrompt,
	kPGPOptionType_Checkbox,
	kPGPOptionType_PopupList
};

	static PGPError
pgpOptionsDialog(
	PGPContextRef		context,
	PGPOptionListRef	optionList)
{
	PGPError			err;
	
	pgpAssert( pgpContextIsValid( context ) );
	pgpAssert( pgpOptionListIsValid( optionList ) );
	
	err = pgpGetOptionListError( optionList );
	if( IsntPGPError( err ) )
	{
		err = pgpCheckOptionsInSet( optionList, sOptionsOptionSet,
					elemsof( sOptionsOptionSet ) );
		if( IsntPGPError( err ) )
		{
			CPGPOptionsDialogOptions	options;
			
			err = options.GatherOptions( context, optionList );
			if( IsntPGPError( err ) )
			{
				err = pgpOptionsDialogPlatform( context, &options );
			}
		}
	}
	
	return( err );
}

	PGPError
PGPOptionsDialog(
	PGPContextRef		context,
	PGPOptionListRef	firstOption,
	...)
{
	PGPError	err;
	va_list		args;

	pgpAssert( pgpContextIsValid( context ) );
	
	if( pgpContextIsValid( context ) )
	{
		PGPOptionListRef	optionList;
		
		va_start( args, firstOption );
		optionList = pgpBuildOptionListArgs(context, FALSE, firstOption, args);
		va_end( args );

		err = pgpOptionsDialog( context, optionList );
		
		PGPFreeOptionList( optionList );
	}
	else
	{
		va_start( args, firstOption );
		pgpFreeVarArgOptionList( firstOption, args );
		va_end( args );
		
		err = kPGPError_BadParams;
	} 
	
	return( err );
}

static const PGPOptionType sKeyOptionSet[] =
{
	kCommonAllowedPassphraseOptions,
	kPGPOptionType_VerifyPassphrase
};

	static PGPError
pgpKeyPassphraseDialog(
	PGPContextRef		context,
	PGPKeyRef			theKey,
	PGPOptionListRef	optionList)
{
	PGPError			err;
	
	pgpAssert( pgpContextIsValid( context ) );
	pgpAssert( pgpOptionListIsValid( optionList ) );
	
	err = pgpGetOptionListError( optionList );
	if( IsntPGPError( err ) )
	{
		err = pgpCheckOptionsInSet( optionList, sKeyOptionSet,
					elemsof( sKeyOptionSet ) );
		if( IsntPGPError( err ) )
		{
			CPGPKeyPassphraseDialogOptions	options;
			
			err = options.GatherOptions( context, optionList );
			if( IsntPGPError( err ) )
			{
				options.mDefaultKey	= theKey;	/* Overloading mDefaultKey */
				
				err = pgpKeyPassphraseDialogPlatform( context, &options );
			}
		}
	}
	
	return( err );
}

	PGPError
PGPKeyPassphraseDialog(
	PGPContextRef		context,
	PGPKeyRef			theKey,
	PGPOptionListRef	firstOption,
	...)
{
	PGPError	err;
	va_list		args;

	pgpAssert( pgpContextIsValid( context ) );
	pgpAssert( PGPKeyRefIsValid( theKey ) );

	if( pgpContextIsValid( context ) &&
		PGPKeyRefIsValid( theKey ) )
	{
		PGPOptionListRef	optionList;
		
		va_start( args, firstOption );
		optionList = pgpBuildOptionListArgs(context, FALSE, firstOption, args);
		va_end( args );

		err = pgpKeyPassphraseDialog( context, theKey, optionList );
		
		PGPFreeOptionList( optionList );
	}
	else
	{
		va_start( args, firstOption );
		pgpFreeVarArgOptionList( firstOption, args );
		va_end( args );
		
		err = kPGPError_BadParams;
	}
	
	return( err );
}

	static PGPError
FindValidSecretKey(
	PGPKeySetRef 	keySet,
	Boolean			signing,
	PGPKeyRef		preferredKey,
	PGPKeyRef		*secretKeyPtr)
{
	PGPError		err;
	PGPKeyListRef	keyList;
	PGPKeyPropName	keyProperty;
	PGPKeyRef		splitKeyRef 		= kInvalidPGPKeyRef;
	PGPKeyRef		secretKeyRef 		= kInvalidPGPKeyRef;
	PGPKeyRef		defaultKey			= kInvalidPGPKeyRef;
	PGPBoolean		foundDefaultKey		= FALSE;
	PGPBoolean		foundPreferredKey	= FALSE;
	PGPBoolean		preferredIsSplitKey	= FALSE;
	PGPBoolean		defaultIsSplitKey	= FALSE;
	
	*secretKeyPtr = kInvalidPGPKeyRef;
	
	/* Note that defaultKey may be a split key */
	(void) PGPGetDefaultPrivateKey( keySet, &defaultKey );
	if( ! PGPKeyRefIsValid( preferredKey ) )
		preferredKey = defaultKey;
		
	if( signing )
	{
		keyProperty = kPGPKeyPropCanSign;
	}
	else
	{
		keyProperty = kPGPKeyPropCanDecrypt;
	}
	
	err = PGPOrderKeySet( keySet, kPGPAnyOrdering, &keyList );
	if( IsntPGPError( err ) )
	{
		PGPKeyIterRef	keyIterator;
		
		err = PGPNewKeyIter( keyList, &keyIterator );
		if( IsntPGPError( err ) )
		{
			PGPKeyRef	theKey;
			
			err = PGPKeyIterNext( keyIterator, &theKey );
			while( IsntPGPError( err ) )
			{
				PGPBoolean	canOperate;
				
				err = PGPGetKeyBoolean( theKey, keyProperty, &canOperate );
				if( IsntPGPError( err ) )
				{
					if( canOperate )
					{
						PGPBoolean	isSplitKey = FALSE;
						
						(void) PGPGetKeyBoolean( theKey,
									kPGPKeyPropIsSecretShared, &isSplitKey );

						if( theKey == defaultKey )
						{
							foundDefaultKey = TRUE;
							if( isSplitKey )
								defaultIsSplitKey = TRUE;
						}
						
						if( theKey == preferredKey )
						{
							foundPreferredKey = TRUE;
							if( isSplitKey )
								preferredIsSplitKey = TRUE;
						}
						
						if( isSplitKey )
						{
							if( ! PGPKeyRefIsValid( splitKeyRef ) )
								splitKeyRef = theKey;
						}
						else
						{
							if( ! PGPKeyRefIsValid( secretKeyRef ) )
								secretKeyRef = theKey;

							/*
							** If we've found the preferred key and we have
							** at least one non-split key, we can stop
							*/
							
							if( foundPreferredKey )
								break;
						}
					}
					
					err = PGPKeyIterNext( keyIterator, &theKey );
				}
			}
			
			if( err == kPGPError_EndOfIteration )
				err = kPGPError_NoErr;
				
			PGPFreeKeyIter( keyIterator );
		}
		
		PGPFreeKeyList( keyList );
	}

	if( IsntPGPError( err ) )
	{
		if( PGPKeyRefIsValid( secretKeyRef ) )
		{
			/*
			** Do not allow a split key as the best secret key
			** if we're decrypting and at least one other secret
			** key is available.
			*/
			
			if( ! signing )
			{
				if( preferredIsSplitKey )
					foundPreferredKey = FALSE;

				if( defaultIsSplitKey )
					foundDefaultKey = FALSE;
			}
			
			if( foundPreferredKey )
			{
				*secretKeyPtr = preferredKey;
			}
			else if( foundDefaultKey )
			{
				*secretKeyPtr = defaultKey;
			}
			else
			{	
				*secretKeyPtr = secretKeyRef;
			}
		}
		else if( PGPKeyRefIsValid( splitKeyRef ) )
		{
			if( foundPreferredKey )
			{
				*secretKeyPtr = preferredKey;
			}
			else if( foundDefaultKey )
			{
				*secretKeyPtr = defaultKey;
			}
			else
			{	
				*secretKeyPtr = splitKeyRef;
			}
			
			if( signing )
			{
				err = kPGPError_KeyUnusableForSignature;
			}
			else
			{
				err = kPGPError_KeyUnusableForDecryption;
			}
		}
		else
		{
			err = kPGPError_SecretKeyNotFound;
		}
	}
	
	return( err );
}

static const PGPOptionType sSigningOptionSet[] =
{
	kCommonAllowedPassphraseOptions,
	kPGPOptionType_DefaultKey,
	kPGPOptionType_VerifyPassphrase,
	kPGPOptionType_FindMatchingKey
};

	static PGPError
pgpSigningPassphraseDialog(
	PGPContextRef		context,
	PGPKeySetRef		allKeys,
	PGPOptionListRef	optionList,
	PGPKeyRef			*signingKey)
{
	PGPError	err;
	
	pgpAssert( pgpContextIsValid( context ) );
	pgpAssert( pgpOptionListIsValid( optionList ) );
	
	err = pgpGetOptionListError( optionList );
	if( IsntPGPError( err ) )
	{
		err = pgpCheckOptionsInSet( optionList, sSigningOptionSet,
					elemsof( sSigningOptionSet ) );
		if( IsntPGPError( err ) )
		{
			CPGPSigningPassphraseDialogOptions	options;
			
			err = options.GatherOptions( context, optionList );
			if( IsntPGPError( err ) )
			{
				err = FindValidSecretKey( allKeys, TRUE, options.mDefaultKey,
								&options.mDefaultKey );
				if( IsntPGPError( err ) )
				{
					options.mKeySet				= allKeys;
					options.mPassphraseKeyPtr	= signingKey;
					
					err = pgpSigningPassphraseDialogPlatform( context,
									&options );
				}
				else if( err == kPGPError_KeyUnusableForSignature )
				{
					/* Special case. We return a split key, if found */
					*signingKey = options.mDefaultKey;
				}
			}
		}
	}
	
	return( err );
}

	PGPError
PGPSigningPassphraseDialog(
	PGPContextRef		context,
	PGPKeySetRef		allKeys,
	PGPKeyRef			*signingKey,
	PGPOptionListRef	firstOption,
	...)
{
	PGPError	err;
	va_list		args;

	pgpAssert( pgpContextIsValid( context ) );
	pgpAssert( PGPKeySetRefIsValid( allKeys ) );

	if( IsntNull( signingKey ) )
		*signingKey = kInvalidPGPKeyRef;

	if( pgpContextIsValid( context ) &&
		PGPKeySetRefIsValid( allKeys ) &&
		IsntNull( signingKey ) )
	{
		PGPOptionListRef	optionList;
		
		va_start( args, firstOption );
		optionList = pgpBuildOptionListArgs(context, FALSE, firstOption, args);
		va_end( args );

		err = pgpSigningPassphraseDialog( context, allKeys,
						optionList, signingKey );
		
		PGPFreeOptionList( optionList );
	}
	else
	{
		va_start( args, firstOption );
		pgpFreeVarArgOptionList( firstOption, args );
		va_end( args );
		
		err = kPGPError_BadParams;
	}
	
	return( err );
}

static const PGPOptionType sDecryptionOptionSet[] =
{
	kCommonAllowedPassphraseOptions,
	kPGPOptionType_DefaultKey,
	kPGPOptionType_VerifyPassphrase,
	kPGPOptionType_FindMatchingKey,
	kPGPOptionType_KeyServerUpdateParams
};

	static PGPError
pgpDecryptionPassphraseDialog(
	PGPContextRef		context,
	PGPKeySetRef		recipientKeys,
	const PGPKeyID		keyIDList[],
	PGPUInt32			keyIDCount,
	PGPOptionListRef	optionList,
	PGPKeyRef			*decryptionKey)
{
	PGPError	err;
	
	pgpAssert( pgpContextIsValid( context ) );
	pgpAssert( pgpOptionListIsValid( optionList ) );
	
	err = pgpGetOptionListError( optionList );
	if( IsntPGPError( err ) )
	{
		err = pgpCheckOptionsInSet( optionList, sDecryptionOptionSet,
					elemsof( sDecryptionOptionSet ) );
		if( IsntPGPError( err ) )
		{
			CPGPDecryptionPassphraseDialogOptions	options;

			err = options.GatherOptions( context, optionList );
			if( IsntPGPError( err ) )
			{
				err = FindValidSecretKey( recipientKeys, FALSE,
							options.mDefaultKey, &options.mDefaultKey );
				
				/* Proceed with dialog even when no keys are found */
				if( err == kPGPError_SecretKeyNotFound )
					err = kPGPError_NoErr;
					
				if( IsntPGPError( err ) )
				{
					options.mKeySet				= recipientKeys;
					options.mPassphraseKeyPtr	= decryptionKey;
					options.mKeyIDList			= keyIDList;
					options.mKeyIDCount			= keyIDCount;
					
					err = options.GatherMissingKeys();
					if( IsntPGPError( err ) )
					{
						err = pgpDecryptionPassphraseDialogPlatform( context,
										&options );
					}
					
					if( IsPGPError( err ) &&
						IsntNull( options.mNewKeys ) &&
						PGPKeySetRefIsValid( *options.mNewKeys ) )
					{
						PGPFreeKeySet( *options.mNewKeys );
						*options.mNewKeys = kInvalidPGPKeySetRef;
					}
				}
				else if( err == kPGPError_KeyUnusableForDecryption )
				{
					/* Special case. We return a split key, if found */
					*decryptionKey = options.mDefaultKey;
				}
			}
		}
	}
	
	return( err );
}

	PGPError
PGPDecryptionPassphraseDialog(
	PGPContextRef		context,
	PGPKeySetRef		recipientKeys,
	PGPUInt32			keyIDCount,
	const PGPKeyID		keyIDList[],
	PGPKeyRef			*decryptionKey,
	PGPOptionListRef	firstOption,
	...)
{
	PGPError	err = kPGPError_NoErr;
	va_list		args;
	
	pgpAssert( pgpContextIsValid( context ) );
	pgpAssert( PGPKeySetRefIsValid( recipientKeys ) );
	
	if( IsntNull( decryptionKey ) )
		*decryptionKey = kInvalidPGPKeyRef;

	if( pgpContextIsValid( context ) &&
		PGPKeySetRefIsValid( recipientKeys ) &&
		IsntNull( decryptionKey ) )
	{
		PGPOptionListRef	optionList;
		
		va_start( args, firstOption );
		optionList = pgpBuildOptionListArgs(context, FALSE, firstOption, args);
		va_end( args );

		err = pgpDecryptionPassphraseDialog( context, recipientKeys, keyIDList,
						keyIDCount, optionList, decryptionKey );
		
		PGPFreeOptionList( optionList );
	}
	else
	{
		va_start( args, firstOption );
		pgpFreeVarArgOptionList( firstOption, args );
		va_end( args );
		
		err = kPGPError_BadParams;
	}
	
	return( err );
}


static const PGPOptionType sConfirmationPassphraseOptionSet[] =

⌨️ 快捷键说明

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