CertificateVerify.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.IO;
  5. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls
  6. {
  7. public sealed class CertificateVerify
  8. {
  9. private readonly int m_algorithm;
  10. private readonly byte[] m_signature;
  11. public CertificateVerify(int algorithm, byte[] signature)
  12. {
  13. if (!TlsUtilities.IsValidUint16(algorithm))
  14. throw new ArgumentException("algorithm");
  15. if (signature == null)
  16. throw new ArgumentNullException("signature");
  17. this.m_algorithm = algorithm;
  18. this.m_signature = signature;
  19. }
  20. /// <returns>a <see cref="SignatureScheme"/> value.</returns>
  21. public int Algorithm
  22. {
  23. get { return m_algorithm; }
  24. }
  25. public byte[] Signature
  26. {
  27. get { return m_signature; }
  28. }
  29. /// <summary>Encode this <see cref="CertificateVerify"/> to a <see cref="Stream"/>.</summary>
  30. /// <param name="output">the <see cref="Stream"/> to encode to.</param>
  31. /// <exception cref="IOException"/>
  32. public void Encode(Stream output)
  33. {
  34. TlsUtilities.WriteUint16(m_algorithm, output);
  35. TlsUtilities.WriteOpaque16(m_signature, output);
  36. }
  37. /// <summary>Parse a <see cref="CertificateVerify"/> from a <see cref="Stream"/>.</summary>
  38. /// <param name="context">the <see cref="TlsContext"/> of the current connection.</param>
  39. /// <param name="input">the <see cref="Stream"/> to parse from.</param>
  40. /// <returns>a <see cref="CertificateVerify"/> object.</returns>
  41. /// <exception cref="IOException"/>
  42. public static CertificateVerify Parse(TlsContext context, Stream input)
  43. {
  44. if (!TlsUtilities.IsTlsV13(context))
  45. throw new InvalidOperationException();
  46. int algorithm = TlsUtilities.ReadUint16(input);
  47. byte[] signature = TlsUtilities.ReadOpaque16(input);
  48. return new CertificateVerify(algorithm, signature);
  49. }
  50. }
  51. }
  52. #pragma warning restore
  53. #endif