Răsfoiți Sursa

Add alternative KeyFile parameter to [ISSigKeys]. Also cleanup a leftover LowerCase on the PublicY parameter.

Martijn Laan 4 luni în urmă
părinte
comite
38b9393df1

+ 15 - 0
Components/ISSigFunc.pas

@@ -37,6 +37,8 @@ procedure ISSigExportPrivateKeyText(const AKey: TECDSAKey;
   var APrivateKeyText: String);
 procedure ISSigExportPublicKeyText(const AKey: TECDSAKey;
   var APublicKeyText: String);
+procedure ISSigExportPublicKeyXY(const AKey: TECDSAKey;
+  out APublicX, APublicY: String);
 function ISSigImportKeyText(const AKey: TECDSAKey; const AText: String;
   const ANeedPrivateKey: Boolean): TISSigImportKeyResult;
 function ISSigImportPublicKey(const AKey: TECDSAKey;
@@ -283,6 +285,19 @@ begin
   end;
 end;
 
+procedure ISSigExportPublicKeyXY(const AKey: TECDSAKey;
+  out APublicX, APublicY: String);
+begin
+  var PublicKey: TECDSAPublicKey;
+  try
+    AKey.ExportPublicKey(PublicKey);
+    APublicX := ECDSAInt256ToString(PublicKey.Public_x);
+    APublicY := ECDSAInt256ToString(PublicKey.Public_y);
+  finally
+    PublicKey.Clear;
+  end;
+end;
+
 function ISSigImportKeyText(const AKey: TECDSAKey; const AText: String;
   const ANeedPrivateKey: Boolean): TISSigImportKeyResult;
 var

+ 6 - 2
Projects/Src/Compiler.Messages.pas

@@ -202,6 +202,7 @@ const
   SCompilerParamDataTooLong = 'Data on parameter "%s" is too long';
   SCompilerParamUnknownParam = 'Unrecognized parameter name "%s"';
   SCompilerParamDuplicated = 'Cannot have multiple "%s" parameters';
+  SCompilerParamConflict = 'Cannot have both the "%s" and "%s" parameters';
   SCompilerParamEmpty2 = 'Parameter "%s" is empty';
   SCompilerParamNotSpecified = 'Required parameter "%s" not specified';
   SCompilerParamNoQuotes2 = 'Parameter "%s" cannot include quotes (")';
@@ -246,9 +247,12 @@ const
   SCompilerComponentsOrTasksBadName = 'Parameter "Name" includes invalid characters.' + SNewLine2 +
     'It may only include alphanumeric characters, underscores, slashes (/), and/or backslashes (\), may not start with a number and may not start or end with a slash or a backslash. Names ''not'', ''and'' and ''or'' are reserved';
   SCompilerComponentsInvalidLevel = 'Component cannot be more than one level below the preceding component';
-  SCompilerTasksInvalidLevel = 'Task cannot be more than one level below the preceding task'; 
+  SCompilerTasksInvalidLevel = 'Task cannot be more than one level below the preceding task';
   SCompilerLanguagesOrISSigKeysBadName = 'Parameter "Name" includes invalid characters.' + SNewLine2 + 'It may only include alphanumeric characters and/or underscores, and may not start with a number. Names ''not'', ''and'' and ''or'' are reserved';
-  SCompilerISSigKeysBadKeyID = 'Value of parameter "KeyID" is not valid for given "PublicX" and "PublicY" values.';
+  SCompilerISSigKeysKeyNotSpecified = 'Required parameter(s) "KeyFile" or "PublicX"/"PublicY" not specified';
+  SCompilerISSigKeysBadKeyID = 'Value of parameter "KeyID" is not valid for given "KeyFile" or "PublicX"/"PublicY" values.';
+  SCompilerISSigKeysBadKeyFile = 'Key file is malformed';
+  SCompilerISSigKeysUnknownKeyImportResult = 'Unknown import key result';
 
   { [Languages] }
   SCompilerParamUnknownLanguage = 'Parameter "%s" includes an unknown language';

+ 43 - 14
Projects/Src/Compiler.SetupCompiler.pas

@@ -4469,17 +4469,19 @@ end;
 
 procedure TSetupCompiler.EnumISSigKeysProc(const Line: PChar; const Ext: Integer);
 type
-  TParam = (paName, paKeyID, paPublicX, paPublicY);
+  TParam = (paName, paKeyFile, paKeyID, paPublicX, paPublicY);
 const
   ParamISSigKeysName = 'Name';
+  ParamISSigKeysKeyFile = 'KeyFile';
   ParamISSigKeysKeyID = 'KeyID';
   ParamISSigKeysPublicX = 'PublicX';
   ParamISSigKeysPublicY = 'PublicY';
   ParamInfo: array[TParam] of TParamInfo = (
     (Name: ParamISSigKeysName; Flags: [piRequired, piNoEmpty]),
+    (Name: ParamISSigKeysKeyFile; Flags: [piNoEmpty]),
     (Name: ParamISSigKeysKeyID; Flags: [piNoEmpty]),
-    (Name: ParamISSigKeysPublicX; Flags: [piRequired, piNoEmpty]),
-    (Name: ParamISSigKeysPublicY; Flags: [piRequired, piNoEmpty]));
+    (Name: ParamISSigKeysPublicX; Flags: [piNoEmpty]),
+    (Name: ParamISSigKeysPublicY; Flags: [piNoEmpty]));
 var
   Values: array[TParam] of TParamValue;
   NewISSigKeyEntry: PSetupISSigKeyEntry;
