NullEngine.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines
  6. {
  7. /**
  8. * The no-op engine that just copies bytes through, irrespective of whether encrypting and decrypting.
  9. * Provided for the sake of completeness.
  10. */
  11. public class NullEngine
  12. : IBlockCipher
  13. {
  14. private bool initialised;
  15. private const int BlockSize = 1;
  16. public NullEngine()
  17. {
  18. }
  19. public virtual void Init(
  20. bool forEncryption,
  21. ICipherParameters parameters)
  22. {
  23. // we don't mind any parameters that may come in
  24. initialised = true;
  25. }
  26. public virtual string AlgorithmName
  27. {
  28. get { return "Null"; }
  29. }
  30. public virtual bool IsPartialBlockOkay
  31. {
  32. get { return true; }
  33. }
  34. public virtual int GetBlockSize()
  35. {
  36. return BlockSize;
  37. }
  38. public virtual int ProcessBlock(
  39. byte[] input,
  40. int inOff,
  41. byte[] output,
  42. int outOff)
  43. {
  44. if (!initialised)
  45. throw new InvalidOperationException("Null engine not initialised");
  46. Check.DataLength(input, inOff, BlockSize, "input buffer too short");
  47. Check.OutputLength(output, outOff, BlockSize, "output buffer too short");
  48. for (int i = 0; i < BlockSize; ++i)
  49. {
  50. output[outOff + i] = input[inOff + i];
  51. }
  52. return BlockSize;
  53. }
  54. public virtual void Reset()
  55. {
  56. // nothing needs to be done
  57. }
  58. }
  59. }
  60. #pragma warning restore
  61. #endif