Files
annotations/Azaion.Common/Services/ResourceLoader.cs
T

22 lines
810 B
C#

using System.IO;
namespace Azaion.Common.Services;
public interface IResourceLoader
{
Task<MemoryStream> Load(string fileName, CancellationToken cancellationToken = default);
}
public class ResourceLoader(string email, string password, AzaionApiClient api, IHardwareService hardwareService) : IResourceLoader
{
public async Task<MemoryStream> Load(string fileName, CancellationToken cancellationToken = default)
{
var hardwareInfo = await hardwareService.GetHardware();
var encryptedStream = await api.GetResource(fileName, password, hardwareInfo);
var key = Security.MakeEncryptionKey(email, password, hardwareInfo.Hash);
var stream = new MemoryStream();
await encryptedStream.DecryptTo(stream, key, cancellationToken);
return stream;
}
}