shadowsocks2022.go 963 B

123456789101112131415161718192021222324252627
  1. package xray
  2. import "github.com/xtls/xray-core/proxy/shadowsocks_2022"
  3. // Shadowsocks2022KeyBytes is the key size a Shadowsocks-2022 method takes, or 0
  4. // for any other method, whose password is free-form.
  5. func Shadowsocks2022KeyBytes(method string) int {
  6. cipher, err := shadowsocks_2022.GetCipherMethod(method)
  7. if err != nil {
  8. return 0
  9. }
  10. return cipher.KeySaltLength
  11. }
  12. // ValidShadowsocks2022Key reads key the way the core does: base64, else the raw
  13. // string, and either way exactly the method's key size.
  14. func ValidShadowsocks2022Key(method, key string) bool {
  15. _, err := shadowsocks_2022.ParseKey(key, Shadowsocks2022KeyBytes(method))
  16. return err == nil
  17. }
  18. // Shadowsocks2022NoMultiUser reports a 2022 method xray-core refuses on an
  19. // inbound with users: the multi-user identity header is AES-only.
  20. func Shadowsocks2022NoMultiUser(method string) bool {
  21. cipher, err := shadowsocks_2022.GetCipherMethod(method)
  22. return err == nil && cipher.IsChaCha
  23. }