Browse Source

Fixing issues reported in google code

master
Nathan Adams 8 years ago
parent
commit
5d1e6a1301
  1. 15
      otpnet/Libraries/Unixtime.cs
  2. 3
      otpnet/OTP/OTP.cs

15
otpnet/Libraries/Unixtime.cs

@ -5,20 +5,22 @@ using System.Text;
namespace OTPNet
{
// Issue reported by larry.ellis
// Patch provided by andrea.bertin
// https://code.google.com/p/otpnet/issues/detail?id=1
class Unixtime
{
private DateTime date;
private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
private readonly DateTime date;
public Unixtime()
{
this.date = DateTime.Now;
this.date = DateTime.UtcNow;
}
public Unixtime(int timestamp)
{
DateTime converted = new DateTime(1970, 1, 1, 0, 0, 0, 0);
DateTime newDateTime = converted.AddSeconds(timestamp);
this.date = newDateTime.ToLocalTime();
this.date = Epoch.AddSeconds(timestamp);
}
public DateTime toDateTime()
@ -28,8 +30,7 @@ namespace OTPNet
public long toTimeStamp()
{
TimeSpan span = (this.date - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).ToLocalTime());
return Convert.ToInt64(span.TotalSeconds);
return (long)this.date.Subtract(Epoch).TotalSeconds;
}
}
}

3
otpnet/OTP/OTP.cs

@ -67,6 +67,9 @@ namespace OTPNet
public OTP(string secret, int digits)
{
// Issue reported by scox.nz
// https://code.google.com/p/otpnet/issues/detail?id=2
this.secret = secret;
this.digits = digits;
this.digest = HashAlgorithm.SHA1;
}

Loading…
Cancel
Save