mirror of
https://github.com/amnezia-vpn/amneziawg-go.git
synced 2026-05-17 00:05:50 +03:00
- fix the bug that transport packet interprets as init/resp/cookie with the same size - cleanup error responses - reduce buffer allocations
48 lines
774 B
Go
48 lines
774 B
Go
package device
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/hex"
|
|
"errors"
|
|
"strings"
|
|
)
|
|
|
|
func newBytesObf(val string) (obf, error) {
|
|
val = strings.TrimPrefix(val, "0x")
|
|
|
|
if len(val) == 0 {
|
|
return nil, errors.New("empty argument")
|
|
}
|
|
|
|
if len(val)%2 != 0 {
|
|
return nil, errors.New("odd amount of symbols")
|
|
}
|
|
|
|
bytes, err := hex.DecodeString(val)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &bytesObf{data: bytes}, nil
|
|
}
|
|
|
|
type bytesObf struct {
|
|
data []byte
|
|
}
|
|
|
|
func (o *bytesObf) Obfuscate(dst, src []byte) {
|
|
copy(dst, o.data)
|
|
}
|
|
|
|
func (o *bytesObf) Deobfuscate(dst, src []byte) bool {
|
|
return bytes.Equal(o.data, src[:o.ObfuscatedLen(0)])
|
|
}
|
|
|
|
func (o *bytesObf) ObfuscatedLen(srcLen int) int {
|
|
return len(o.data)
|
|
}
|
|
|
|
func (o *bytesObf) DeobfuscatedLen(srcLen int) int {
|
|
return 0
|
|
}
|