Skip to content

Commit

Permalink
Enable tests for WASM runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
dorssel committed Jan 5, 2025
1 parent 33748fc commit 66c5535
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 28 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/runtime-browser-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,17 @@ jobs:
-S xmss-library
-B build
-DXMSS_C99_COMPATIBLE=OFF
-DXMSS_BUILD_TESTS=OFF
-DCMAKE_EXE_LINKER_FLAGS="-s NODERAWFS=1"
- name: Build
run: cmake --build build

- name: Test
working-directory: build
env:
NODE_OPTIONS: --no-experimental-fetch
run: ctest

- name: Copy artifact
run: |
mkdir -p "Xmss/runtimes/${{ env.RUNTIME }}/nativeassets"
Expand Down
46 changes: 21 additions & 25 deletions Xmss/XmssFileStateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,20 @@
namespace Dorssel.Security.Cryptography;

/// <summary>
/// TODO
/// Manages the state of an XMSS key as files in a given folder.
/// </summary>
/// <param name="path">TODO</param>
/// <remarks>
/// The folder given by <paramref name="path"/> must already exist; it will not be created.
/// <para>
/// This class will manage the following three files within the folder:
/// <list type="bullet">
/// <item><c>xmss_private_stateless</c></item>
/// <item><c>xmss_private_stateful</c></item>
/// <item><c>xmss_public</c></item>
/// </list>
/// </para>
/// </remarks>
/// <param name="path">The path to the folder holding the state files.</param>
public sealed class XmssFileStateManager(string path)
: IXmssStateManager
{
Expand Down Expand Up @@ -37,24 +48,15 @@ string GetPath(XmssKeyPart part)
return TryGetPath(part, out var partPath) ? partPath : throw new ArgumentOutOfRangeException(nameof(part));
}

/// <summary>
/// TODO
/// </summary>
/// <param name="part">TODO</param>
/// <param name="data">TODO</param>
/// <inheritdoc/>
public void Store(XmssKeyPart part, ReadOnlySpan<byte> data)
{
using var file = File.Open(GetPath(part), FileMode.CreateNew);
file.Write(data);
file.Flush();
}

/// <summary>
/// TODO
/// </summary>
/// <param name="expected">TODO</param>
/// <param name="data">TODO</param>
/// <exception cref="ArgumentException">TODO</exception>
/// <inheritdoc/>
public void StoreStatefulPart(ReadOnlySpan<byte> expected, ReadOnlySpan<byte> data)
{
if (data.Length != expected.Length)
Expand Down Expand Up @@ -85,12 +87,7 @@ public void StoreStatefulPart(ReadOnlySpan<byte> expected, ReadOnlySpan<byte> da
file.Flush();
}

/// <summary>
/// TODO
/// </summary>
/// <param name="part">TODO</param>
/// <param name="destination">TODO</param>
/// <exception cref="ArgumentException">TODO</exception>
/// <inheritdoc/>
public void Load(XmssKeyPart part, Span<byte> destination)
{
using var file = File.OpenRead(GetPath(part));
Expand All @@ -101,9 +98,7 @@ public void Load(XmssKeyPart part, Span<byte> destination)
file.ReadExactly(destination);
}

/// <summary>
/// TODO
/// </summary>
/// <inheritdoc/>
public void DeletePublicPart()
{
File.Delete(GetPath(XmssKeyPart.Public));
Expand Down Expand Up @@ -138,9 +133,10 @@ static void SecureDelete(string path)
File.Delete(path);
}

/// <summary>
/// TODO
/// </summary>
/// <inheritdoc path="/summary"/>
/// <remarks>
/// This method overwrites files containing private data with zeros before deleting the file.
/// </remarks>
public void Purge()
{
SecureDelete(GetPath(XmssKeyPart.PrivateStateless));
Expand Down
14 changes: 12 additions & 2 deletions Xmss/XmssMemoryStateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
namespace Dorssel.Security.Cryptography;

/// <summary>
/// TODO
/// Manages the state of an XMSS key in process memory.
/// </summary>
/// <remarks>
/// The maximum lifetime of the key is bound to the lifetime of the current process.
/// <para>This class implements <see cref="IDisposable"/> to ensure the memory is securely erased before being freed.</para>
/// </remarks>
public sealed class XmssMemoryStateManager()
: IXmssStateManager, IDisposable
{
Expand Down Expand Up @@ -103,7 +107,10 @@ public void DeletePublicPart()
}
}

/// <inheritdoc/>
/// <inheritdoc path="/summary"/>
/// <remarks>
/// This method overwrites memory containing private data with zeros before freeing the memory.
/// </remarks>
public void Purge()
{
lock (State)
Expand All @@ -121,6 +128,9 @@ public void Purge()
bool IsDisposed;

/// <inheritdoc/>
/// <remarks>
/// This method calls <see cref="Purge"/> to ensure that any private data is purged before the memory is freed.
/// </remarks>
public void Dispose()
{
lock (State)
Expand Down

0 comments on commit 66c5535

Please sign in to comment.