From 65553f4ec467dff20aa650b4d53644de510ba6c0 Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Sun, 29 Dec 2019 16:55:21 +0000 Subject: [PATCH] Remove redundant base64 decoding --- internal/client/state.go | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/internal/client/state.go b/internal/client/state.go index e26936c..ac555ce 100644 --- a/internal/client/state.go +++ b/internal/client/state.go @@ -2,7 +2,6 @@ package client import ( "crypto" - "encoding/base64" "encoding/json" "errors" "io/ioutil" @@ -18,8 +17,8 @@ type rawConfig struct { ServerName string ProxyMethod string EncryptionMethod string - UID string - PublicKey string + UID []byte + PublicKey []byte BrowserSig string Transport string NumConn int @@ -131,21 +130,13 @@ func (sta *State) ParseConfig(conf string) (err error) { sta.ServerName = preParse.ServerName sta.NumConn = preParse.NumConn sta.Timeout = time.Duration(preParse.StreamTimeout) * time.Second + sta.UID = preParse.UID - uid, err := base64.StdEncoding.DecodeString(preParse.UID) - if err != nil { - return errors.New("Failed to parse UID: " + err.Error()) - } - sta.UID = uid - - pubBytes, err := base64.StdEncoding.DecodeString(preParse.PublicKey) - if err != nil { - return errors.New("Failed to parse Public key: " + err.Error()) - } - pub, ok := ecdh.Unmarshal(pubBytes) + pub, ok := ecdh.Unmarshal(preParse.PublicKey) if !ok { return errors.New("Failed to unmarshal Public key") } sta.staticPub = pub + return nil }