wabbajack/Wabbajack.CLI/Verbs/Encrypt.cs

38 lines
1.2 KiB
C#
Raw Normal View History

2021-09-27 12:42:46 +00:00
using System.CommandLine;
using System.CommandLine.Invocation;
using System.CommandLine.NamingConventionBinder;
2021-09-27 12:42:46 +00:00
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Wabbajack.CLI.Builder;
2021-09-27 12:42:46 +00:00
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
using Wabbajack.Services.OSIntegrated;
2020-01-31 22:38:56 +00:00
2021-10-23 16:51:17 +00:00
namespace Wabbajack.CLI.Verbs;
public class Encrypt
2020-01-31 22:38:56 +00:00
{
2021-10-23 16:51:17 +00:00
private readonly ILogger<Encrypt> _logger;
public Encrypt(ILogger<Encrypt> logger)
2020-01-31 22:38:56 +00:00
{
2021-10-23 16:51:17 +00:00
_logger = logger;
}
2020-01-31 22:38:56 +00:00
2022-10-01 01:35:36 +00:00
public static VerbDefinition Definition = new("encrypt",
"Encrypts a file and stores it in the Wabbajack encrypted storage",
new[]
{
new OptionDefinition(typeof(AbsolutePath), "i", "input", "Path to the file to encrypt"),
new OptionDefinition(typeof(string), "n", "name", "Name of the key to store the data into")
});
2021-10-23 16:51:17 +00:00
2022-10-01 01:35:36 +00:00
internal async Task<int> Run(AbsolutePath input, string name)
2021-10-23 16:51:17 +00:00
{
var data = await input.ReadAllBytesAsync();
_logger.LogInformation("Encrypting {bytes} bytes into `{key}`", data.Length, name);
await data.AsEncryptedDataFile(name.ToRelativePath()
.RelativeTo(KnownFolders.WabbajackAppLocal.Combine("encrypted")));
return 0;
2020-01-31 22:38:56 +00:00
}
2021-09-27 12:42:46 +00:00
}