KeyExpirationTime.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg.Sig
  5. {
  6. /**
  7. * packet giving time after creation at which the key expires.
  8. */
  9. public class KeyExpirationTime
  10. : SignatureSubpacket
  11. {
  12. protected static byte[] TimeToBytes(
  13. long t)
  14. {
  15. byte[] data = new byte[4];
  16. data[0] = (byte)(t >> 24);
  17. data[1] = (byte)(t >> 16);
  18. data[2] = (byte)(t >> 8);
  19. data[3] = (byte)t;
  20. return data;
  21. }
  22. public KeyExpirationTime(
  23. bool critical,
  24. bool isLongLength,
  25. byte[] data)
  26. : base(SignatureSubpacketTag.KeyExpireTime, critical, isLongLength, data)
  27. {
  28. }
  29. public KeyExpirationTime(
  30. bool critical,
  31. long seconds)
  32. : base(SignatureSubpacketTag.KeyExpireTime, critical, false, TimeToBytes(seconds))
  33. {
  34. }
  35. /**
  36. * Return the number of seconds after creation time a key is valid for.
  37. *
  38. * @return second count for key validity.
  39. */
  40. public long Time
  41. {
  42. get
  43. {
  44. long time = ((long)(data[0] & 0xff) << 24) | ((long)(data[1] & 0xff) << 16)
  45. | ((long)(data[2] & 0xff) << 8) | ((long)data[3] & 0xff);
  46. return time;
  47. }
  48. }
  49. }
  50. }
  51. #pragma warning restore
  52. #endif