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.

Socks5MethodSelectionMessage.cs 1.1 kB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. namespace Shadowsocks.Protocol.Socks5
  3. {
  4. public class Socks5MethodSelectionMessage : Socks5Message
  5. {
  6. // 5 auth
  7. public byte SelectedAuth;
  8. public override int Serialize(Memory<byte> buffer)
  9. {
  10. if (buffer.Length < 2) throw Util.BufferTooSmall(2, buffer.Length, nameof(buffer));
  11. buffer.Span[0] = 5;
  12. buffer.Span[1] = SelectedAuth;
  13. return 2;
  14. }
  15. public override (bool success, int length) TryLoad(ReadOnlyMemory<byte> buffer)
  16. {
  17. // need 3 byte
  18. if (buffer.Length < 2) return (false, 2);
  19. if (buffer.Span[0] != 5) return (false, 0);
  20. SelectedAuth = buffer.Span[1];
  21. return (true, 2);
  22. }
  23. public override bool Equals(IProtocolMessage other)
  24. {
  25. if (other is null) return false;
  26. if (ReferenceEquals(this, other)) return true;
  27. if (other.GetType() != GetType()) return false;
  28. return SelectedAuth == ((Socks5MethodSelectionMessage) other).SelectedAuth;
  29. }
  30. }
  31. }