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