blob: 3ed216ab58d86a3e9cd482d0d88b663a5660eec9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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}");
}
}
}
}
|