Advertisement
Guest User

Untitled

a guest
Jul 16th, 2017
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.37 KB | None | 0 0
  1.   {$MINENUMSIZE 1}
  2.   TOpenPGPPKAlgorithm = (
  3.     pkRSA                    = 1,
  4.     pkRSAEncryptOnly         = 2,
  5.     pkRSASignOnly            = 3,
  6.     pkElgamalEncryptOnly     = 16,
  7.     pkDSA                    = 17,
  8.     pkReservedEC             = 18,
  9.     pkReservedECDSA          = 19,
  10.     pkReserved20             = 20,
  11.     pkReservedDH             = 21,
  12.     pkPrivate100             = 100,
  13.     pkPrivate101             = 101,
  14.     pkPrivate102             = 102,
  15.     pkPrivate103             = 103,
  16.     pkPrivate104             = 104,
  17.     pkPrivate105             = 105,
  18.     pkPrivate106             = 106,
  19.     pkPrivate107             = 107,
  20.     pkPrivate108             = 108,
  21.     pkPrivate109             = 109,
  22.     pkPrivate110             = 110
  23.   );
  24.  
  25. function TPGPTag_Signature.ReadBody(PartOf: ITagStreamReader; Source: IIOReadable): OpenPGPResult; stdcall;
  26. var
  27.   reader: IIOTypedReader;
  28.   subpack: IIOReadable;
  29.   wb: Byte;
  30.   ww: Word;
  31. begin
  32.   // some init
  33.  
  34.   reader:= TIOTypedReader.Create(Source);
  35.   if not OpenPGPSuccess(reader.ReadByte(fVersion), Result) then
  36.     Exit;
  37.   case fVersion of
  38.     2, 3: {...};
  39.     4: begin
  40.       if not OpenPGPSuccess(reader.ReadByte(wb), Result) then
  41.         Exit;
  42.       fSignatureType:= TOpenPGPSignatureType(wb);
  43.       TraceDebug('V4 Signature: %s', [SignatureTypeToStr(fSignatureType)]);
  44.       if not OpenPGPSuccess(reader.ReadByte(wb), Result) then
  45.         Exit;
  46.       fPKAlgo:= TOpenPGPPKAlgorithm(wb);
  47.       {...}
  48.     end;
  49.   else
  50.     TraceError('Unsupported Signature version: %d', [fVersion]);
  51.     Exit(OPENPGP_ERROR_PACKET_INVALID_DATA);
  52.   end;
  53.   case fPKAlgo of
  54.     pkRSA, pkRSASignOnly: begin
  55.       fRSA_mdn:= TMPInteger.Create;
  56.       if not OpenPGPSuccess(fRSA_mdn.Read(Source), Result) then
  57.         Exit;
  58.     end;
  59.     pkDSA: begin
  60.       fDSA_r:= TMPInteger.Create;
  61.       fDSA_s:= TMPInteger.Create;
  62.       if not OpenPGPSuccess(fDSA_r.Read(Source), Result) then
  63.         Exit;
  64.       if not OpenPGPSuccess(fDSA_s.Read(Source), Result) then
  65.         Exit;
  66.     end;
  67.   else
  68.     TraceWarn('Signature.ReadBody: Unknown Signature Algorithm: %s', [PKAlgorithmToStr(fPKAlgo)]);
  69.     Exit(OPENPGP_ERROR_PACKET_INVALID_DATA);
  70.   end;
  71.   Result:= OPENPGP_ERROR_NOERROR;
  72. end;
  73.  
  74. function SignatureTypeToStr(const X: TOpenPGPSignatureType): String;
  75. begin
  76.   case X of
  77.     stBinaryDocument              : Result:= 'BinaryDocument';
  78.     stCanonicalDocument           : Result:= 'CanonicalDocument';
  79.     stStandalone                  : Result:= 'Standalone';
  80.  
  81.     stUserIDCertificationGeneric  : Result:= 'UserIDCertificationGeneric';
  82.     stUserIDCertificationPersona  : Result:= 'UserIDCertificationPersona';
  83.     stUserIDCertificationCasual   : Result:= 'UserIDCertificationCasual';
  84.     stUserIDCertificationPositive : Result:= 'UserIDCertificationPositive';
  85.  
  86.     stSubkeyBinding               : Result:= 'SubkeyBinding';
  87.     stPrimaryKeyBinding           : Result:= 'PrimaryKeyBinding';
  88.  
  89.     stDirectKey                   : Result:= 'DirectKey';
  90.  
  91.     stKeyRevocation               : Result:= 'KeyRevocation';
  92.     stSubKeyRevocation            : Result:= 'SubKeyRevocation';
  93.  
  94.     stCertificationRevocation     : Result:= 'CertificationRevocation';
  95.  
  96.     stTimestamp                   : Result:= 'Timestamp';
  97.  
  98.     stThirdPartyConfirmation      : Result:= 'ThirdPartyConfirmation';
  99.   else
  100.     Str(Ord(X), Result);
  101.   end;
  102. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement