Add save data transfer sf interfaces

This commit is contained in:
Alex Barney 2021-01-05 01:27:25 -07:00
parent f2f68958a8
commit 5367d7c5cd
16 changed files with 270 additions and 2 deletions

View file

@ -21,7 +21,7 @@ namespace LibHac.Boot
private IStorage _storage;
private Package2Header _header;
private KeySet _keySet;
private AesKey _key;
private Crypto.AesKey _key;
public ref readonly Package2Header Header => ref _header;

View file

@ -45,7 +45,7 @@ namespace LibHac.Crypto
[FieldOffset(0)] private ulong _ulong;
[FieldOffset(0)] public AesKey DataKey;
[FieldOffset(0)] public AesKey TweakKey;
[FieldOffset(0x10)] public AesKey TweakKey;
public Span<byte> Data => SpanHelpers.CreateSpan(ref _byte, Size);
public readonly ReadOnlySpan<byte> DataRo => SpanHelpers.CreateReadOnlySpan(in _byte, Size);

View file

@ -0,0 +1,54 @@
using System;
using System.Runtime.InteropServices;
using LibHac.Common;
namespace LibHac.Fs.Impl
{
[StructLayout(LayoutKind.Sequential, Size = 0x20)]
public struct InitialDataAad
{
public byte this[int i]
{
readonly get => BytesRo[i];
set => Bytes[i] = value;
}
public Span<byte> Bytes => SpanHelpers.AsByteSpan(ref this);
public readonly ReadOnlySpan<byte> BytesRo => SpanHelpers.AsReadOnlyByteSpan(in this);
}
[StructLayout(LayoutKind.Sequential, Size = 0x10)]
public struct KeySeed
{
public byte this[int i]
{
readonly get => BytesRo[i];
set => Bytes[i] = value;
}
public Span<byte> Bytes => SpanHelpers.AsByteSpan(ref this);
public readonly ReadOnlySpan<byte> BytesRo => SpanHelpers.AsReadOnlyByteSpan(in this);
}
[StructLayout(LayoutKind.Sequential, Size = 0x10)]
public struct InitialDataMac
{
public byte this[int i]
{
readonly get => BytesRo[i];
set => Bytes[i] = value;
}
public Span<byte> Bytes => SpanHelpers.AsByteSpan(ref this);
public readonly ReadOnlySpan<byte> BytesRo => SpanHelpers.AsReadOnlyByteSpan(in this);
}
[StructLayout(LayoutKind.Sequential, Size = 0x20)]
public struct ImportReportInfo
{
public byte DiffChunkCount;
public byte DoubleDivisionDiffChunkCount;
public byte HalfDivisionDiffChunkCount;
public byte CompressionRate;
}
}

View file

@ -0,0 +1,33 @@
using System;
using System.Runtime.InteropServices;
using LibHac.Common;
namespace LibHac.Fs
{
[StructLayout(LayoutKind.Sequential, Size = 0x100)]
public struct RsaEncryptedKey
{
public byte this[int i]
{
readonly get => BytesRo[i];
set => Bytes[i] = value;
}
public Span<byte> Bytes => SpanHelpers.AsByteSpan(ref this);
public readonly ReadOnlySpan<byte> BytesRo => SpanHelpers.AsReadOnlyByteSpan(in this);
}
[StructLayout(LayoutKind.Sequential, Size = 0x10)]
public struct AesKey
{
public byte this[int i]
{
readonly get => BytesRo[i];
set => Bytes[i] = value;
}
public Span<byte> Bytes => SpanHelpers.AsByteSpan(ref this);
public readonly ReadOnlySpan<byte> BytesRo => SpanHelpers.AsReadOnlyByteSpan(in this);
}
}

View file

@ -0,0 +1,11 @@
using System;
using LibHac.Sf;
namespace LibHac.FsSrv.Sf
{
public interface ISaveDataChunkExporter : IDisposable
{
public Result Pull(out ulong bytesRead, OutBuffer buffer, ulong size);
public Result GetRestRawDataSize(out long remainingSize);
}
}

View file

@ -0,0 +1,10 @@
using System;
using LibHac.Sf;
namespace LibHac.FsSrv.Sf
{
public interface ISaveDataChunkImporter : IDisposable
{
public Result Push(InBuffer buffer, ulong size);
}
}

View file

