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

📄 pgpclientencode.c

📁 vc环境下的pgp源码
💻 C
📖 第 1 页 / 共 4 页
字号:
	if( IsntNull( descriptor ) )
	{
		PGPOptionValue	value;
		
		descriptor->buffer 				= buffer;
		descriptor->bufferSize 			= bufferSize;
		descriptor->outputDataLength	= outputDataLength;
		
		value.asPtr = descriptor;
		
		optionList = pgpCreateStandardValueOptionList( context, 
							kPGPOptionType_OutputBuffer,
							&value, sizeof( *descriptor ),
							AllocatedOptionHandlerProc );
	}
	else
	{
		optionList = kPGPOutOfMemoryOptionListRef;
	}
	
	return( optionList );
}

#if PGP_MACINTOSH	/* [ */

	PGPOptionListRef
PGPOOutputFileFSSpec(
	PGPContextRef 	context,
	const FSSpec	*fileSpec)
{
	PGPOptionListRef	optionList;
	PGPFileSpecRef		fileRef;
	
	pgpValidateOptionContext( context );
	pgpValidateOptionParam( FSSpecIsValid( fileSpec ) );
	
	if( IsntPGPError( PGPNewFileSpecFromFSSpec( context,
			fileSpec, &fileRef ) ) )
	{
		optionList = pgpCreateFileRefOptionList( context,
			kPGPOptionType_OutputFileRef, fileRef );
			
		PGPFreeFileSpec( fileRef );
	}
	else
	{
		optionList = kPGPOutOfMemoryOptionListRef;
	}
	
	return( optionList );
}

#endif	/* ] */

	PGPOptionListRef
PGPOAllocatedOutputBuffer(
	PGPContextRef	context,
	void			**buffer,
	PGPSize			maximumBufferSize,
	PGPSize			*actualBufferSize)
{
	PGPOptionListRef				optionList;
	PGPOAllocatedOutputBufferDesc	*descriptor;
	
	if ( IsntNull( buffer ) )
		*buffer	= NULL;
	if ( IsntNull( actualBufferSize ) )
		*actualBufferSize	= 0;
	pgpValidateOptionParam( IsntNull( buffer ) );
	pgpValidateOptionParam( IsntNull( actualBufferSize ) );
	pgpValidateOptionParam( maximumBufferSize > 0 );
	pgpValidateOptionContext( context );
	
	descriptor = (PGPOAllocatedOutputBufferDesc *)
			pgpContextMemAlloc( context,
				sizeof(*descriptor), kPGPMemoryMgrFlags_Clear);
	if( IsntNull( descriptor ) )
	{
		PGPOptionValue	value;
		
		descriptor->buffer 				= buffer;
		descriptor->maximumBufferSize 	= maximumBufferSize;
		descriptor->actualBufferSize	= actualBufferSize;
		
		value.asPtr = descriptor;
		
		optionList = pgpCreateStandardValueOptionList( context,  
							kPGPOptionType_OutputAllocatedBuffer,
							&value, sizeof( *descriptor ),
							AllocatedOptionHandlerProc );
	}
	else
	{
		optionList = kPGPOutOfMemoryOptionListRef;
	}
	
	return( optionList );
}

/* Not yet supported */
	PGPOptionListRef
PGPOAppendOutput(
	PGPContextRef	context,
	PGPBoolean		appendOutput
	)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );

	value.asUInt = (PGPUInt32)appendOutput;
	
	optionList = pgpCreateStandardValueOptionList( context,  
							kPGPOptionType_AppendOutput,
							&value, sizeof( PGPUInt32 ), NULL);

	return( optionList );
}

	PGPOptionListRef
PGPODiscardOutput(
	PGPContextRef	context,
	PGPBoolean		discardOutput
	)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );

	value.asUInt = (PGPUInt32)discardOutput;
	
	optionList = pgpCreateStandardValueOptionList( context,  
							kPGPOptionType_DiscardOutput,
							&value, sizeof( PGPUInt32 ), NULL);

	return( optionList );
}


#if 0

	PGPOptionListRef
PGPOAskUserForOutput(
	PGPContextRef	context,
	PGPBoolean		askUserForOutput
	)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );

	value.asUInt = (PGPUInt32)askUserForOutput;
	
	optionList = pgpCreateStandardValueOptionList( context,  
							kPGPOptionType_AskUserForOutput,
							&value, sizeof( PGPUInt32 ), NULL);

	return( optionList );
}
#endif



	PGPOptionListRef
PGPOEncryptToKey(
	PGPContextRef	context,
	PGPKeyRef		keyRef
	)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );
	pgpValidateOptionParam( pgpKeyIsValid( keyRef ) );
	
	value.asKeyRef = keyRef;

	pgpIncKeyRefCount( keyRef );

	optionList = pgpCreateStandardValueOptionList( context,  
							kPGPOptionType_EncryptToKey,
							&value, sizeof( keyRef ),
							SpecialOptionHandlerProc );
	
