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

📄 pgpdialogs.cpp

📁 vc环境下的pgp源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
{
	kCommonAllowedPassphraseOptions,
	kPGPOptionType_ShowPassphraseQuality
};

	static PGPError
pgpConfirmationPassphraseDialog(
	PGPContextRef		context,
	PGPOptionListRef 	optionList,
	PGPUInt32			minPassphraseLength)
{
	PGPError	err;

	pgpAssert( pgpContextIsValid( context ) );
	pgpAssert( pgpOptionListIsValid( optionList ) );
	
	err = pgpGetOptionListError( optionList );
	if( IsntPGPError( err ) )
	{
		err = pgpCheckOptionsInSet( optionList,
					sConfirmationPassphraseOptionSet,
					elemsof( sConfirmationPassphraseOptionSet ) );
		if( IsntPGPError( err ) )
		{
			CPGPConfirmationPassphraseDialogOptions	options;
			
			err = options.GatherOptions( context, optionList );
			if( IsntPGPError( err ) )
			{
				if( options.mMinPassphraseLength < minPassphraseLength )
				{
					options.mMinPassphraseLength = minPassphraseLength;
				}
					
				err = pgpConfirmationPassphraseDialogPlatform( context, 
									&options );
			}
		}
	}
	
	return( err );
}

	PGPError
PGPConfirmationPassphraseDialog(
	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 = pgpConfirmationPassphraseDialog( context, optionList, 0 );
	
		PGPFreeOptionList( optionList );
	}
	else
	{
		va_start( args, firstOption );
		pgpFreeVarArgOptionList( firstOption, args );
		va_end( args );
		
		err = kPGPError_BadParams;
	}
	
	return( err );
}

	PGPError
PGPConventionalEncryptionPassphraseDialog(
	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 = pgpConfirmationPassphraseDialog( context, optionList, 0 );
	
		PGPFreeOptionList( optionList );
	}
	else
	{
		va_start( args, firstOption );
		pgpFreeVarArgOptionList( firstOption, args );
		va_end( args );
		
		err = kPGPError_BadParams;
	}
	
	return( err );
}

static const PGPOptionType sRecipientOptionSet[] =
{
	kCommonAllowedOptions,
	kPGPOptionType_DialogPrompt,
	kPGPOptionType_DialogOptions,
	kPGPOptionType_DefaultRecipients,
	kPGPOptionType_DisplayMarginalValidity,
	kPGPOptionType_IgnoreMarginalValidity,
	kPGPOptionType_RecipientGroups,
	kPGPOptionType_ARREnforcement,
	kPGPOptionType_KeyServerUpdateParams,
	kPGPOptionType_RecipientList
};

	static PGPError
pgpRecipientDialog(
	PGPContextRef		context,
	PGPKeySetRef		allKeys,
	PGPBoolean			alwaysDisplay,
	PGPOptionListRef	optionList,
	PGPKeySetRef 		*recipientKeys)
{
	PGPError			err;
	
	pgpAssert( pgpContextIsValid( context ) );
	pgpAssert( pgpOptionListIsValid( optionList ) );
	
	err = pgpGetOptionListError( optionList );
	if( IsntPGPError( err ) )
	{
		err = pgpCheckOptionsInSet( optionList, sRecipientOptionSet,
					elemsof( sRecipientOptionSet ) );
		if( IsntPGPError( err ) )
		{
			CPGPRecipientDialogOptions	options;
			
			err = options.GatherOptions( context, optionList );
			if( IsntPGPError( err ) )
			{
				PGPKeySetRef	workingKeySet;
				
				// Copy the set of known keys into an in-memory set so we can
				// make additions via key server searches
				
				err = PGPNewKeySet( context, &workingKeySet );
				if( IsntPGPError( err ) )
				{
					err = PGPAddKeys( allKeys, workingKeySet );
					if( IsntPGPError( err ) )
					{
						err = PGPCommitKeyRingChanges( workingKeySet );
						if( IsntPGPError( err ) )
						{
							options.mClientKeySet		= workingKeySet;
							options.mAlwaysDisplay		= alwaysDisplay;
							options.mRecipientKeysPtr	= recipientKeys;
							
							err = pgpRecipientDialogPlatform( context,
											&options );
													
							if( IsPGPError( err ) &&
								IsntNull( options.mNewKeys ) &&
								PGPKeySetRefIsValid( *options.mNewKeys ) )
							{
								PGPFreeKeySet( *options.mNewKeys );
								*options.mNewKeys = kInvalidPGPKeySetRef;
							}
							
							PGPFreeKeySet( workingKeySet );
						}
					}
				}
			}
		}
	}
	
	return( err );
}

	PGPError
