aboutsummaryrefslogtreecommitdiff
path: root/src/Publishing/GpgSigner.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Publishing/GpgSigner.cs')
-rw-r--r--src/Publishing/GpgSigner.cs54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/Publishing/GpgSigner.cs b/src/Publishing/GpgSigner.cs
new file mode 100644
index 0000000..3ed216a
--- /dev/null
+++ b/src/Publishing/GpgSigner.cs
@@ -0,0 +1,54 @@
+using System;
+using System.IO;
+using System.Threading.Tasks;
+using System.Collections.Generic;
+
+using VNLib.Tools.Build.Executor.Constants;
+
+namespace VNLib.Tools.Build.Executor.Publishing
+{
+ public sealed class GpgSigner(bool enabled, string? defaultKey)
+ {
+ public bool IsEnabled { get; } = enabled;
+
+ public async Task SignFileAsync(FileInfo file)
+ {
+ if (!IsEnabled)
+ {
+ return;
+ }
+
+ List<string> args = [
+ "--detach-sign"
+ ];
+
+ if (!string.IsNullOrWhiteSpace(defaultKey))
+ {
+ //Set the preferred key
+ args.Add("--default-key");
+ args.Add(defaultKey);
+ }
+
+ //Add input file
+ args.Add(file.FullName);
+
+ //Delete an original file
+ string sigFile = $"{file.FullName}.sig";
+ if (File.Exists(sigFile))
+ {
+ File.Delete(sigFile);
+ }
+
+ int result = await Utils.RunProcessAsync("gpg", null, args.ToArray());
+
+ switch (result)
+ {
+ case 2:
+ case 0:
+ break;
+ default:
+ throw new BuildFailedException($"Failed to sign file {file.FullName}");
+ }
+ }
+ }
+} \ No newline at end of file