@ -0,0 +1,11 @@
using System;
namespace LibHac.FsSrv.Sf
{
public interface ISaveDataChunkIterator : IDisposable
{
public Result Next();
public Result IsEnd(out bool isEnd);
public Result GetId(out uint chunkId);
}
}

View file

@ -0,0 +1,23 @@
using System;
using LibHac.Fs.Impl;
using LibHac.Sf;
namespace LibHac.FsSrv.Sf
{
public interface ISaveDataDivisionExporter : IDisposable
{
public Result SetDivisionCount(int divisionCount);
public Result ReadSaveDataExtraData(OutBuffer extraData);
public Result OpenSaveDataDiffChunkIterator(out ReferenceCountedDisposable<ISaveDataChunkIterator> iterator);
public Result OpenSaveDataChunkExporter(out ReferenceCountedDisposable<ISaveDataChunkExporter> exporter, uint chunkId);
public Result CancelExport();
public Result SuspendExport(OutBuffer exportContext);
public Result GetKeySeed(out KeySeed keySeed);
public Result GetInitialDataMac(out InitialDataMac initialDataMac);
public Result FinalizeExport();
public Result GetInitialDataMacKeyGeneration(out int keyGeneration);
public Result GetImportInitialDataAad(out InitialDataAad initialDataAad);
public Result SetExportInitialDataAad(in InitialDataAad initialDataAad);
public Result GetReportInfo(out ImportReportInfo reportInfo);
}
}

View file

@ -0,0 +1,21 @@
using System;
using LibHac.Fs.Impl;
using LibHac.Sf;
namespace LibHac.FsSrv.Sf
{
public interface ISaveDataDivisionImporter : IDisposable
{
public Result ReadSaveDataExtraData(OutBuffer extraData);
public Result OpenSaveDataDiffChunkIterator(out ReferenceCountedDisposable<ISaveDataChunkIterator> iterator);
public Result InitializeImport(out long remaining, long sizeToProcess);
public Result FinalizeImport();
public Result CancelImport();
public Result GetImportContext(OutBuffer context);
public Result SuspendImport();
public Result FinalizeImportWithoutSwap();
public Result OpenSaveDataChunkImporter(out ReferenceCountedDisposable<ISaveDataChunkImporter> importer, uint chunkId);
public Result GetImportInitialDataAad(out InitialDataAad initialDataAad);
public Result GetReportInfo(out ImportReportInfo reportInfo);
}
}

View file

@ -0,0 +1,14 @@
using System;
using LibHac.Fs;
using LibHac.Sf;
namespace LibHac.FsSrv.Sf
{
public interface ISaveDataExporter : IDisposable
{
public Result GetSaveDataInfo(out SaveDataInfo info);
public Result GetRestSize(out ulong remainingSize);
public Result Pull(out ulong bytesRead, OutBuffer buffer);
public Result PullInitialData(OutBuffer initialData);
}
}

View file

@ -0,0 +1,15 @@
using System;
using LibHac.Fs;
using LibHac.Sf;
namespace LibHac.FsSrv.Sf
{
public interface ISaveDataImporter : IDisposable
{
public Result GetSaveDataInfo(out SaveDataInfo info);
public Result GetRestSize(out ulong remainingSize);
public Result Push(InBuffer buffer);
// Can't name the method "Finalize" because it's basically a reserved method in .NET
public Result FinalizeImport();
}
}

View file

@ -0,0 +1,14 @@
using System;
using LibHac.Fs;
using LibHac.Sf;
namespace LibHac.FsSrv.Sf
{
public interface ISaveDataTransferManager : IDisposable
{
public Result GetChallenge(OutBuffer challenge);
public Result SetToken(InBuffer token);
public Result OpenSaveDataExporter(out ReferenceCountedDisposable<ISaveDataExporter> exporter, SaveDataSpaceId spaceId, ulong saveDataId);
public Result OpenSaveDataImporter(out ReferenceCountedDisposable<ISaveDataImporter> importer, out long requiredSize, InBuffer initialData, in UserId userId, SaveDataSpaceId spaceId);
}
}

View file

@ -0,0 +1,12 @@
using System;
using LibHac.Fs;
using LibHac.Sf;
namespace LibHac.FsSrv.Sf
{
public interface ISaveDataTransferManagerForRepair : IDisposable
{
public Result OpenSaveDataExporter(out ReferenceCountedDisposable<ISaveDataDivisionExporter> exporter, SaveDataSpaceId spaceId, ulong saveDataId);
public Result OpenSaveDataImporter(out ReferenceCountedDisposable<ISaveDataDivisionImporter> importer, InBuffer initialData, SaveDataSpaceId spaceId);
}
}

