public void GetUnixTicks_WhenTimeIsLocal_ItIsChangedToUtc() { var unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); var localTime = ChangeTimeToLocal(unixEpoch); Assert.AreEqual(0, UnixTime.GetUnixTicks(localTime)); }
/// <summary> /// TOTP = HOTP(K, T), where T is an integer and represents the number of time /// steps between the initial countertime T0 and the current Unix time. /// </summary> /// <param name="key"></param> /// <param name="time"></param> /// <returns></returns> public string GenerateOtp(byte[] key, DateTime time) { if (time < UnixTime.UnixEpochDate) { throw new ArgumentOutOfRangeException("time", "Time cannot be less than unix epoch"); } var stepsSinceUnixEpoch = (long)(UnixTime.GetUnixTicks(time) / DefaultTimeStep); return(_hotp.GenerateOtp(key, stepsSinceUnixEpoch)); }
public void GetUnixTicks_ReturnsPassedTicks() { var unixEpoch = new DateTime(2016, 6, 13, 16, 18, 33, DateTimeKind.Utc); Assert.AreEqual(1465834713, UnixTime.GetUnixTicks(unixEpoch)); }