PGPRecipientDialog(
	PGPContextRef		context,
	PGPKeySetRef		allKeys,
	PGPBoolean			alwaysDisplayDialog,
	PGPKeySetRef 		*recipientKeys,
	PGPOptionListRef	firstOption,
	...)
{
	PGPError	err;
	va_list		args;

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

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

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

static const PGPOptionType sRandomDataOptionSet[] =
{
	kCommonAllowedOptions,
	kPGPOptionType_DialogPrompt
};

	static PGPError
pgpCollectRandomDataDialog(
	PGPContextRef		context,
	PGPUInt32			neededEntropyBits,
	PGPOptionListRef	optionList)
{
	PGPError	err;
	
	pgpAssert( pgpContextIsValid( context ) );
	pgpAssert( pgpOptionListIsValid( optionList ) );
	
	err = pgpGetOptionListError( optionList );
	if( IsntPGPError( err ) )
	{
		err = pgpCheckOptionsInSet( optionList, sRandomDataOptionSet,
					elemsof( sRandomDataOptionSet ) );
		if( IsntPGPError( err ) )
		{
			CPGPRandomDataDialogOptions	options;
			
			err = options.GatherOptions( context, optionList );
			if( IsntPGPError( err ) )
			{
				options.mNeededEntropyBits = neededEntropyBits;
				
				err = pgpCollectRandomDataDialogPlatform( context, &options );
			}
		}
	}
	
	return( err );
}

	PGPError
PGPCollectRandomDataDialog(
	PGPContextRef 		context,
	PGPUInt32			neededEntropyBits,
	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 = pgpCollectRandomDataDialog( context, neededEntropyBits,
						optionList );
		
		PGPFreeOptionList( optionList );
	}
	else
	{
		va_start( args, firstOption );
		pgpFreeVarArgOptionList( firstOption, args );
		va_end( args );
		
		err = kPGPError_BadParams;
	} 
	
	return( err );
}

static const PGPOptionType sSearchKeyServerOptionSet[] =
{
	kCommonAllowedKeyServerOptions,
	kPGPOptionType_KeyServerSearchFilter,
	kPGPOptionType_KeyServerSearchKeyIDList,
	kPGPOptionType_KeyServerSearchKey,
	kPGPOptionType_KeyServerSearchKeySet
};

#if PGP_WIN32
	PGPError
pgpCheckNetworklibAvailability(void)
{
	// We're simply static linking for now.
	return( kPGPError_NoErr );
}

#endif

	static PGPError
pgpSearchKeyServerDialog(
	PGPContextRef 			context,
	const PGPKeyServerSpec 	serverList[],
	PGPUInt32				serverCount,
	PGPtlsContextRef		tlsContext,
	PGPBoolean				searchAllServers,
	PGPKeySetRef 			*foundKeys,
	PGPOptionListRef		optionList)
{
	PGPError	err;
	
	pgpAssert( pgpOptionListIsValid( optionList ) );
	
	err = pgpGetOptionListError( optionList );
	if( IsntPGPError( err ) )
	{
		err = pgpCheckNetworklibAvailability();
		if( IsntPGPError( err ) )
		{
			err = pgpCheckOptionsInSet( optionList, sSearchKeyServerOptionSet,
						elemsof( sSearchKeyServerOptionSet ) );
			if( IsntPGPError( err ) )
			{
				CPGPSearchKeyServerDialogOptions	options;
				
				err = options.GatherOptions( context, optionList );
				if( IsntPGPError( err ) )
				{
					options.mServerList			= serverList;
					options.mServerCount		= serverCount;
					options.mTLSContext			= tlsContext;
					options.mSearchAllServers	= searchAllServers;
					options.mNewKeys			= foundKeys;
					
					err = pgpSearchKeyServerDialogPlatform(context, &options);
				}
			}
		}
	}
	
	return( err );
}

	PGPError
PGPSearchKeyServerDialog(
	PGPContextRef 			context,
	PGPUInt32				serverCount,
	const PGPKeyServerSpec 	serverList[],
	PGPtlsContextRef		tlsContext,
	PGPBoolean				searchAllServers,
	PGPKeySetRef 			*foundKeys,
	PGPOptionListRef 		firstOption,
	... )
{
	PGPError	err;
	va_list		args;

	pgpAssert( pgpContextIsValid( context ) );
	pgpAssert( IsntNull( serverList ) );
	pgpAssert( serverCount >= 1 );
	pgpAssert( IsntNull( foundKeys ) );
	
	if( IsntNull( foundKeys ) )
		*foundKeys = kInvalidPGPKeySetRef;
		
	if( pgpContextIsValid( context ) &&
		IsntNull( serverList ) &&
		serverCount >= 1 &&
		IsntNull( foundKeys ) )
	{
		PGPOptionListRef	optionList;
		
		va_start( args, firstOption );
		optionList = pgpBuildOptionListArgs( context, FALSE, firstOption,
								args );
		va_end( args );

		err = pgpSearchKeyServerDialog( context, serverList, serverCount,
						tlsContext, searchAllServers, foundKeys, optionList );
		
		PGPFreeOptionList( optionList );
	}
	else
	{
		va_start( args, firstOption );
		pgpFreeVarArgOptionList( firstOption, args );
		va_end( args );
		
		err = kPGPError_BadParams;
	} 
	
	return( err );
}

	PGPKeyRef
