|
| 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