#if PGP_ENCRYPT_DISABLE
	pgpSetOptionListError( optionList, kPGPError_FeatureNotAvailable );
#endif

	return( optionList );
}

	PGPOptionListRef
PGPOEncryptToKeySet(
	PGPContextRef	context,
	PGPKeySetRef	keySetRef
	)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );
	pgpValidateOptionParam( pgpKeySetIsValid( keySetRef ) );
	
	value.asKeySetRef = keySetRef;

	PGPIncKeySetRefCount( keySetRef );

	optionList = pgpCreateStandardValueOptionList( context,  
							kPGPOptionType_EncryptToKeySet,
							&value, sizeof( keySetRef ),
							SpecialOptionHandlerProc );
	
#if PGP_ENCRYPT_DISABLE
	pgpSetOptionListError( optionList, kPGPError_FeatureNotAvailable );
#endif

	return( optionList );
}

	PGPOptionListRef
PGPOEncryptToUserID(
	PGPContextRef	context,
	PGPUserIDRef	userIDRef
	)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );
	pgpValidateOptionParam( PGPUserIDRefIsValid( userIDRef ) );
	
	value.asUserIDRef = userIDRef;

	pgpIncUserIDRefCount( userIDRef );

	optionList = pgpCreateStandardValueOptionList( context, 
							kPGPOptionType_EncryptToUserID,
							&value, sizeof( userIDRef ),
							SpecialOptionHandlerProc );
	
#if PGP_ENCRYPT_DISABLE
	pgpSetOptionListError( optionList, kPGPError_FeatureNotAvailable );
#endif

	return( optionList );
}

	PGPOptionListRef
PGPOSignWithKey(
	PGPContextRef		context,
	PGPKeyRef			keyRef,
	PGPOptionListRef	firstOption,
	...)
{
	PGPOptionListRef	optionList;
	
	pgpAssert( pgpContextIsValid( context ) );
	pgpAssert( pgpKeyIsValid( keyRef ) );
	
	if( pgpKeyIsValid( keyRef ) && pgpContextIsValid( context ) )
	{
		PGPOptionListRef	subOptions;
		PGPOptionValue		value;
		va_list				args;
		
		va_start( args, firstOption );
			subOptions = pgpBuildOptionListArgs( context,
				FALSE, firstOption, args );
		va_end( args );

		value.asKeyRef = keyRef;
	
		pgpIncKeyRefCount( keyRef );

		optionList = pgpCreateCustomValueOptionList(
								context,
								kPGPOptionType_SignWithKey,
								kPGPOptionFlag_Default, &value,
								sizeof( keyRef ), subOptions,
								SpecialOptionHandlerProc );
	}
	else
	{
		va_list				args;
		
		va_start( args, firstOption );
		pgpFreeVarArgOptionList( firstOption, args);
		va_end( args );
		
		optionList = kPGPBadParamsOptionListRef;
	}
	
#if PGP_SIGN_DISABLE
	pgpSetOptionListError( optionList, kPGPError_FeatureNotAvailable );
#endif

	return( optionList );
}

	PGPOptionListRef
PGPOConventionalEncrypt(
	PGPContextRef	context,
	PGPOptionListRef firstOption,
	...)
{
	PGPOptionListRef	optionList;
	PGPOptionListRef	subOptions;
	va_list				args;
	
	pgpAssert( pgpContextIsValid( context ) );

	if ( pgpContextIsValid( context ) )
	{
		va_start( args, firstOption );
			subOptions = pgpBuildOptionListArgs( context,
						FALSE, firstOption, args );
		va_end( args );

		optionList = pgpCreateCustomValueOptionList(
						context,  
						kPGPOptionType_ConventionalEncrypt,
						kPGPOptionFlag_Default, NULL,
						0, subOptions, NULL);
	}
	else
	{
		va_start( args, firstOption );
		pgpFreeVarArgOptionList( firstOption, args);
		va_end( args );
		
		optionList = kPGPBadParamsOptionListRef;
	}
	
#if PGP_ENCRYPT_DISABLE
	pgpSetOptionListError( optionList, kPGPError_FeatureNotAvailable );
#endif

	return( optionList );
}

	PGPOptionListRef
PGPOPassphraseBuffer(
	PGPContextRef	context,
	const void *	passphrase,
	PGPSize			passphraseLength)
{
	pgpValidateOptionContext( context );
	pgpValidateOptionParam( IsntNull( passphrase ) );
	
	return( pgpCreateSensitiveOptionList( context,
				kPGPOptionType_Passphrase, passphrase, passphraseLength ) );
}

	PGPOptionListRef
