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

📄 pgpclientencode.c

📁 vc环境下的pgp源码
💻 C
📖 第 1 页 / 共 4 页
字号:
	)
{
	PGPOptionListRef	optionList;
	PGPOAdditionalRecipientRequestKeySetDesc	*descriptor;

	pgpValidateOptionContext( context );
	pgpValidateOptionParam( pgpKeySetIsValid( raKeySetRef ) );

	/* Use ADK descriptor as we have similar data structure */
	descriptor = (PGPOAdditionalRecipientRequestKeySetDesc *)
						pgpContextMemAlloc( context, sizeof(*descriptor), 0);
	if( IsntNull( descriptor ) )
	{
		PGPOptionValue	value;

		descriptor->arKeySetRef	= raKeySetRef;
		descriptor->arkclass 	= 0x80;	/* hard code value for revocation */

		value.asPtr = descriptor;

		PGPIncKeySetRefCount( raKeySetRef );

		optionList = pgpCreateStandardValueOptionList( context,  
							kPGPOptionType_RevocationKeySet,
							&value, sizeof( *descriptor ),
							AllocatedOptionHandlerProc );
	}
	else
	{
		optionList = kPGPOutOfMemoryOptionListRef;
	}
	
	return( optionList );
}

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

	pgpIncKeyRefCount( masterKeyRef );

	optionList = pgpCreateStandardValueOptionList( context,  
							kPGPOptionType_KeyGenMasterKey,
							&value, sizeof( masterKeyRef ),
							SpecialOptionHandlerProc );
	
	return( optionList );
}

	PGPOptionListRef
PGPOPreferredAlgorithms(
	PGPContextRef				context,
	PGPCipherAlgorithm const *	prefAlg,
	PGPUInt32					numAlgs)
{
	pgpValidateOptionContext( context );
	pgpValidateOptionParam( IsntNull( prefAlg ) );
	pgpValidateOptionParam( numAlgs != 0 );
	pgpAssert( numAlgs <= kPGPCipherAlgorithm_Last );
	
	return( pgpCreateBufferOptionList( context,
					kPGPOptionType_PreferredAlgorithms,
					prefAlg, numAlgs * sizeof( prefAlg[ 0 ] )  ) );
}

	PGPOptionListRef
PGPOKeyGenFast(
	PGPContextRef	context,
	PGPBoolean		fastGen
	)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );

	value.asUInt = (PGPUInt32)fastGen;
	
	optionList = pgpCreateStandardValueOptionList( context,  
							kPGPOptionType_KeyGenFast,
							&value, sizeof( PGPUInt32 ), NULL);

	return( optionList );
}

	PGPOptionListRef
PGPOKeyGenUseExistingEntropy(
	PGPContextRef	context,
	PGPBoolean		useExistingEntropy
	)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );

	value.asUInt = (PGPUInt32)useExistingEntropy;
	
	optionList = pgpCreateStandardValueOptionList( context,  
							kPGPOptionType_KeyGenUseExistingEntropy,
							&value, sizeof( PGPUInt32 ), NULL);

	return( optionList );
}

	PGPOptionListRef
PGPOExportable(
	PGPContextRef	context,
	PGPBoolean		exportable
	)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );

	value.asUInt = (PGPUInt32)exportable;
	
	optionList = pgpCreateStandardValueOptionList( context,  
							kPGPOptionType_Exportable,
							&value, sizeof( PGPUInt32 ), NULL);

	return( optionList );
}

	PGPOptionListRef
PGPOExportPrivateKeys(
	PGPContextRef	context,
	PGPBoolean		exportKeys
	)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );

	value.asUInt = (PGPUInt32)exportKeys;
	
	optionList = pgpCreateStandardValueOptionList( context,  
							kPGPOptionType_ExportPrivateKeys,
							&value, sizeof( PGPUInt32 ), NULL);

	return( optionList );
}

	PGPOptionListRef
PGPOExportPrivateSubkeys(
	PGPContextRef	context,
	PGPBoolean		exportSubkeys
	)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );

	value.asUInt = (PGPUInt32)exportSubkeys;
	
	optionList = pgpCreateStandardValueOptionList( context,  
							kPGPOptionType_ExportPrivateSubkeys,
							&value, sizeof( PGPUInt32 ), NULL);

	return( optionList );
}

	PGPOptionListRef
