Skip to content

Commit 79dbe76

Browse files
Add some CorePassSearchSpace tests
1 parent 38d544e commit 79dbe76

File tree

2 files changed

+103
-1
lines changed

2 files changed

+103
-1
lines changed

Src/FinderOuter/Services/SearchSpaces/CorePassSearchSpace.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public bool Process(string hex, int passLength, out string error)
5050
}
5151
if (result.Length < 70)
5252
{
53-
error = $"Input hex was expected to be 70 bytes but it is {result.Length} bytes.";
53+
error = $"Input hex is expected to be at least 70 bytes but it is {result.Length} bytes.";
5454
return false;
5555
}
5656

@@ -138,6 +138,13 @@ public bool Process(string hex, int passLength, out string error)
138138
AssertArray(salt, saltLen);
139139
AssertArray(encKey, 48);
140140
#endif
141+
142+
if (passLength < 1)
143+
{
144+
error = "Password length must be at least 1.";
145+
return false;
146+
}
147+
141148
PasswordLength = passLength;
142149
Iteration = iteration;
143150
Salt = salt;
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// The FinderOuter
2+
// Copyright (c) 2020 Coding Enthusiast
3+
// Distributed under the MIT software license, see the accompanying
4+
// file LICENCE or http://www.opensource.org/licenses/mit-license.php.
5+
6+
using FinderOuter.Services.SearchSpaces;
7+
using System.Collections.Generic;
8+
9+
namespace Tests.Services.SearchSpaces
10+
{
11+
public class CorePassSearchSpaceTests
12+
{
13+
public static IEnumerable<object[]> GetProcessCases()
14+
{
15+
// Taken from: https://bitcointalk.org/index.php?topic=5511431.msg64607294#msg64607294
16+
yield return new object[]
17+
{
18+
"43000130ac71182a748152bb788fb9deb11f2f5a55f5e848d66586747cc000826d4c0c350032153d50cbf924a2ac1dc5f6279436089ca0271b64c0e66f00000000c6fe040000",
19+
2,
20+
true, string.Empty,
21+
Helper.HexToBytes("9ca0271b64c0e66f"),
22+
Helper.HexToBytes("55f5e848d66586747cc000826d4c0c35"),
23+
327366
24+
};
25+
yield return new object[]
26+
{
27+
"43000130ac71182a748152bb788fb9deb11f2f5a55f5e848d66586747cc000826d4c0c350032153d50cbf924a2ac1dc5f6279436089ca0271b64c0e66f00000000c6fe040000",
28+
0,
29+
false, "Password length must be at least 1.",
30+
null, null, 0
31+
};
32+
yield return new object[]
33+
{
34+
"43000130ac71182a748152bb788fb9deb11f2f5a55f5e848d66586747cc000826d4c0c350032153d50cbf924a2ac1dc5f6279436089ca0271b64c0e66f00000000c6fe040000",
35+
-1,
36+
false, "Password length must be at least 1.",
37+
null, null, 0
38+
};
39+
yield return new object[]
40+
{
41+
null,
42+
2,
43+
false, "Input hex can not be null or empty.",
44+
null, null, 0
45+
};
46+
yield return new object[]
47+
{
48+
"abcx",
49+
2,
50+
false, "Invalid character \"x\" found at index=3.",
51+
null, null, 0
52+
};
53+
yield return new object[]
54+
{
55+
"abc",
56+
2,
57+
false, "Invalid hex string.",
58+
null, null, 0
59+
};
60+
yield return new object[]
61+
{
62+
"abcd",
63+
2,
64+
false, "Input hex is expected to be at least 70 bytes but it is 2 bytes.",
65+
null, null, 0
66+
};
67+
yield return new object[]
68+
{
69+
Helper.GetBytesHex(70),
70+
2,
71+
false, "Could not find 0x43000130 in the given hex.",
72+
null, null, 0
73+
};
74+
}
75+
76+
[Theory]
77+
[MemberData(nameof(GetProcessCases))]
78+
public void ProcessTest(string hex, int passLength, bool expected, string expError, byte[] expSalt, byte[] expXor, int expIter)
79+
{
80+
CorePassSearchSpace searchSpace = new();
81+
bool actual = searchSpace.Process(hex, passLength, out string error);
82+
83+
Assert.Equal(expected, actual);
84+
Assert.Equal(expError, error);
85+
86+
if (expected)
87+
{
88+
Assert.Equal(searchSpace.PasswordLength, passLength);
89+
Assert.Equal(searchSpace.Salt, expSalt);
90+
Assert.Equal(searchSpace.XOR, expXor);
91+
Assert.Equal(searchSpace.Iteration, expIter);
92+
}
93+
}
94+
}
95+
}

0 commit comments

Comments
 (0)