wabbajack/Wabbajack.CLI/Verbs/Encrypt.cs

42 lines
1.4 KiB
C#
Raw Normal View History

2021-09-27 12:42:46 +00:00
using System.CommandLine;
using System.CommandLine.Invocation;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Wabbajack.Hashing.xxHash64;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
using Wabbajack.Services.OSIntegrated;
2020-01-31 22:38:56 +00:00
namespace Wabbajack.CLI.Verbs
{
2021-09-27 12:42:46 +00:00
public class Encrypt : IVerb
2020-01-31 22:38:56 +00:00
{
2021-09-27 12:42:46 +00:00
private readonly ILogger<Encrypt> _logger;
2020-01-31 22:38:56 +00:00
2021-09-27 12:42:46 +00:00
public Encrypt(ILogger<Encrypt> logger)
{
_logger = logger;
}
public Command MakeCommand()
{
var command = new Command("encrypt");
command.Add(new Option<AbsolutePath>(new[] { "-i", "-input" }, "Path to the file to enrypt"));
command.Add(new Option<string>(new[] { "-n", "-name" }, "Name of the key to store the data into"));
command.Description = "Encrypts a file and stores it in the Wabbajack encrypted storage";
command.Handler = CommandHandler.Create(Run);
return command;
}
public async Task<int> Run(AbsolutePath input, string name)
2020-01-31 22:38:56 +00:00
{
2021-09-27 12:42:46 +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")));
2020-01-31 22:38:56 +00:00
return 0;
}
}
2021-09-27 12:42:46 +00:00
}