PGPOOmitMIMEVersion(
	PGPContextRef	context,
	PGPBoolean		omitVersion
	)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );

	value.asUInt = (PGPUInt32)omitVersion;
	
	optionList = pgpCreateStandardValueOptionList( context,  
							kPGPOptionType_OmitMIMEVersion,
							&value, sizeof( PGPUInt32 ), NULL);

	return( optionList );
}

	PGPOptionListRef
PGPOX509Encoding(
	PGPContextRef	context,
	PGPBoolean		x509Encoding
	)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );

	value.asUInt = (PGPUInt32)x509Encoding;
	
	optionList = pgpCreateStandardValueOptionList( context,  
							kPGPOptionType_X509Encoding,
							&value, sizeof( PGPUInt32 ), NULL);

	return( optionList );
}

	PGPOptionListRef
PGPOSigTrust(
	PGPContextRef	context,
	PGPUInt32		trustLevel,
	PGPUInt32		trustValue)
{
	PGPOptionListRef			optionList;
	PGPOCertificateTrustDesc	*descriptor;

	pgpValidateOptionContext( context );
	pgpValidateOptionParam( trustValue >= kPGPKeyTrust_Unknown &&
		trustValue <= kPGPKeyTrust_Ultimate );

	descriptor = (PGPOCertificateTrustDesc *)
						pgpContextMemAlloc( context, sizeof(*descriptor), 0);
	if( IsntNull( descriptor ) )
	{
		PGPOptionValue	value;

		descriptor->trustLevel	= trustLevel;
		descriptor->trustValue 	= trustValue;

		value.asPtr = descriptor;

		optionList = pgpCreateStandardValueOptionList( context,  
							kPGPOptionType_CertificateTrust,
							&value, sizeof( *descriptor ),
							AllocatedOptionHandlerProc );
	}
	else
	{
		optionList = kPGPOutOfMemoryOptionListRef;
	}
	
	return( optionList );
}

	PGPOptionListRef
PGPOCommentString(
	PGPContextRef	context,
	char const		*comment
	)
{
	PGPSize			 commentLength;

	pgpValidateOptionContext( context );
	pgpValidateOptionParam( IsntNull( comment ) );
	
	commentLength = strlen( comment ) + 1;

	return( pgpCreateBufferOptionList( context,
								kPGPOptionType_CommentString,
								comment, commentLength ) );
}

	PGPOptionListRef
PGPOVersionString(
	PGPContextRef	context,
	char const		*version
	)
{
	PGPSize			 versionLength;

	pgpValidateOptionContext( context );
	pgpValidateOptionParam( IsntNull( version ) );
	
	versionLength = strlen( version ) + 1;

	return( pgpCreateBufferOptionList( context,
								kPGPOptionType_VersionString,
								version, versionLength ) );
}

	PGPOptionListRef
PGPOFileNameString(
	PGPContextRef	context,
	char const		*fileName
	)
{
	PGPSize			 fileNameLength;

	pgpValidateOptionContext( context );
	pgpValidateOptionParam( IsntNull( fileName ) );
	
	fileNameLength = strlen( fileName ) + 1;

	return( pgpCreateBufferOptionList( context,
								kPGPOptionType_InputFileName,
								fileName, fileNameLength ) );
}

	PGPOptionListRef
PGPOSigRegularExpression(
	PGPContextRef	context,
	char const		*regexp
	)
{
	PGPSize			 regexpLength;

	pgpValidateOptionContext( context );
	pgpValidateOptionParam( IsntNull( regexp ) );
	
	regexpLength = strlen( regexp ) + 1;

	return( pgpCreateBufferOptionList( context,
								kPGPOptionType_CertificateRegularExpression,
								regexp, regexpLength ) );
}

	PGPOptionListRef
PGPOLocalEncoding(
	PGPContextRef				context,
	PGPLocalEncodingFlags		localEncode
	)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );

	/* Ensure incompatible options not selected */
	if( (localEncode & kPGPLocalEncoding_Force) &&
		(localEncode & kPGPLocalEncoding_Auto) )
		return kPGPBadParamsOptionListRef;

	value.asUInt = localEncode;
	
	optionList = pgpCreateStandardValueOptionList( context,  
					kPGPOptionType_LocalEncoding,
					&value, sizeof( PGPLocalEncodingFlags ), NULL);

	return( optionList );
}

	PGPOptionListRef
