diff options
author | vnugent <public@vaughnnugent.com> | 2024-09-06 20:50:06 -0400 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2024-09-06 20:50:06 -0400 |
commit | 7f1482c5d77b1b5f7e369ade925d2351d7623fa1 (patch) | |
tree | c99a0c8a0137e940492892977ef1e4f6f42b6d52 /src/Publishing/GpgSigner.cs | |
parent | 79d824cfb0e0cc9ff4fab0e0c546a83c0edaae1c (diff) |
cleanup and add fluent-ftp as an publishing location
Diffstat (limited to 'src/Publishing/GpgSigner.cs')
-rw-r--r-- | src/Publishing/GpgSigner.cs | 54 |
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 |