99 "errors"
1010 "fmt"
1111 "io"
12+ "slices"
1213 "strings"
1314)
1415
@@ -83,7 +84,7 @@ func (c *connection) clientAuthenticate(config *ClientConfig) error {
8384 // success
8485 return nil
8586 } else if ok == authFailure {
86- if m := auth .method (); ! contains (tried , m ) {
87+ if m := auth .method (); ! slices . Contains (tried , m ) {
8788 tried = append (tried , m )
8889 }
8990 }
@@ -97,7 +98,7 @@ func (c *connection) clientAuthenticate(config *ClientConfig) error {
9798 findNext:
9899 for _ , a := range config .Auth {
99100 candidateMethod := a .method ()
100- if contains (tried , candidateMethod ) {
101+ if slices . Contains (tried , candidateMethod ) {
101102 continue
102103 }
103104 for _ , meth := range methods {
@@ -117,15 +118,6 @@ func (c *connection) clientAuthenticate(config *ClientConfig) error {
117118 return fmt .Errorf ("ssh: unable to authenticate, attempted methods %v, no supported methods remain" , tried )
118119}
119120
120- func contains (list []string , e string ) bool {
121- for _ , s := range list {
122- if s == e {
123- return true
124- }
125- }
126- return false
127- }
128-
129121// An AuthMethod represents an instance of an RFC 4252 authentication method.
130122type AuthMethod interface {
131123 // auth authenticates user over transport t.
@@ -255,7 +247,7 @@ func pickSignatureAlgorithm(signer Signer, extensions map[string][]byte) (MultiA
255247 // Fallback to use if there is no "server-sig-algs" extension or a
256248 // common algorithm cannot be found. We use the public key format if the
257249 // MultiAlgorithmSigner supports it, otherwise we return an error.
258- if ! contains (as .Algorithms (), underlyingAlgo (keyFormat )) {
250+ if ! slices . Contains (as .Algorithms (), underlyingAlgo (keyFormat )) {
259251 return "" , fmt .Errorf ("ssh: no common public key signature algorithm, server only supports %q for key type %q, signer only supports %v" ,
260252 underlyingAlgo (keyFormat ), keyFormat , as .Algorithms ())
261253 }
@@ -284,7 +276,7 @@ func pickSignatureAlgorithm(signer Signer, extensions map[string][]byte) (MultiA
284276 // Filter algorithms based on those supported by MultiAlgorithmSigner.
285277 var keyAlgos []string
286278 for _ , algo := range algorithmsForKeyFormat (keyFormat ) {
287- if contains (as .Algorithms (), underlyingAlgo (algo )) {
279+ if slices . Contains (as .Algorithms (), underlyingAlgo (algo )) {
288280 keyAlgos = append (keyAlgos , algo )
289281 }
290282 }
@@ -334,7 +326,7 @@ func (cb publicKeyCallback) auth(session []byte, user string, c packetConn, rand
334326 // the key try to use the obtained algorithm as if "server-sig-algs" had
335327 // not been implemented if supported from the algorithm signer.
336328 if ! ok && idx < origSignersLen && isRSACert (algo ) && algo != CertAlgoRSAv01 {
337- if contains (as .Algorithms (), KeyAlgoRSA ) {
329+ if slices . Contains (as .Algorithms (), KeyAlgoRSA ) {
338330 // We retry using the compat algorithm after all signers have
339331 // been tried normally.
340332 signers = append (signers , & multiAlgorithmSigner {
@@ -385,7 +377,7 @@ func (cb publicKeyCallback) auth(session []byte, user string, c packetConn, rand
385377 // contain the "publickey" method, do not attempt to authenticate with any
386378 // other keys. According to RFC 4252 Section 7, the latter can occur when
387379 // additional authentication methods are required.
388- if success == authSuccess || ! contains (methods , cb .method ()) {
380+ if success == authSuccess || ! slices . Contains (methods , cb .method ()) {
389381 return success , methods , err
390382 }
391383 }
@@ -434,7 +426,7 @@ func confirmKeyAck(key PublicKey, c packetConn) (bool, error) {
434426 // servers send the key type instead. OpenSSH allows any algorithm
435427 // that matches the public key, so we do the same.
436428 // https://github.com/openssh/openssh-portable/blob/86bdd385/sshconnect2.c#L709
437- if ! contains (algorithmsForKeyFormat (key .Type ()), msg .Algo ) {
429+ if ! slices . Contains (algorithmsForKeyFormat (key .Type ()), msg .Algo ) {
438430 return false , nil
439431 }
440432 if ! bytes .Equal (msg .PubKey , pubKey ) {
0 commit comments