PGPOOutputLineEndType(
	PGPContextRef		context,
	PGPLineEndType		lineEnd
	)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );
	pgpValidateOptionParam( lineEnd == kPGPLineEnd_LF ||
		lineEnd == kPGPLineEnd_CR || lineEnd == kPGPLineEnd_CRLF );

	value.asUInt = (PGPUInt32) lineEnd;
	
	optionList = pgpCreateStandardValueOptionList( context,
					kPGPOptionType_OutputLineEndType,
					&value, sizeof( PGPLocalEncodingFlags ), NULL);

	return( optionList );
}

	PGPOptionListRef
PGPOExportFormat(
	PGPContextRef		context,
	PGPExportFormat		exportFormat
	)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );

	value.asUInt = (PGPUInt32) exportFormat;
	
	optionList = pgpCreateStandardValueOptionList( context,
					kPGPOptionType_ExportFormat,
					&value, sizeof( PGPLocalEncodingFlags ), NULL);

	return( optionList );
}

	PGPOptionListRef
PGPOInputFormat(
	PGPContextRef		context,
	PGPInputFormat		inputFormat
	)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );

	value.asUInt = (PGPUInt32) inputFormat;
	
	optionList = pgpCreateStandardValueOptionList( context,
					kPGPOptionType_InputFormat,
					&value, sizeof( PGPLocalEncodingFlags ), NULL);

	return( optionList );
}

	PGPOptionListRef
PGPOOutputFormat(
	PGPContextRef		context,
	PGPOutputFormat		outputFormat
	)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );

	value.asUInt = (PGPUInt32) outputFormat;
	
	optionList = pgpCreateStandardValueOptionList( context,
					kPGPOptionType_OutputFormat,
					&value, sizeof( PGPLocalEncodingFlags ), NULL);

	return( optionList );
}

/*
 * We don't use copy semantics on this one because it may have deep
 * structure that we don't know about.
 */
	PGPOptionListRef
PGPOAttributeValue(
	PGPContextRef		context,
	PGPAttributeValue	*attributeValue,
	PGPUInt32			attributeValueCount
	)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );

	value.asPtr = attributeValue;
	
	optionList = pgpCreateStandardValueOptionList( context,
					kPGPOptionType_AttributeValue,
					&value, attributeValueCount * sizeof(PGPAttributeValue),
					NULL);

	return( optionList );
}

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

	PGPIncKeySetRefCount( keySetRef );

	optionList = pgpCreateStandardValueOptionList( context,  
							kPGPOptionType_ImportKeysTo,
							&value, sizeof( keySetRef ),
							SpecialOptionHandlerProc );
	
	return( optionList );
}

	PGPOptionListRef
PGPOPGPMIMEEncoding(
	PGPContextRef	context,
	PGPBoolean		mimeEncoding,
	PGPSize *		mimeBodyOffset,
	char *			mimeSeparator
	)
{
	PGPOptionListRef			optionList;
	PGPOPGPMIMEEncodingDesc		*descriptor;

	pgpValidateOptionContext( context );
	if ( mimeEncoding )
	{
		if ( IsntNull( mimeBodyOffset ) )
			*mimeBodyOffset	= 0;
		if ( IsntNull( mimeSeparator ) )
			*mimeSeparator	= '\0';
			
		pgpValidateOptionParam( IsntNull( mimeBodyOffset ) );
		pgpValidateOptionParam( IsntNull( mimeSeparator ) );
		pgpDebugWhackMemory( mimeSeparator, kPGPMimeSeparatorSize );
	}
	else
	{
		/* mime off--ignore other params */
	}

	descriptor = (PGPOPGPMIMEEncodingDesc *)
						pgpContextMemAlloc( context, sizeof(*descriptor), 0 );
	if( IsntNull( descriptor ) )
	{
		PGPOptionValue	value;

		descriptor->mimeEncoding	= (PGPUInt32) mimeEncoding;
		descriptor->mimeBodyOffset 	= mimeEncoding ? mimeBodyOffset : NULL;
		descriptor->mimeSeparator 	= mimeEncoding ? mimeSeparator : NULL;

		value.asPtr = descriptor;

		optionList = pgpCreateStandardValueOptionList( context,
							kPGPOptionType_PGPMIMEEncoding,
							&value, sizeof( *descriptor ),
							AllocatedOptionHandlerProc );
	}
	else
	{
		optionList = kPGPOutOfMemoryOptionListRef;
	}
	
	return( optionList );
}



/*__Editor_settings____

	Local Variables:
	tab-width: 4
	End:
	vi: ts=4 sw=4
	vim: si
_____________________*/

⌨️ 快捷键说明

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