pgpoptionlist.pas
来自「用DELPHI实现的 PGP 加密算法」· PAS 代码 · 共 344 行 · 第 1/2 页
PAS
344 行
PGPOCommentString: function(Context: pPGPContext; Comment: PChar): pPGPOptionList; cdecl;
PGPOVersionString: function(Context: pPGPContext; Version: PChar): pPGPOptionList; cdecl;
// both
PGPOPassphrase: function(Context: pPGPContext; Passphrase: PChar): pPGPOptionList; cdecl;
PGPOPassphraseBuffer: function(Context: pPGPContext; Passphrase: PChar;
PassphraseLength: PGPSize): pPGPOptionList; cdecl;
PGPOPasskeyBuffer: function(Context: pPGPContext; Passkey: PChar; PasskeyLength: PGPSize): pPGPOptionList; cdecl;
PGPOPreferredAlgorithms: function(Context: pPGPContext; const PrefAlg: TPGPCipherAlgorithms;
NumAlgs: PGPUInt32): pPGPOptionList; cdecl;
// PGP 6.5.X
PGPOKeySetRef6: function(Context: pPGPContext; KeySet: pPGPKeySet): pPGPOptionList; cdecl;
// PGP 7.X
PGPOKeyDBRef7: function(Context: pPGPContext; KeyDB: pPGPKeyDB): pPGPOptionList; cdecl;
// both
PGPOSendNullEvents: function(Context: pPGPContext; ApproxInterval: PGPTimeInterval): pPGPOptionList; cdecl;
PGPOExportFormat: function(Context: pPGPContext; ExportFormat: PGPExportFormat): pPGPOptionList; cdecl;
PGPOExportKeySet: function(Context: pPGPContext; KeySet: pPGPKeySet): pPGPOptionList; cdecl;
PGPOExportPrivateSubkeys: function(Context: pPGPContext; ExportSubkeys: PGPBoolean): pPGPOptionList; cdecl;
// PGP 6.5.X
PGPOImportKeysTo: function(Context: pPGPContext; KeySet: pPGPKeySet): pPGPOptionList; cdecl;
// PGP 7.X
{PGPOImportKeysTo: function(Context: pPGPContext; KeyDB: pPGPKeyDB): pPGPOptionList; cdecl;}
// both
PGPOEventHandler: function(Context: pPGPContext; Handler: TPGPEventHandlerProcPtr;
UserValue: PGPUserValue): pPGPOptionList; cdecl;
PGPOLastOption: function(Context: pPGPContext): pPGPOptionList; cdecl;
// wrappers for the respective PGP functions as Delphi cannot handle open arrays with the cdecl convention
function PGPBuildOptionList(Context: pPGPContext; var OptionList: pPGPOptionList;
const Options: Array of pPGPOptionList): PGPError;
function PGPAppendOptionList(OutList: pPGPOptionList; const Options: Array of pPGPOptionList): PGPError;
// wrapper function for version compatibility
function PGPOKeySetRef(Context: pPGPContext; KeySet: pPGPKeySet): pPGPOptionList;
implementation // code modified by idw
uses
Windows;
// the ASM technique for accessing open arrays is based on the
// original work of Graham Grieve in Kestral Computing's
// PGPAPI.PAS file: <http://www.kestral.com.au/devtools/pgp/>
const
PGPBuildOptionListProcPtr: Pointer = nil;
PGPAppendOptionListProcPtr: Pointer = nil;
function PGPBuildOptionList(Context: pPGPContext; var OptionList: pPGPOptionList;
const Options: Array of pPGPOptionList): PGPError; assembler;
// EAX = Context; EDX = @OptionList; ECX = Options; EBP+08h = high(Options)
asm // Delphi automatically creates a stack frame here which helps us cleaning up the stack
SUB ESP,4 // for temporary OptionList variable
MOV [EBP-4],EDX // free EDX for using as variable
MOV EDX,[EBP+8] // get high(Options) from stack
SHL EDX,2 // mul SizeOf(pPGPOptionList)
PUSH -1 // push PGPLastOption = kPGPEndOfArgsOptionListRef (see pgpOptionListPriv.h)
@LOOP: // push Options
PUSH DWORD PTR [ECX+EDX]
SUB EDX,4
JNS @LOOP
PUSH DWORD PTR [EBP-4] // push OptionList
PUSH EAX // push Context
CALL PGPBuildOptionListProcPtr // result comes in EAX
POP ECX // remove Context from stack
POP EDX // get OptionList from stack
MOV ESP,EBP // restore stack pointer (and cleanup cdecl stack)
end;
function PGPAppendOptionList(OutList: pPGPOptionList; const Options: Array of pPGPOptionList): PGPError; assembler;
// EAX = OutList; EDX = Options; ECX = high(Options)
asm // Delphi does not create a stack frame here, but we do it for conveniently cleaning up the stack
PUSH EBP // save base pointer
MOV EBP,ESP // save stack pointer
SHL ECX,2 // high(Options) mul SizeOf(pPGPOptionList)
PUSH -1 // push PGPLastOption = kPGPEndOfArgsOptionListRef (see pgpOptionListPriv.h)
@LOOP: // push Options
PUSH DWORD PTR [EDX+ECX]
SUB ECX,4
JNS @LOOP
PUSH EAX // push OutList
CALL PGPAppendOptionListProcPtr // result comes in EAX
MOV ESP,EBP // restore stack pointer
POP EBP // restore base pointer
end;
function PGPOKeySetRef(Context: pPGPContext; KeySet: pPGPKeySet): pPGPOptionList;
begin
if PGP7X then
Result:=PGPOKeyDBRef7(Context, PGPPeekKeySetKeyDB(KeySet))
else Result:=PGPOKeySetRef6(Context, KeySet);
end;
initialization
if PGPInitErrorCode=ieNone then begin
PGPBuildOptionListProcPtr:=GetProcAddress(hPGPsdkLib, 'PGPBuildOptionList');
PGPAppendOptionListProcPtr:=GetProcAddress(hPGPsdkLib, 'PGPAppendOptionList');
PGPNewOptionList:=GetProcAddress(hPGPsdkLib, 'PGPNewOptionList');
PGPCopyOptionList:=GetProcAddress(hPGPsdkLib, 'PGPCopyOptionList');
PGPFreeOptionList:=GetProcAddress(hPGPsdkLib, 'PGPFreeOptionList');
PGPAddJobOptions:=GetProcAddress(hPGPsdkLib, 'PGPAddJobOptions');
PGPOInputBuffer:=GetProcAddress(hPGPsdkLib, 'PGPOInputBuffer');
PGPOInputFile:=GetProcAddress(hPGPsdkLib, 'PGPOInputFile');
PGPODiscardOutput:=GetProcAddress(hPGPsdkLib, 'PGPODiscardOutput');
PGPOAllocatedOutputBuffer:=GetProcAddress(hPGPsdkLib, 'PGPOAllocatedOutputBuffer');
PGPOOutputBuffer:=GetProcAddress(hPGPsdkLib, 'PGPOOutputBuffer');
PGPOOutputFile:=GetProcAddress(hPGPsdkLib, 'PGPOOutputFile');
PGPOPGPMIMEEncoding:=GetProcAddress(hPGPsdkLib, 'PGPOPGPMIMEEncoding');
PGPOOmitMIMEVersion:=GetProcAddress(hPGPsdkLib, 'PGPOOmitMIMEVersion');
PGPOLocalEncoding:=GetProcAddress(hPGPsdkLib, 'PGPOLocalEncoding');
PGPOOutputLineEndType:=GetProcAddress(hPGPsdkLib, 'PGPOOutputLineEndType');
PGPODetachedSig:=GetProcAddress(hPGPsdkLib, 'PGPODetachedSig');
PGPOConventionalEncrypt:=GetProcAddress(hPGPsdkLib, 'PGPOConventionalEncrypt');
PGPOCipherAlgorithm:=GetProcAddress(hPGPsdkLib, 'PGPOCipherAlgorithm');
if PGP7X then
PGPOEncryptToKey:=GetProcAddress(hPGPsdkLib, 'PGPOEncryptToKeyDBObj')
else PGPOEncryptToKey:=GetProcAddress(hPGPsdkLib, 'PGPOEncryptToKey');
PGPOEncryptToKeySet:=GetProcAddress(hPGPsdkLib, 'PGPOEncryptToKeySet');
PGPOHashAlgorithm:=GetProcAddress(hPGPsdkLib, 'PGPOHashAlgorithm');
PGPOSignWithKey:=GetProcAddress(hPGPsdkLib, 'PGPOSignWithKey');
PGPOWarnBelowValidity:=GetProcAddress(hPGPsdkLib, 'PGPOWarnBelowValidity');
PGPOFailBelowValidity:=GetProcAddress(hPGPsdkLib, 'PGPOFailBelowValidity');
PGPOAskUserForEntropy:=GetProcAddress(hPGPsdkLib, 'PGPOAskUserForEntropy');
PGPODataIsASCII:=GetProcAddress(hPGPsdkLib, 'PGPODataIsASCII');
PGPORawPGPInput:=GetProcAddress(hPGPsdkLib, 'PGPORawPGPInput');
PGPOForYourEyesOnly:=GetProcAddress(hPGPsdkLib, 'PGPOForYourEyesOnly');
PGPOArmorOutput:=GetProcAddress(hPGPsdkLib, 'PGPOArmorOutput');
PGPOFileNameString:=GetProcAddress(hPGPsdkLib, 'PGPOFileNameString');
PGPOClearSign:=GetProcAddress(hPGPsdkLib, 'PGPOClearSign');
PGPOPassThroughIfUnrecognized:=GetProcAddress(hPGPsdkLib, 'PGPOPassThroughIfUnrecognized');
PGPOPassThroughClearSigned:=GetProcAddress(hPGPsdkLib, 'PGPOPassThroughClearSigned');
PGPOPassThroughKeys:=GetProcAddress(hPGPsdkLib, 'PGPOPassThroughKeys');
PGPOSendEventIfKeyFound:=GetProcAddress(hPGPsdkLib, 'PGPOSendEventIfKeyFound');
PGPORecursivelyDecode:=GetProcAddress(hPGPsdkLib, 'PGPORecursivelyDecode');
PGPOAdditionalRecipientRequestKeySet:=GetProcAddress(hPGPsdkLib, 'PGPOAdditionalRecipientRequestKeySet');
PGPOKeyGenName:=GetProcAddress(hPGPsdkLib, 'PGPOKeyGenName');
PGPOKeyGenMasterKey:=GetProcAddress(hPGPsdkLib, 'PGPOKeyGenMasterKey');
PGPOExportPrivateKeys:=GetProcAddress(hPGPsdkLib, 'PGPOExportPrivateKeys');
PGPOKeyGenFast:=GetProcAddress(hPGPsdkLib, 'PGPOKeyGenFast');
PGPOKeyGenParams:=GetProcAddress(hPGPsdkLib, 'PGPOKeyGenParams');
PGPOCreationDate:=GetProcAddress(hPGPsdkLib, 'PGPOCreationDate');
PGPOExpiration:=GetProcAddress(hPGPsdkLib, 'PGPOExpiration');
PGPOExportable:=GetProcAddress(hPGPsdkLib, 'PGPOExportable');
PGPOSigRegularExpression:=GetProcAddress(hPGPsdkLib, 'PGPOSigRegularExpression');
PGPOSigTrust:=GetProcAddress(hPGPsdkLib, 'PGPOSigTrust');
PGPORevocationKeySet:=GetProcAddress(hPGPsdkLib, 'PGPORevocationKeySet');
if PGP7X then
PGPOKeyFlags:=GetProcAddress(hPGPsdkLib, 'PGPOKeyFlags')
else PGPOKeyFlags:=nil;
PGPONullOption:=GetProcAddress(hPGPsdkLib, 'PGPONullOption');
PGPOCompression:=GetProcAddress(hPGPsdkLib, 'PGPOCompression');
PGPOCommentString:=GetProcAddress(hPGPsdkLib, 'PGPOCommentString');
PGPOVersionString:=GetProcAddress(hPGPsdkLib, 'PGPOVersionString');
PGPOPassphrase:=GetProcAddress(hPGPsdkLib, 'PGPOPassphrase');
PGPOPassphraseBuffer:=GetProcAddress(hPGPsdkLib, 'PGPOPassphraseBuffer');
PGPOPasskeyBuffer:=GetProcAddress(hPGPsdkLib, 'PGPOPasskeyBuffer');
PGPOPreferredAlgorithms:=GetProcAddress(hPGPsdkLib, 'PGPOPreferredAlgorithms');
if PGP7X then
PGPOKeyDBRef7:=GetProcAddress(hPGPsdkLib, 'PGPOKeyDBRef')
else PGPOKeySetRef6:=GetProcAddress(hPGPsdkLib, 'PGPOKeySetRef');
PGPOSendNullEvents:=GetProcAddress(hPGPsdkLib, 'PGPOSendNullEvents');
PGPOExportFormat:=GetProcAddress(hPGPsdkLib, 'PGPOExportFormat');
PGPOExportKeySet:=GetProcAddress(hPGPsdkLib, 'PGPOExportKeySet');
PGPOExportPrivateSubkeys:=GetProcAddress(hPGPsdkLib, 'PGPOExportPrivateSubkeys');
PGPOImportKeysTo:=GetProcAddress(hPGPsdkLib, 'PGPOImportKeysTo');
PGPOEventHandler:=GetProcAddress(hPGPsdkLib, 'PGPOEventHandler');
PGPOLastOption:=GetProcAddress(hPGPsdkLib, 'PGPOLastOption');
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?