pgp2comp.pas

来自「用DELPHI实现的 PGP 加密算法」· PAS 代码 · 共 2,057 行 · 第 1/5 页

PAS
2,057
字号
{$A+,B-,C-,D+,E-,F-,G+,H+,I+,J+,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z4}
unit PGP2Comp;						        // Version 3.3.4

{------------------------------------------------------------------------------}
{                                                                              }
{                This unit was generated on 30.09.99 19:40:45 by               }
{                     the RTE Software Component Generator                     }
{                                                                              }
{               This code was written by:  Michael in der Wiesche              }
{                                                                              }
{                     This code is Copyright (c) 1999-2003                     }
{                           by Michael in der Wiesche                          }
{                                                                              }
{------------------------------------------------------------------------------}

interface

uses
  Forms,
  Windows,
  Classes,
  SysUtils,
  ExtCtrls,
  StdCtrls,
  KeyPropTypes,
  UTF8,
  pgpBase,
  pgpErrors,
  pgpPubTypes,
  pgpUtilities,
  pgpOptionList,
  pgpMemoryMgr,
  pgpKeyServer,
  pgpEvents,
  pgpKeys,
  pgpTLS,
  pgpUI,
  pgpCL,
  pgpSC,
  KeyFuncs,
  PrefFuncs,
  PGPDialogs,
  PGPKeyGenerate,
  PGPEncode,
  PGPDecode;


// Register --------------------------------------------------------------------

procedure Register;


// PGP Initialization Error ----------------------------------------------------

type
  TPGPInitErrorCode = pgpBase.TPGPInitErrorCode;

const
  PGPInitErrorCode: TPGPInitErrorCode = ieNone;


// Notification Messages -------------------------------------------------------

const
  WM_PGP_ReloadPrefs: UInt = 0;
  WM_PGP_ReloadKeyring: UInt = 0;
  WM_PGP_ReloadKeyserverPrefs: UInt = 0;


// Common types ----------------------------------------------------------------

