HandshakeMessageInput.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.IO;
  5. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto;
  6. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls
  7. {
  8. // TODO Rewrite without MemoryStream
  9. public sealed class HandshakeMessageInput
  10. : MemoryStream
  11. {
  12. private readonly int m_offset;
  13. internal HandshakeMessageInput(byte[] buf, int offset, int length)
  14. : base(buf, offset, length, false, true)
  15. {
  16. m_offset = offset;
  17. }
  18. public void UpdateHash(TlsHash hash)
  19. {
  20. WriteTo(new TlsHashSink(hash));
  21. }
  22. internal void UpdateHashPrefix(TlsHash hash, int bindersSize)
  23. {
  24. byte[] buf = GetBuffer();
  25. int count = Convert.ToInt32(Length);
  26. hash.Update(buf, m_offset, count - bindersSize);
  27. }
  28. internal void UpdateHashSuffix(TlsHash hash, int bindersSize)
  29. {
  30. byte[] buf = GetBuffer();
  31. int count = Convert.ToInt32(Length);
  32. hash.Update(buf, m_offset + count - bindersSize, bindersSize);
  33. }
  34. }
  35. }
  36. #pragma warning restore
  37. #endif