public void HotpFromMatchingHash(long binCode, int digitCount, string hotp, long expectedHotp) { "Given a desired HOTP length" .x(() => digitCount = 6); "And a truncated hash containing the same digits as the desired HOTP length" .x(() => binCode = expectedHotp = Faker.Random.Long(111111, 999999)); "When HOTP value is computed" .x(() => hotp = TestInstance.ExtractHotp(binCode, digitCount)); "Then the HOTP is the least significant 6 digits" .x(() => hotp.ShouldBe($"{expectedHotp}")); }
public void HotpFromShortHash(long hashMinimum, long hashMaximum, string expectedPadding, long binCode, int digitCount, string hotp, long expectedHotp) { "Given a desired HOTP length" .x(() => digitCount = 6); "And a truncated hash containing fewer digits than the desired HOTP length" .x(() => binCode = expectedHotp = Faker.Random.Long(hashMinimum, hashMaximum)); "When HOTP value is computed" .x(() => hotp = TestInstance.ExtractHotp(binCode, digitCount)); "Then the HOTP is the least significant 6 digits" .x(() => hotp.ShouldBe($"{expectedPadding}{expectedHotp}")); }
public void HotpFromLongHash(long binCode, int digitCount, string hotp, long expectedHotp) { "Given a desired HOTP length" .x(() => digitCount = 6); "And a truncated hash containing more digits than the desired HOTP length" .x(() => { // 2147483647 is the largest possible truncated hash value expectedHotp = Faker.Random.Long(111111, 483647); binCode = long.Parse($"{Faker.Random.Long(1, 2147)}{expectedHotp}"); }); "When HOTP value is computed" .x(() => hotp = TestInstance.ExtractHotp(binCode, digitCount)); "Then the HOTP is the least significant 6 digits" .x(() => hotp.ShouldBe($"{expectedHotp}")); }