@@ -4494,18 +4496,45 @@ begin
         AbortCompile(SCompilerLanguagesOrISSigKeysBadName);
       Name := LowerCase(Values[paName].Data);
 
-      { PublicX & PublicY }
+      { KeyFile & PublicX & PublicY }
+      var KeyFile := Values[paKeyFile].Data;
       PublicX := Values[paPublicX].Data;
-      try
-        ISSigCheckValidPublicXOrY(PublicX);
-      except
-        AbortCompileFmt(SCompilerParamInvalidWithError, [ParamISSigKeysPublicX, GetExceptMessage]);
-      end;
-      PublicY := LowerCase(Values[paPublicY].Data);
-      try
-        ISSigCheckValidPublicXOrY(PublicY);
-      except
-        AbortCompileFmt(SCompilerParamInvalidWithError, [ParamISSigKeysPublicY, GetExceptMessage]);
+      PublicY := Values[paPublicY].Data;
+
+      if (KeyFile = '') and (PublicX = '') and (PublicY = '') then
+        AbortCompile(SCompilerISSigKeysKeyNotSpecified)
+      else if KeyFile <> '' then begin
+        if PublicX <> '' then
+          AbortCompileFmt(SCompilerParamConflict, [ParamISSigKeysKeyFile, ParamISSigKeysPublicX])
+        else if PublicY <> '' then
+          AbortCompileFmt(SCompilerParamConflict, [ParamISSigKeysKeyFile, ParamISSigKeysPublicY]);
+        var Key := TECDSAKey.Create;
+        try
+          var SigText := ISSigLoadTextFromFile(KeyFile);
+          const ImportResult = ISSigImportKeyText(Key, SigText, False);
+          if ImportResult = ikrMalformed then
+            AbortCompile(SCompilerISSigKeysBadKeyFile)
+          else if ImportResult <> ikrSuccess then
+            AbortCompile(SCompilerISSigKeysUnknownKeyImportResult);
+          ISSigExportPublicKeyXY(Key, PublicX, PublicY);
+        finally
+          Key.Free;
+        end;
+      end else begin
+        if PublicX = '' then
+          AbortCompileParamError(SCompilerParamNotSpecified, ParamISSigKeysPublicX)
+        else if PublicY = '' then
+          AbortCompileParamError(SCompilerParamNotSpecified, ParamISSigKeysPublicY);
+        try
+          ISSigCheckValidPublicXOrY(PublicX);
+        except
+          AbortCompileFmt(SCompilerParamInvalidWithError, [ParamISSigKeysPublicX, GetExceptMessage]);
+        end;
+        try
+          ISSigCheckValidPublicXOrY(PublicY);
+        except
+          AbortCompileFmt(SCompilerParamInvalidWithError, [ParamISSigKeysPublicY, GetExceptMessage]);
+        end;
       end;
 
       { KeyID }

+ 1 - 1
Projects/Src/IDE.ScintStylerInnoSetup.pas

@@ -235,7 +235,7 @@ const
   ];
 
   ISSigKeysSectionParameters: array of TScintRawString = [
-    'Name', 'KeyID', 'PublicX', 'PublicY'
+    'Name', 'KeyFile', 'KeyID', 'PublicX', 'PublicY'
   ];
 
   FilesSectionParameters: array of TScintRawString = [