type

  // Preferences ---------------------------------------------------------------

  TPGPPref = (
    Pref_DefaultKeyID,
    Pref_PublicKeyring,
    Pref_PrivateKeyring,
    Pref_RandomSeedFile,
    Pref_GroupsFile
  );

  TPGPPrefs = Set of TPGPPref;

  TPrefsPage = (
    PrefsPage_GeneralPrefs,
    PrefsPage_KeyringPrefs,
    PrefsPage_EmailPrefs,
    PrefsPage_HotkeyPrefs,
    PrefsPage_KeyserverPrefs,
    PrefsPage_CAPrefs,
    PrefsPage_AdvancedPrefs
  );

  {$IFNDEF _PGP2COMP_BCPPB_}
  // BCPPB has ambiguity issues in method declarations if these are included
  TPreferenceRec = PrefFuncs.TPreferenceRec;
  {$ENDIF}

  // Key properties ------------------------------------------------------------

  {$IFNDEF _PGP2COMP_BCPPB_}
  // BCPPB has ambiguity issues in method declarations if these are included
  TKeyPropsList = KeyPropTypes.TKeyPropsList;
  TKeyPropsRec = KeyPropTypes.TKeyPropsRec;
  PKeyPropsRec = KeyPropTypes.PKeyPropsRec;
  TKeyProp = KeyPropTypes.TKeyProp;
  TKeyProps = KeyPropTypes.TKeyProps;
  {$ENDIF}

  TAlgorithmKeyFilter = (
    AlgorithmFilter_AllKeys,
    AlgorithmFilter_DHDSS,
    AlgorithmFilter_RSA,
    AlgorithmFilter_RSALegacy
  );

  TBooleanKeyFilter = (
    BoolFilter_AllKeys,
    BoolFilter_CanEncrypt,
    BoolFilter_CanDecrypt,
    BoolFilter_CanSign,
    BoolFilter_CanVerify
  );

  TKeyOrdering = (
    Any_Order,
    UserID_Order,
    ReverseUserID_Order,
    KeyID_Order,
    ReverseKeyID_Order,
    Validity_Order,
    ReverseValidity_Order,
    Trust_Order,
    ReverseTrust_Order,
    EncryptKeySize_Order,
    ReverseEncryptKeySize_Order,
    SigKeySize_Order,
    ReverseSigKeySize_Order,
    Creation_Order,
    ReverseCreation_Order,
    Expiration_Order,
    ReverseExpiration_Order
  );

  {$IFNDEF _PGP2COMP_BCPPB_}
  // BCPPB has ambiguity issues in method declarations if these are included
  TTrustLevel = KeyPropTypes.TTrustLevel;
  TValidityLevel = KeyPropTypes.TValidityLevel;
  TKeyAlgorithm = KeyPropTypes.TKeyAlgorithm;
  TCipherAlgorithm = KeyPropTypes.TCipherAlgorithm;
  TADKType = KeyPropTypes.TADKType;
  {$ENDIF}

  // Key server ----------------------------------------------------------------

  TServerType = (
    KeyServerType_Invalid,
    KeyServerType_LDAP,
    KeyServerType_HTTP,
    KeyServerType_LDAPS,
    KeyServerType_HTTPS
  );

  TServerFlag = (
    KeyServerListed,
    KeyServerIsRoot
  );

  TServerFlags = Set of TServerFlag;

  // Key import ----------------------------------------------------------------

  TIgnoreKnownKeys = Set of (Ignore_ByHexID, Ignore_ByUserID);

  // Key generation ------------------------------------------------------------

  {$IFNDEF _PGP2COMP_BCPPB_}
  // BCPPB has ambiguity issues in method declarations if these are included
  TKeySize = PGPKeyGenerate.TKeySize;
  TSubKeySize = PGPKeyGenerate.TSubKeySize;
  TMinPassLen = PGPKeyGenerate.TMinPassLen;
  TMinPassQual = PGPKeyGenerate.TMinPassQual;
  {$ENDIF}

  // Encoding ------------------------------------------------------------------

  {$IFNDEF _PGP2COMP_BCPPB_}
  // BCPPB has ambiguity issues in method declarations if these are included
  TSignAlgorithm = PGPEncode.TSignAlgorithm;
  TConventionalAlgorithm = PGPEncode.TConventionalAlgorithm;
  {$ENDIF}

  // Decoding ------------------------------------------------------------------

  {$IFNDEF _PGP2COMP_BCPPB_}
  // BCPPB has ambiguity issues in method declarations if these are included
  TSigStatus = PGPDecode.TSigStatus;
  TSigPropsRec = PGPDecode.TSigPropsRec;
  {$ENDIF}


// Common Constants ------------------------------------------------------------

const
  KeyProp_HexID = KeyPropTypes.KeyProp_HexID;
  KeyProp_UserID = KeyPropTypes.KeyProp_UserID;
  KeyProp_Fingerprint = KeyPropTypes.KeyProp_Fingerprint;
  KeyProp_CreaTimeStr = KeyPropTypes.KeyProp_CreaTimeStr;
  KeyProp_ExpTimeStr = KeyPropTypes.KeyProp_ExpTimeStr;
  KeyProp_Size = KeyPropTypes.KeyProp_Size;
  KeyProp_Algorithm = KeyPropTypes.KeyProp_Algorithm;
  KeyProp_Trust = KeyPropTypes.KeyProp_Trust;
  KeyProp_Validity = KeyPropTypes.KeyProp_Validity;
  KeyProp_CreaTimeNum = KeyPropTypes.KeyProp_CreaTimeNum;
  KeyProp_ExpTimeNum = KeyPropTypes.KeyProp_ExpTimeNum;
  KeyProp_Secret = KeyPropTypes.KeyProp_Secret;
  KeyProp_ImplicitTrust = KeyPropTypes.KeyProp_ImplicitTrust;
  KeyProp_Revoked = KeyPropTypes.KeyProp_Revoked;
  KeyProp_Disabled = KeyPropTypes.KeyProp_Disabled;
  KeyProp_Expired = KeyPropTypes.KeyProp_Expired;
  KeyProp_SecretShared = KeyPropTypes.KeyProp_SecretShared;
  KeyProp_CanEncrypt = KeyPropTypes.KeyProp_CanEncrypt;
  KeyProp_CanDecrypt = KeyPropTypes.KeyProp_CanDecrypt;
  KeyProp_CanSign = KeyPropTypes.KeyProp_CanSign;
  KeyProp_CanVerify = KeyPropTypes.KeyProp_CanVerify;
  KeyProp_HasRevoker = KeyPropTypes.KeyProp_HasRevoker;
  KeyProp_HasADK = KeyPropTypes.KeyProp_HasADK;
  KeyProp_HasSubKey = KeyPropTypes.KeyProp_HasSubKey;
  KeyProp_LegacyKey = KeyPropTypes.KeyProp_LegacyKey;
  KeyProp_IncludeUserIDs = KeyPropTypes.KeyProp_IncludeUserIDs;
  KeyProp_IncludeSignerIDs = KeyPropTypes.KeyProp_IncludeSignerIDs;
  KeyProp_IncludeGroupsList = KeyPropTypes.KeyProp_IncludeGroupsList;

  KeyProps_IDFlags = [KeyProp_HexID, KeyProp_UserID];
  KeyProps_IDComplete = KeyProps_IDFlags + [KeyProp_Size, KeyProp_Algorithm];


// Common Procs ----------------------------------------------------------------

type
  TOnFailure = procedure(ErrorCode: Longint; const ErrorMsg: String) of Object;


// TPGPPreferences -------------------------------------------------------------

  TOnGetPreferences = procedure(const Preferences: TPreferenceRec) of Object;
  TOnSetPreferences = procedure(var Preferences: TPreferenceRec) of Object;

  TPGPPreferences = class(TComponent)
  private
    FAltPubringFile: String;
    FAltSecringFile: String;
    FAltGroupsFile: String;
    FParentHandle: THandle;
    FPreferences: TPreferenceRec;
    FPGPPrefs: TPGPPrefs;
    FPrefsPage: TPrefsPage;
    FOnFailure: TOnFailure;
    FOnGetPreferences: TOnGetPreferences;
    FOnSetPreferences: TOnSetPreferences;
    function GetFlags: Longint;
    function PrefsError: Longbool;
    function GetAltPubKeyring: String;
    function GetAltPrivKeyring: String;
    function GetAltGroupsFile: String;
    procedure SetAltPubKeyring(const Value: String);
    procedure SetAltPrivKeyring(const Value: String);
    procedure SetAltGroupsFile(const Value: String);
  protected
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    function ShowPrefsDialog: Longint;
    function DoGetPreferences: Longint;
    function DoSetPreferences: Longint;
    property ParentHandle: THandle
      read FParentHandle
      write FParentHandle;
  published
    property AltPubKeyring: String
      read GetAltPubKeyring
      write SetAltPubKeyring;
    property AltPrivKeyring: String
      read GetAltPrivKeyring
      write SetAltPrivKeyring;
    property AltGroupsFile: String
      read GetAltGroupsFile
      write SetAltGroupsFile;
    property PrefsPage: TPrefsPage
      read FPrefsPage
      write FPrefsPage;
    property DefaultKeyHexID: String
      read FPreferences.DefaultKeyHexID
      write FPreferences.DefaultKeyHexID;
    property PublicKeyring: String
      read FPreferences.PublicKeyring
      write FPreferences.PublicKeyring;
    property PrivateKeyring: String
      read FPreferences.PrivateKeyring
      write FPreferences.PrivateKeyring;
    property RandomSeedFile: String
      read FPreferences.RandomSeedFile
      write FPreferences.RandomSeedFile;
    property GroupsFile: String
      read FPreferences.GroupsFile
      write FPreferences.GroupsFile;
    property PGPPrefs: TPGPPrefs
      read FPGPPrefs
      write FPGPPrefs;
    property OnFailure: TOnFailure
      read FOnFailure
      write FOnFailure;
    property OnGetPreferences: TOnGetPreferences
      read FOnGetPreferences
      write FOnGetPreferences;
    property OnSetPreferences: TOnSetPreferences
      read FOnSetPreferences
      write FOnSetPreferences;
  end;


