Skip to content

Commit

Permalink
Add some CorePassSearchSpace tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Coding-Enthusiast committed Oct 30, 2024
1 parent 38d544e commit 79dbe76
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Src/FinderOuter/Services/SearchSpaces/CorePassSearchSpace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public bool Process(string hex, int passLength, out string error)
}
if (result.Length < 70)
{
error = $"Input hex was expected to be 70 bytes but it is {result.Length} bytes.";
error = $"Input hex is expected to be at least 70 bytes but it is {result.Length} bytes.";
return false;
}

Expand Down Expand Up @@ -138,6 +138,13 @@ public bool Process(string hex, int passLength, out string error)
AssertArray(salt, saltLen);
AssertArray(encKey, 48);
#endif

if (passLength < 1)
{
error = "Password length must be at least 1.";
return false;
}

PasswordLength = passLength;
Iteration = iteration;
Salt = salt;
Expand Down
95 changes: 95 additions & 0 deletions Src/Tests/Services/SearchSpaces/CorePassSearchSpaceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// The FinderOuter
// Copyright (c) 2020 Coding Enthusiast
// Distributed under the MIT software license, see the accompanying
// file LICENCE or http://www.opensource.org/licenses/mit-license.php.

using FinderOuter.Services.SearchSpaces;
using System.Collections.Generic;

namespace Tests.Services.SearchSpaces
{
public class CorePassSearchSpaceTests
{
public static IEnumerable<object[]> GetProcessCases()
{
// Taken from: https://bitcointalk.org/index.php?topic=5511431.msg64607294#msg64607294
yield return new object[]
{
"43000130ac71182a748152bb788fb9deb11f2f5a55f5e848d66586747cc000826d4c0c350032153d50cbf924a2ac1dc5f6279436089ca0271b64c0e66f00000000c6fe040000",
2,
true, string.Empty,
Helper.HexToBytes("9ca0271b64c0e66f"),
Helper.HexToBytes("55f5e848d66586747cc000826d4c0c35"),
327366
};
yield return new object[]
{
"43000130ac71182a748152bb788fb9deb11f2f5a55f5e848d66586747cc000826d4c0c350032153d50cbf924a2ac1dc5f6279436089ca0271b64c0e66f00000000c6fe040000",
0,
false, "Password length must be at least 1.",
null, null, 0
};
yield return new object[]
{
"43000130ac71182a748152bb788fb9deb11f2f5a55f5e848d66586747cc000826d4c0c350032153d50cbf924a2ac1dc5f6279436089ca0271b64c0e66f00000000c6fe040000",
-1,
false, "Password length must be at least 1.",
null, null, 0
};
yield return new object[]
{
null,
2,
false, "Input hex can not be null or empty.",
null, null, 0
};
yield return new object[]
{
"abcx",
2,
false, "Invalid character \"x\" found at index=3.",
null, null, 0
};
yield return new object[]
{
"abc",
2,
false, "Invalid hex string.",
null, null, 0
};
yield return new object[]
{
"abcd",
2,
false, "Input hex is expected to be at least 70 bytes but it is 2 bytes.",
null, null, 0
};
yield return new object[]
{
Helper.GetBytesHex(70),
2,
false, "Could not find 0x43000130 in the given hex.",
null, null, 0
};
}

[Theory]
[MemberData(nameof(GetProcessCases))]
public void ProcessTest(string hex, int passLength, bool expected, string expError, byte[] expSalt, byte[] expXor, int expIter)
{
CorePassSearchSpace searchSpace = new();
bool actual = searchSpace.Process(hex, passLength, out string error);

Assert.Equal(expected, actual);
Assert.Equal(expError, error);

if (expected)
{
Assert.Equal(searchSpace.PasswordLength, passLength);
Assert.Equal(searchSpace.Salt, expSalt);
Assert.Equal(searchSpace.XOR, expXor);
Assert.Equal(searchSpace.Iteration, expIter);
}
}
}
}

0 comments on commit 79dbe76

Please sign in to comment.