PGPOPassphrase(
	PGPContextRef	context,
	const char *	passphrase)
{
	PGPSize			passphraseLength;

	pgpValidateOptionContext( context );
	pgpValidateOptionParam( IsntNull( passphrase ) );

	/* Don't include trailing null, it is not used in the hash operations */
	passphraseLength = strlen( passphrase );
	
	return( pgpCreateSensitiveOptionList( context,
				kPGPOptionType_Passphrase, passphrase, passphraseLength ) );
}


	PGPOptionListRef
PGPOPasskeyBuffer(
	PGPContextRef	context,
	const void *	passkey,
	PGPSize			passkeyLength)
{
	pgpValidateOptionContext( context );
	pgpValidateOptionParam( IsntNull( passkey ) );
	
	return( pgpCreateSensitiveOptionList( context,
				kPGPOptionType_Passkey, passkey, passkeyLength ) );
}


	PGPOptionListRef
PGPOSessionKey(
	PGPContextRef	context,
	const void *	sessionKey,
	PGPSize			sessionKeyLength)
{
	pgpValidateOptionContext( context );
	pgpValidateOptionParam( IsntNull( sessionKey ) );
	
	return( pgpCreateSensitiveOptionList( context,
				kPGPOptionType_SessionKey, sessionKey, sessionKeyLength ) );
}


	PGPOptionListRef
PGPODetachedSig(
	PGPContextRef	context,
	PGPOptionListRef firstOption,
	...)
{
	PGPOptionListRef	optionList;
	PGPOptionListRef	subOptions;
	va_list				args;
	
	pgpAssert( pgpContextIsValid( context ) );

	if ( pgpContextIsValid( context )  )
	{
		va_start( args, firstOption );
			subOptions = pgpBuildOptionListArgs( context,
				FALSE, firstOption, args );
		va_end( args );

		optionList = pgpCreateCustomValueOptionList( context, 
								kPGPOptionType_DetachedSignature,
								kPGPOptionFlag_Default, NULL,
								0, subOptions, NULL);
	}
	else
	{
		va_start( args, firstOption );
		pgpFreeVarArgOptionList( firstOption, args);
		va_end( args );
		
		optionList = kPGPBadParamsOptionListRef;
	}
	
	return( optionList );
}

#if 0
/* Not supported */
	PGPOptionListRef
PGPOMailHeaders(
	PGPContextRef	context,
	PGPOptionListRef firstOption,
	...)
{
	PGPOptionListRef	optionList;
	PGPOptionListRef	subOptions;
	va_list				args;
	
	pgpAssert( pgpContextIsValid( context ) );

	va_start( args, firstOption );
		subOptions = pgpBuildOptionListArgs( context,
			FALSE, firstOption, args );
	va_end( args );

	optionList = pgpCreateCustomValueOptionList( context, 
							kPGPOptionType_MailHeaders,
							kPGPOptionFlag_Default, NULL,
							0, subOptions, NULL);
	
	return( optionList );
}
#endif

	PGPOptionListRef
PGPOCipherAlgorithm(
	PGPContextRef	context,
	PGPCipherAlgorithm	algorithm
	)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );
	pgpValidateOptionParam( algorithm == kPGPCipherAlgorithm_IDEA ||
		algorithm == kPGPCipherAlgorithm_3DES ||
		algorithm == kPGPCipherAlgorithm_CAST5);

	value.asCipherAlgorithm = algorithm;
	
	optionList = pgpCreateStandardValueOptionList( context,  
							kPGPOptionType_CipherAlgorithm,
							&value, sizeof( algorithm ), NULL);
	
	return( optionList );
}

	PGPOptionListRef
PGPOHashAlgorithm(
	PGPContextRef		context,
	PGPHashAlgorithm	algorithm
	)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
		
	pgpValidateOptionContext( context );
	pgpValidateOptionParam( algorithm == kPGPHashAlgorithm_MD5 ||
		algorithm == kPGPHashAlgorithm_SHA ||
		algorithm == kPGPHashAlgorithm_RIPEMD160 );

	value.asHashAlgorithm = algorithm;
	
	optionList = pgpCreateStandardValueOptionList( context, 
						kPGPOptionType_HashAlgorithm,
						&value, sizeof( algorithm ), NULL );
	
	return( optionList );
}

	PGPOptionListRef
PGPOFailBelowValidity(
	PGPContextRef	context,
	PGPValidity		minValidity)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );

	value.asValidity = minValidity;
	
	optionList = pgpCreateStandardValueOptionList( context,  
						kPGPOptionType_FailBelowValidity,
						&value, sizeof( minValidity ), NULL );
	
	return( optionList );
}

	PGPOptionListRef
PGPOWarnBelowValidity(
	PGPContextRef	context,
	PGPValidity		minValidity)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );

	value.asValidity = minValidity;
	
	optionList = pgpCreateStandardValueOptionList( context, 
						kPGPOptionType_WarnBelowValidity,
						&value, sizeof( minValidity ), NULL );
	
	return( optionList );

⌨️ 快捷键说明

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