TlsMacSink.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
  5. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto
  6. {
  7. public class TlsMacSink
  8. : BaseOutputStream
  9. {
  10. private readonly TlsMac m_mac;
  11. public TlsMacSink(TlsMac mac)
  12. {
  13. this.m_mac = mac;
  14. }
  15. public virtual TlsMac Mac
  16. {
  17. get { return m_mac; }
  18. }
  19. public override void Write(byte[] buffer, int offset, int count)
  20. {
  21. Streams.ValidateBufferArguments(buffer, offset, count);
  22. if (count > 0)
  23. {
  24. m_mac.Update(buffer, offset, count);
  25. }
  26. }
  27. #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
  28. public override void Write(ReadOnlySpan<byte> buffer)
  29. {
  30. if (!buffer.IsEmpty)
  31. {
  32. m_mac.Update(buffer);
  33. }
  34. }
  35. #endif
  36. public override void WriteByte(byte value)
  37. {
  38. m_mac.Update(new byte[]{ value }, 0, 1);
  39. }
  40. }
  41. }
  42. #pragma warning restore
  43. #endif