View file

@ -0,0 +1,18 @@
using System;
using LibHac.Fs;
using LibHac.Sf;
namespace LibHac.FsSrv.Sf
{
public interface ISaveDataTransferManagerForSaveDataRepair : IDisposable
{
public Result GetChallenge(OutBuffer challenge);
public Result SetKeyPackage(InBuffer keyPackage);
public Result OpenSaveDataExporterAndGetEncryptedKey(out ReferenceCountedDisposable<ISaveDataDivisionExporter> exporter, out RsaEncryptedKey key, SaveDataSpaceId spaceId, ulong saveDataId);
public Result PrepareOpenSaveDataImporter(out RsaEncryptedKey key);
public Result OpenSaveDataImporterForSaveDataAfterRepair(out ReferenceCountedDisposable<ISaveDataDivisionImporter> importer, InBuffer initialDataBeforeRepair, InBuffer initialDataAfterRepair, UserId userId, SaveDataSpaceId spaceId);
public Result OpenSaveDataImporterForSaveDataBeforeRepair(out ReferenceCountedDisposable<ISaveDataDivisionImporter> importer, InBuffer initialData, UserId userId, SaveDataSpaceId spaceId);
public Result OpenSaveDataExporterWithKey(out ReferenceCountedDisposable<ISaveDataDivisionExporter> exporter, in AesKey key, SaveDataSpaceId spaceId, ulong saveDataId);
public Result OpenSaveDataImporterWithKey(out ReferenceCountedDisposable<ISaveDataDivisionImporter> importer, in AesKey key, InBuffer initialData, UserId userId, ulong saveDataSpaceId);
}
}

View file

@ -0,0 +1,23 @@
using System;
using LibHac.Fs;
using LibHac.Sf;
namespace LibHac.FsSrv.Sf
{
public interface ISaveDataTransferManagerWithDivision : IDisposable
{
public Result GetChallenge(OutBuffer challenge);
public Result SetKeySeedPackage(InBuffer keySeedPackage);
public Result OpenSaveDataExporter(out ReferenceCountedDisposable<ISaveDataDivisionExporter> exporter, SaveDataSpaceId spaceId, ulong saveDataId);
public Result OpenSaveDataExporterForDiffExport(out ReferenceCountedDisposable<ISaveDataDivisionExporter> exporter, InBuffer initialData, SaveDataSpaceId spaceId, ulong saveDataId);
public Result OpenSaveDataExporterByContext(out ReferenceCountedDisposable<ISaveDataDivisionExporter> exporter, InBuffer exportContext);
public Result OpenSaveDataImporterDeprecated(out ReferenceCountedDisposable<ISaveDataDivisionImporter> importer, InBuffer initialData, in UserId userId, SaveDataSpaceId spaceId);
public Result OpenSaveDataImporterForDiffImport(out ReferenceCountedDisposable<ISaveDataDivisionImporter> importer, InBuffer initialData, SaveDataSpaceId spaceId, ulong saveDataId);
public Result OpenSaveDataImporterForDuplicateDiffImport(out ReferenceCountedDisposable<ISaveDataDivisionImporter> importer, InBuffer initialData, SaveDataSpaceId spaceId, ulong saveDataId);
public Result OpenSaveDataImporter(out ReferenceCountedDisposable<ISaveDataDivisionImporter> importer, InBuffer initialData, in UserId userId, SaveDataSpaceId spaceId, bool useSwap);
public Result OpenSaveDataImporterByContext(out ReferenceCountedDisposable<ISaveDataDivisionImporter> importer, InBuffer importContext);
public Result CancelSuspendingImport(Ncm.ApplicationId applicationId, in UserId userId);
public Result CancelSuspendingImportByAttribute(in SaveDataAttribute attribute);
public Result SwapSecondary(in SaveDataAttribute attribute, bool doSwap, long primaryCommitId);
}
}

View file

@ -0,0 +1,9 @@
using System;
namespace LibHac.FsSrv.Sf
{
public interface ISaveDataTransferProhibiter : IDisposable
{
// No methods. Disposing the service object removes the prohibition.
}
}