SignatureCreationTime.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Date;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg.Sig
  6. {
  7. /**
  8. * packet giving signature creation time.
  9. */
  10. public class SignatureCreationTime
  11. : SignatureSubpacket
  12. {
  13. protected static byte[] TimeToBytes(
  14. DateTime time)
  15. {
  16. long t = DateTimeUtilities.DateTimeToUnixMs(time) / 1000L;
  17. byte[] data = new byte[4];
  18. data[0] = (byte)(t >> 24);
  19. data[1] = (byte)(t >> 16);
  20. data[2] = (byte)(t >> 8);
  21. data[3] = (byte)t;
  22. return data;
  23. }
  24. public SignatureCreationTime(
  25. bool critical,
  26. bool isLongLength,
  27. byte[] data)
  28. : base(SignatureSubpacketTag.CreationTime, critical, isLongLength, data)
  29. {
  30. }
  31. public SignatureCreationTime(
  32. bool critical,
  33. DateTime date)
  34. : base(SignatureSubpacketTag.CreationTime, critical, false, TimeToBytes(date))
  35. {
  36. }
  37. public DateTime GetTime()
  38. {
  39. long time = (long)(
  40. ((uint)data[0] << 24)
  41. | ((uint)data[1] << 16)
  42. | ((uint)data[2] << 8)
  43. | ((uint)data[3])
  44. );
  45. return DateTimeUtilities.UnixMsToDateTime(time * 1000L);
  46. }
  47. }
  48. }
  49. #pragma warning restore
  50. #endif