OnePassSignaturePacket.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.IO;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
  6. {
  7. /// <remarks>Generic signature object</remarks>
  8. public class OnePassSignaturePacket
  9. : ContainedPacket
  10. {
  11. private int version;
  12. private int sigType;
  13. private HashAlgorithmTag hashAlgorithm;
  14. private PublicKeyAlgorithmTag keyAlgorithm;
  15. private long keyId;
  16. private int nested;
  17. internal OnePassSignaturePacket(
  18. BcpgInputStream bcpgIn)
  19. {
  20. version = bcpgIn.ReadByte();
  21. sigType = bcpgIn.ReadByte();
  22. hashAlgorithm = (HashAlgorithmTag) bcpgIn.ReadByte();
  23. keyAlgorithm = (PublicKeyAlgorithmTag) bcpgIn.ReadByte();
  24. keyId |= (long)bcpgIn.ReadByte() << 56;
  25. keyId |= (long)bcpgIn.ReadByte() << 48;
  26. keyId |= (long)bcpgIn.ReadByte() << 40;
  27. keyId |= (long)bcpgIn.ReadByte() << 32;
  28. keyId |= (long)bcpgIn.ReadByte() << 24;
  29. keyId |= (long)bcpgIn.ReadByte() << 16;
  30. keyId |= (long)bcpgIn.ReadByte() << 8;
  31. keyId |= (uint)bcpgIn.ReadByte();
  32. nested = bcpgIn.ReadByte();
  33. }
  34. public OnePassSignaturePacket(
  35. int sigType,
  36. HashAlgorithmTag hashAlgorithm,
  37. PublicKeyAlgorithmTag keyAlgorithm,
  38. long keyId,
  39. bool isNested)
  40. {
  41. this.version = 3;
  42. this.sigType = sigType;
  43. this.hashAlgorithm = hashAlgorithm;
  44. this.keyAlgorithm = keyAlgorithm;
  45. this.keyId = keyId;
  46. this.nested = (isNested) ? 0 : 1;
  47. }
  48. public int SignatureType
  49. {
  50. get { return sigType; }
  51. }
  52. /// <summary>The encryption algorithm tag.</summary>
  53. public PublicKeyAlgorithmTag KeyAlgorithm
  54. {
  55. get { return keyAlgorithm; }
  56. }
  57. /// <summary>The hash algorithm tag.</summary>
  58. public HashAlgorithmTag HashAlgorithm
  59. {
  60. get { return hashAlgorithm; }
  61. }
  62. public long KeyId
  63. {
  64. get { return keyId; }
  65. }
  66. public override void Encode(
  67. BcpgOutputStream bcpgOut)
  68. {
  69. MemoryStream bOut = new MemoryStream();
  70. BcpgOutputStream pOut = new BcpgOutputStream(bOut);
  71. pOut.Write(
  72. (byte) version,
  73. (byte) sigType,
  74. (byte) hashAlgorithm,
  75. (byte) keyAlgorithm);
  76. pOut.WriteLong(keyId);
  77. pOut.WriteByte((byte) nested);
  78. bcpgOut.WritePacket(PacketTag.OnePassSignature, bOut.ToArray(), true);
  79. }
  80. }
  81. }
  82. #pragma warning restore
  83. #endif