// TPGPKeyServer ---------------------------------------------------------------

type
  TServerEntry = Record
    ServerProtocol: TServerType;
    ServerDNS: String;
    ServerPort: Word;
    ServerFlags: TServerFlags;
  end;

  TOnGetDefaultServer = procedure(const ServerEntry: TServerEntry) of Object;
  TOnSetDefaultServer = procedure(var ServerEntry: TServerEntry) of Object;
  TOnServerResults = procedure(const KeyPropsList: TKeyPropsList) of Object;

  TPGPKeyServer = class(TComponent)
  private
    FParentHandle: THandle;
    FKeyDlgPrompt: String;
    FKeyProps: TKeyProps;
    FServerEntry: TServerEntry;
    FOnFailure: TOnFailure;
    FOnGetDefaultServer: TOnGetDefaultServer;
    FOnSetDefaultServer: TOnSetDefaultServer;
    FOnServerResults: TOnServerResults;
  protected
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    function DoGetKeysFromServer(const KeyData: String): Longint;
    function DoSendKeysToServer: Longint;
    function DoGetDefaultServer: Longint;
    function DoSetDefaultServer: Longint;
    property ParentHandle: THandle
      read FParentHandle
      write FParentHandle;
  published
    property KeyDlgPrompt: String
      read FKeyDlgPrompt
      write FKeyDlgPrompt;
    property KeyProps: TKeyProps
      read FKeyProps
      write FKeyProps;
    property ServerProtocol: TServerType
      read FServerEntry.ServerProtocol
      write FServerEntry.ServerProtocol;
    property ServerDNS: String
      read FServerEntry.ServerDNS
      write FServerEntry.ServerDNS;
    property ServerPort: Word
      read FServerEntry.ServerPort
      write FServerEntry.ServerPort;
    property ServerFlags: TServerFlags
      read FServerEntry.ServerFlags
      write FServerEntry.ServerFlags;
    property OnFailure: TOnFailure
      read FOnFailure
      write FOnFailure;
    property OnGetDefaultServer: TOnGetDefaultServer
      read FOnGetDefaultServer
      write FOnGetDefaultServer;
    property OnSetDefaultServer: TOnSetDefaultServer
      read FOnSetDefaultServer
      write FOnSetDefaultServer;
    property OnServerResults: TOnServerResults
      read FOnServerResults
      write FOnServerResults;
  end;


// TPGPGetKeyProps -------------------------------------------------------------

type
  TKeyRingProps = class(TComponent)
  private
    FComboBox: TComboBox;
    FListBox: TListBox;
    FPrimaryIDs: TStringList;
    FRingAlgorithmFilter: TAlgorithmKeyFilter;
    FRingBoolFilter: TBooleanKeyFilter;
    FRingKeyOrdering: TKeyOrdering;
    FRingProps: TKeyProps;
    FRingPropsList: TKeyPropsList;
    FOnFailure: TOnFailure;
    function GetPrimaryIDs: Longint;
    function GetKeyFilter(AlgorithmFilter: TAlgorithmKeyFilter; BoolFilter: TBooleanKeyFilter): Longint;
  protected
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

⌨️ 快捷键说明

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