shadowsocks2022.go 668 B

1234567891011121314151617181920
  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. }