GetKeyForPassphrase(
	PGPKeySetRef	keySet,
	const char *	passphrase,
	PGPBoolean		signing)
{
	PGPKeyRef		theKey	= kInvalidPGPKeyRef;
	PGPError		err;
	PGPKeyListRef	keyListRef;
	PGPBoolean		foundValidKey	= FALSE;
	
	err = PGPOrderKeySet( keySet, kPGPAnyOrdering, &keyListRef );
	if( IsntPGPError( err ) )
	{
		PGPKeyIterRef	keyIterator;
	
		err = PGPNewKeyIter( keyListRef, &keyIterator );
		if( IsntPGPError( err ) )
		{
			err = PGPKeyIterNext( keyIterator, &theKey );
			while( IsntPGPError( err ) )
			{
				PGPBoolean	tryKey = FALSE;
				
				if( signing )
				{
					PGPBoolean	canSign;
					
					if( IsntPGPError( PGPGetKeyBoolean( theKey,
							kPGPKeyPropCanSign, &canSign ) ) && canSign )
					{
						tryKey = TRUE;
					}
				}
				else
				{
					PGPBoolean	canDecrypt;
					
					if( IsntPGPError( PGPGetKeyBoolean( theKey,
							kPGPKeyPropCanDecrypt, &canDecrypt ) ) &&
								canDecrypt )
					{
						tryKey = TRUE;
					}
				}
				
				if ( tryKey )
				{
					PGPContextRef	context	= PGPGetKeyContext( theKey );
					
					if ( PGPPassphraseIsValid( theKey,
							PGPOPassphrase( context, passphrase),
							PGPOLastOption( context ) ) )
					{
						foundValidKey	= TRUE;
						break;
					}
				}
				
				err = PGPKeyIterNext( keyIterator, &theKey );
			}
			
			PGPFreeKeyIter( keyIterator );
		}
		
		PGPFreeKeyList( keyListRef );
	}

	return( foundValidKey ? theKey : NULL );
}

static const PGPOptionType sSendToKeyServerOptionSet[] =
{
	kCommonAllowedKeyServerOptions
};

	static PGPError
pgpSendToKeyServerDialog(
	PGPContextRef 			context,
	const PGPKeyServerSpec 	*server,
	PGPtlsContextRef		tlsContext,
	PGPKeySetRef 			keysToSend,
	PGPKeySetRef 			*failedKeys,
	PGPOptionListRef		optionList)
{
	PGPError	err;
	
	pgpAssert( pgpOptionListIsValid( optionList ) );
	
	err = pgpGetOptionListError( optionList );
	if( IsntPGPError( err ) )
	{
		err = pgpCheckNetworklibAvailability();
		if( IsntPGPError( err ) )
		{
			err = pgpCheckOptionsInSet( optionList, sSendToKeyServerOptionSet,
						elemsof( sSendToKeyServerOptionSet ) );
			if( IsntPGPError( err ) )
			{
				CPGPSendToKeyServerDialogOptions	options;
				
				err = options.GatherOptions( context, optionList );
				if( IsntPGPError( err ) )
				{
					options.mServerList		= server;
					options.mServerCount	= 1;
					options.mTLSContext		= tlsContext;
					options.mKeysToSend		= keysToSend;
					options.mFailedKeys		= failedKeys;
					
					err = pgpSendToKeyServerDialogPlatform(context, &options);
				}
			}
		}
	}
	
	return( err );
}

	PGPError
PGPSendToKeyServerDialog(
	PGPContextRef 			context,
	const PGPKeyServerSpec 	*server,
	PGPtlsContextRef		tlsContext,
	PGPKeySetRef 			keysToSend,
	PGPKeySetRef 			*failedKeys,
	PGPOptionListRef 		firstOption,
	... )
{
	PGPError	err;
	va_list		args;

	pgpAssert( pgpContextIsValid( context ) );
	pgpAssert( IsntNull( server ) );
	pgpAssert( PGPKeySetRefIsValid( keysToSend ) );
	pgpAssert( IsntNull( failedKeys ) );
	
	if( IsntNull( failedKeys ) )
		*failedKeys = kInvalidPGPKeySetRef;
		
	if( pgpContextIsValid( context ) &&
		IsntNull( server ) &&
		PGPKeySetRefIsValid( keysToSend ) &&
		IsntNull( failedKeys ) )
	{
		PGPOptionListRef	optionList;
		
		va_start( args, firstOption );
		optionList = pgpBuildOptionListArgs( context, FALSE, firstOption,
								args );
		va_end( args );

		err = pgpSendToKeyServerDialog( context, server, tlsContext,
						keysToSend, failedKeys, optionList );
		
		PGPFreeOptionList( optionList );
	}
	else
	{
		va_start( args, firstOption );
		pgpFreeVarArgOptionList( firstOption, args );
		va_end( args );
		
		err = kPGPError_BadParams;
	} 
	
	return( err );
}

⌨️ 快捷键说明

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