EcbBlockCipher.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Modes
  5. {
  6. public class EcbBlockCipher
  7. : IBlockCipherMode
  8. {
  9. internal static IBlockCipherMode GetBlockCipherMode(IBlockCipher blockCipher)
  10. {
  11. if (blockCipher is IBlockCipherMode blockCipherMode)
  12. return blockCipherMode;
  13. return new EcbBlockCipher(blockCipher);
  14. }
  15. private readonly IBlockCipher m_cipher;
  16. public EcbBlockCipher(IBlockCipher cipher)
  17. {
  18. if (cipher == null)
  19. throw new ArgumentNullException(nameof(cipher));
  20. m_cipher = cipher;
  21. }
  22. public bool IsPartialBlockOkay => false;
  23. public string AlgorithmName => m_cipher.AlgorithmName + "/ECB";
  24. public int GetBlockSize()
  25. {
  26. return m_cipher.GetBlockSize();
  27. }
  28. public IBlockCipher UnderlyingCipher => m_cipher;
  29. public void Init(bool forEncryption, ICipherParameters parameters)
  30. {
  31. m_cipher.Init(forEncryption, parameters);
  32. }
  33. public int ProcessBlock(byte[] inBuf, int inOff, byte[] outBuf, int outOff)
  34. {
  35. return m_cipher.ProcessBlock(inBuf, inOff, outBuf, outOff);
  36. }
  37. #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
  38. public int ProcessBlock(ReadOnlySpan<byte> input, Span<byte> output)
  39. {
  40. return m_cipher.ProcessBlock(input, output);
  41. }
  42. #endif
  43. public void Reset()
  44. {
  45. }
  46. }
  47. }
  48. #pragma warning restore
  49. #endif