BcTlsHash.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
  6. {
  7. internal sealed class BcTlsHash
  8. : TlsHash
  9. {
  10. private readonly BcTlsCrypto m_crypto;
  11. private readonly int m_cryptoHashAlgorithm;
  12. private readonly IDigest m_digest;
  13. internal BcTlsHash(BcTlsCrypto crypto, int cryptoHashAlgorithm)
  14. : this(crypto, cryptoHashAlgorithm, crypto.CreateDigest(cryptoHashAlgorithm))
  15. {
  16. }
  17. private BcTlsHash(BcTlsCrypto crypto, int cryptoHashAlgorithm, IDigest digest)
  18. {
  19. this.m_crypto = crypto;
  20. this.m_cryptoHashAlgorithm = cryptoHashAlgorithm;
  21. this.m_digest = digest;
  22. }
  23. public void Update(byte[] data, int offSet, int length)
  24. {
  25. m_digest.BlockUpdate(data, offSet, length);
  26. }
  27. public byte[] CalculateHash()
  28. {
  29. byte[] rv = new byte[m_digest.GetDigestSize()];
  30. m_digest.DoFinal(rv, 0);
  31. return rv;
  32. }
  33. public TlsHash CloneHash()
  34. {
  35. IDigest clone = m_crypto.CloneDigest(m_cryptoHashAlgorithm, m_digest);
  36. return new BcTlsHash(m_crypto, m_cryptoHashAlgorithm, clone);
  37. }
  38. public void Reset()
  39. {
  40. m_digest.Reset();
  41. }
  42. }
  43. }
  44. #pragma warning restore
  45. #endif