ssh: use a variable rather than type for NoAuthError
Change-Id: Ib61e0bc7d953cefde0436f77fe6a610201043c85
Reviewed-on: https://go-review.googlesource.com/96336
Run-TryBot: Han-Wen Nienhuys <hanwen@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Spencer Tung <spencertung@google.com>
Reviewed-by: Han-Wen Nienhuys <hanwen@google.com>
diff --git a/ssh/client_auth_test.go b/ssh/client_auth_test.go
index a6b8b99..e457ca5 100644
--- a/ssh/client_auth_test.go
+++ b/ssh/client_auth_test.go
@@ -614,8 +614,8 @@
for i, e := range authErrs.Errors {
switch i {
case 0:
- if _, ok := e.(*NoAuthError); !ok {
- t.Fatalf("errors: got error type %T, want NoAuthError", e)
+ if e != NoAuthError {
+ t.Fatalf("errors: got error %v, want NoAuthError", e)
}
case 1:
if e != publicKeyErr {
diff --git a/ssh/server.go b/ssh/server.go
index f40657d..6262f34 100644
--- a/ssh/server.go
+++ b/ssh/server.go
@@ -297,7 +297,7 @@
// provided by the user failed to authenticate.
type ServerAuthError struct {
// Errors contains authentication errors returned by the authentication
- // callback methods.
+ // callback methods. The first entry typically is NoAuthError.
Errors []error
}
@@ -309,13 +309,11 @@
return "[" + strings.Join(errs, ", ") + "]"
}
-// NoAuthError is the unique error that is returned if no authentication method
-// has been passed yet
-type NoAuthError struct{}
-
-func (e *NoAuthError) Error() string {
- return "no auth passed yet"
-}
+// NoAuthError is the unique error that is returned if no
+// authentication method has been passed yet. This happens as a normal
+// part of the authentication loop, since the client first tries
+// 'none' authentication to discover available methods.
+var NoAuthError = errors.New("ssh: no auth passed yet")
func (s *connection) serverAuthenticate(config *ServerConfig) (*Permissions, error) {
sessionID := s.transport.getSessionID()
@@ -371,7 +369,7 @@
}
perms = nil
- authErr := error(&NoAuthError{})
+ authErr := NoAuthError
switch userAuthReq.Method {
case "none":