Skip to content

Commit

Permalink
Extracted ArrayExtensions to clear arrays.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesper Glintborg authored and somdoron committed Jul 24, 2020
1 parent 93e472b commit aee0c42
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
17 changes: 17 additions & 0 deletions NaCl.net/ArrayExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Runtime.CompilerServices;

namespace NetMQ.Utils
{
internal static class ArrayExtensions
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Clear<T>(this T[] array)
{
if (array != null)
{
Array.Clear(array, 0, array.Length);
}
}
}
}
6 changes: 4 additions & 2 deletions NaCl.net/Internal/StreamSalsa20.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Runtime.CompilerServices;
using NetMQ.Utils;

namespace NaCl.Internal
{
Expand Down Expand Up @@ -48,8 +49,9 @@ static public void Transform(Span<byte> c, ReadOnlySpan<byte> n, ReadOnlySpan<by
}
finally
{
Array.Clear(block, 0, block.Length);
Array.Clear(kcopy, 0, kcopy.Length);
input.Clear();
block.Clear();
kcopy.Clear();
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions NaCl.net/Internal/StreamSalsa20Xor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Runtime.CompilerServices;
using NetMQ.Utils;

namespace NaCl.Internal
{
Expand Down Expand Up @@ -62,8 +63,9 @@ public static void Transform(Span<byte> c, ReadOnlySpan<byte> m, ReadOnlySpan<by
}
finally
{
Array.Clear(block, 0, block.Length);
Array.Clear(kcopy, 0, kcopy.Length);
input.Clear();
block.Clear();
kcopy.Clear();
}
}
}
Expand Down

0 comments on commit aee0c42

Please sign in to comment.