@@ -773,15 +773,11 @@ func (c *Conn) handleAuth(arg string) {
773
773
// Parse client initial response if there is one
774
774
var ir []byte
775
775
if len (parts ) > 1 {
776
- if parts [1 ] == "=" {
777
- ir = []byte {}
778
- } else {
779
- var err error
780
- ir , err = base64 .StdEncoding .DecodeString (parts [1 ])
781
- if err != nil {
782
- c .writeResponse (454 , EnhancedCode {4 , 7 , 0 }, "Invalid base64 data" )
783
- return
784
- }
776
+ var err error
777
+ ir , err = decodeSASLResponse (parts [1 ])
778
+ if err != nil {
779
+ c .writeResponse (454 , EnhancedCode {4 , 7 , 0 }, "Invalid base64 data" )
780
+ return
785
781
}
786
782
}
787
783
@@ -820,21 +816,24 @@ func (c *Conn) handleAuth(arg string) {
820
816
return
821
817
}
822
818
823
- if encoded == "=" {
824
- response = []byte {}
825
- } else {
826
- response , err = base64 .StdEncoding .DecodeString (encoded )
827
- if err != nil {
828
- c .writeResponse (454 , EnhancedCode {4 , 7 , 0 }, "Invalid base64 data" )
829
- return
830
- }
819
+ response , err = decodeSASLResponse (encoded )
820
+ if err != nil {
821
+ c .writeResponse (454 , EnhancedCode {4 , 7 , 0 }, "Invalid base64 data" )
822
+ return
831
823
}
832
824
}
833
825
834
826
c .writeResponse (235 , EnhancedCode {2 , 0 , 0 }, "Authentication succeeded" )
835
827
c .didAuth = true
836
828
}
837
829
830
+ func decodeSASLResponse (s string ) ([]byte , error ) {
831
+ if s == "=" {
832
+ return []byte {}, nil
833
+ }
834
+ return base64 .StdEncoding .DecodeString (s )
835
+ }
836
+
838
837
func (c * Conn ) authMechanisms () []string {
839
838
if authSession , ok := c .Session ().(AuthSession ); ok {
840
839
return authSession .AuthMechanisms ()
0 commit comments