顶顶顶顶顶顶顶顶顶

This commit is contained in:
CN-JS-HuiBai
2026-04-15 01:26:11 +08:00
parent bd95fb4a08
commit 7c0512ce72

View File

@@ -27,20 +27,16 @@ import (
"github.com/sagernet/sing/service" "github.com/sagernet/sing/service"
) )
// ss2022Key derives a key for SS2022 exactly like Xboard/V2bX: // ss2022Key returns the correctly sized identity string.
// It takes the identity string (like a Hex hash or UUID), ensures it's the correct length,
// and returns its Base64 representation.
func ss2022Key(identity string, keyLen int) string { func ss2022Key(identity string, keyLen int) string {
raw := []byte(identity) if len(identity) > keyLen {
if len(raw) > keyLen { return identity[:keyLen]
raw = raw[:keyLen] } else if len(identity) < keyLen {
} else if len(raw) < keyLen {
// Pad with zeros if shorter (though Xboard usually provides 32 chars)
padded := make([]byte, keyLen) padded := make([]byte, keyLen)
copy(padded, raw) copy(padded, []byte(identity))
raw = padded return string(padded)
} }
return base64.StdEncoding.EncodeToString(raw) return identity
} }
// ss2022KeyLength returns the required key length for a given SS2022 cipher. // ss2022KeyLength returns the required key length for a given SS2022 cipher.