KeyFlags.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg.Sig
  6. {
  7. /**
  8. * Packet holding the key flag values.
  9. */
  10. public class KeyFlags
  11. : SignatureSubpacket
  12. {
  13. public const int CertifyOther = 0x01;
  14. public const int SignData = 0x02;
  15. public const int EncryptComms = 0x04;
  16. public const int EncryptStorage = 0x08;
  17. public const int Split = 0x10;
  18. public const int Authentication = 0x20;
  19. public const int Shared = 0x80;
  20. private static byte[] IntToByteArray(
  21. int v)
  22. {
  23. byte[] tmp = new byte[4];
  24. int size = 0;
  25. for (int i = 0; i != 4; i++)
  26. {
  27. tmp[i] = (byte)(v >> (i * 8));
  28. if (tmp[i] != 0)
  29. {
  30. size = i;
  31. }
  32. }
  33. byte[] data = new byte[size + 1];
  34. Array.Copy(tmp, 0, data, 0, data.Length);
  35. return data;
  36. }
  37. public KeyFlags(
  38. bool critical,
  39. bool isLongLength,
  40. byte[] data)
  41. : base(SignatureSubpacketTag.KeyFlags, critical, isLongLength, data)
  42. {
  43. }
  44. public KeyFlags(
  45. bool critical,
  46. int flags)
  47. : base(SignatureSubpacketTag.KeyFlags, critical, false, IntToByteArray(flags))
  48. {
  49. }
  50. /// <summary>
  51. /// Return the flag values contained in the first 4 octets (note: at the moment
  52. /// the standard only uses the first one).
  53. /// </summary>
  54. public int Flags
  55. {
  56. get
  57. {
  58. int flags = 0;
  59. for (int i = 0; i != data.Length; i++)
  60. {
  61. flags |= (data[i] & 0xff) << (i * 8);
  62. }
  63. return flags;
  64. }
  65. }
  66. }
  67. }
  68. #pragma warning restore
  69. #endif