DigestSink.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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.Crypto.IO
  6. {
  7. public sealed class DigestSink
  8. : BaseOutputStream
  9. {
  10. private readonly IDigest m_digest;
  11. public DigestSink(IDigest digest)
  12. {
  13. m_digest = digest;
  14. }
  15. public IDigest Digest => m_digest;
  16. public override void Write(byte[] buffer, int offset, int count)
  17. {
  18. Streams.ValidateBufferArguments(buffer, offset, count);
  19. if (count > 0)
  20. {
  21. m_digest.BlockUpdate(buffer, offset, count);
  22. }
  23. }
  24. #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
  25. public override void Write(ReadOnlySpan<byte> buffer)
  26. {
  27. if (!buffer.IsEmpty)
  28. {
  29. m_digest.BlockUpdate(buffer);
  30. }
  31. }
  32. #endif
  33. public override void WriteByte(byte value)
  34. {
  35. m_digest.Update(value);
  36. }
  37. }
  38. }
  39. #pragma warning restore
  40. #endif