You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

EncryptorBase.cs 1.5 kB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. namespace Shadowsocks.Encryption
  4. {
  5. public abstract class EncryptorBase : IEncryptor
  6. {
  7. private static int _currentId = 0;
  8. public const int MaxInputSize = 32768;
  9. public const int MAX_DOMAIN_LEN = 255;
  10. public const int ADDR_PORT_LEN = 2;
  11. public const int ADDR_ATYP_LEN = 1;
  12. public const int ATYP_IPv4 = 0x01;
  13. public const int ATYP_DOMAIN = 0x03;
  14. public const int ATYP_IPv6 = 0x04;
  15. public const int MD5Length = 16;
  16. // for debugging only, give it a number to trace data stream
  17. public readonly int instanceId;
  18. protected EncryptorBase(string method, string password)
  19. {
  20. instanceId = _currentId;
  21. _currentId++;
  22. Method = method;
  23. Password = password;
  24. }
  25. protected string Method;
  26. protected string Password;
  27. public override string ToString()
  28. {
  29. return $"{instanceId}({Method},{Password})";
  30. }
  31. public abstract int Encrypt(ReadOnlySpan<byte> plain, Span<byte> cipher);
  32. public abstract int Decrypt(Span<byte> plain, ReadOnlySpan<byte> cipher);
  33. public abstract int EncryptUDP(ReadOnlySpan<byte> plain, Span<byte> cipher);
  34. public abstract int DecryptUDP(Span<byte> plain, ReadOnlySpan<byte> cipher);
  35. public int AddressBufferLength { get; set; } = -1;
  36. }
  37. }