Skip to content

Commit beaf6a3

Browse files
bradfitzhanwen
authored andcommitted
ssh: fix error variable naming convention, add docs
Follow up to CL 96336 Change-Id: I038f3901919c5136273e5df051bc6e958082f830 Reviewed-on: https://go-review.googlesource.com/96415 Reviewed-by: Han-Wen Nienhuys <[email protected]> Run-TryBot: Han-Wen Nienhuys <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 4979611 commit beaf6a3

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

ssh/client_auth_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,8 @@ func TestClientAuthErrorList(t *testing.T) {
614614
for i, e := range authErrs.Errors {
615615
switch i {
616616
case 0:
617-
if e != NoAuthError {
618-
t.Fatalf("errors: got error %v, want NoAuthError", e)
617+
if e != ErrNoAuth {
618+
t.Fatalf("errors: got error %v, want ErrNoAuth", e)
619619
}
620620
case 1:
621621
if e != publicKeyErr {

ssh/server.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ type ServerConn struct {
166166
// unsuccessful, it closes the connection and returns an error. The
167167
// Request and NewChannel channels must be serviced, or the connection
168168
// will hang.
169+
//
170+
// The returned error may be of type *ServerAuthError for
171+
// authentication errors.
169172
func NewServerConn(c net.Conn, config *ServerConfig) (*ServerConn, <-chan NewChannel, <-chan *Request, error) {
170173
fullConf := *config
171174
fullConf.SetDefaults()
@@ -292,12 +295,13 @@ func checkSourceAddress(addr net.Addr, sourceAddrs string) error {
292295
return fmt.Errorf("ssh: remote address %v is not allowed because of source-address restriction", addr)
293296
}
294297

295-
// ServerAuthError implements the error interface. It appends any authentication
296-
// errors that may occur, and is returned if all of the authentication methods
297-
// provided by the user failed to authenticate.
298+
// ServerAuthError represents server authentication errors and is
299+
// sometimes returned by NewServerConn. It appends any authentication
300+
// errors that may occur, and is returned if all of the authentication
301+
// methods provided by the user failed to authenticate.
298302
type ServerAuthError struct {
299303
// Errors contains authentication errors returned by the authentication
300-
// callback methods. The first entry typically is NoAuthError.
304+
// callback methods. The first entry is typically ErrNoAuth.
301305
Errors []error
302306
}
303307

@@ -309,11 +313,12 @@ func (l ServerAuthError) Error() string {
309313
return "[" + strings.Join(errs, ", ") + "]"
310314
}
311315

312-
// NoAuthError is the unique error that is returned if no
316+
// ErrNoAuth is the error value returned if no
313317
// authentication method has been passed yet. This happens as a normal
314318
// part of the authentication loop, since the client first tries
315319
// 'none' authentication to discover available methods.
316-
var NoAuthError = errors.New("ssh: no auth passed yet")
320+
// It is returned in ServerAuthError.Errors from NewServerConn.
321+
var ErrNoAuth = errors.New("ssh: no auth passed yet")
317322

318323
func (s *connection) serverAuthenticate(config *ServerConfig) (*Permissions, error) {
319324
sessionID := s.transport.getSessionID()
@@ -369,7 +374,7 @@ userAuthLoop:
369374
}
370375

371376
perms = nil
372-
authErr := NoAuthError
377+
authErr := ErrNoAuth
373378

374379
switch userAuthReq.Method {
375380
case "none":

0 commit comments

Comments
 (0)