Commit a27ede0b authored by Daniel Martí's avatar Daniel Martí

all: remove a few unused parameters

I recently modified tabwriter to reduce the number of defers due to
flush calls. However, I forgot to notice that the new function
flushNoDefers can no longer return an error, due to the lack of the
defer.

In crypto/tls, hashForServerKeyExchange never returned a non-nil error,
so simplify the code.

Finally, in go/types and net we can find a few trivially unused
parameters, so remove them.

Change-Id: I54c8de83fbc944df432453b55c93008d7e810e61
Reviewed-on: https://go-review.googlesource.com/c/go/+/174131
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBenny Siegert <bsiegert@gmail.com>
parent 45ed3dbd
...@@ -106,19 +106,19 @@ func md5SHA1Hash(slices [][]byte) []byte { ...@@ -106,19 +106,19 @@ func md5SHA1Hash(slices [][]byte) []byte {
// hashForServerKeyExchange hashes the given slices and returns their digest // hashForServerKeyExchange hashes the given slices and returns their digest
// using the given hash function (for >= TLS 1.2) or using a default based on // using the given hash function (for >= TLS 1.2) or using a default based on
// the sigType (for earlier TLS versions). // the sigType (for earlier TLS versions).
func hashForServerKeyExchange(sigType uint8, hashFunc crypto.Hash, version uint16, slices ...[]byte) ([]byte, error) { func hashForServerKeyExchange(sigType uint8, hashFunc crypto.Hash, version uint16, slices ...[]byte) []byte {
if version >= VersionTLS12 { if version >= VersionTLS12 {
h := hashFunc.New() h := hashFunc.New()
for _, slice := range slices { for _, slice := range slices {
h.Write(slice) h.Write(slice)
} }
digest := h.Sum(nil) digest := h.Sum(nil)
return digest, nil return digest
} }
if sigType == signatureECDSA { if sigType == signatureECDSA {
return sha1Hash(slices), nil return sha1Hash(slices)
} }
return md5SHA1Hash(slices), nil return md5SHA1Hash(slices)
} }
// ecdheKeyAgreement implements a TLS key agreement where the server // ecdheKeyAgreement implements a TLS key agreement where the server
...@@ -185,10 +185,7 @@ NextCandidate: ...@@ -185,10 +185,7 @@ NextCandidate:
return nil, errors.New("tls: certificate cannot be used with the selected cipher suite") return nil, errors.New("tls: certificate cannot be used with the selected cipher suite")
} }
digest, err := hashForServerKeyExchange(sigType, hashFunc, ka.version, clientHello.random, hello.random, serverECDHParams) digest := hashForServerKeyExchange(sigType, hashFunc, ka.version, clientHello.random, hello.random, serverECDHParams)
if err != nil {
return nil, err
}
signOpts := crypto.SignerOpts(hashFunc) signOpts := crypto.SignerOpts(hashFunc)
if sigType == signatureRSAPSS { if sigType == signatureRSAPSS {
...@@ -297,10 +294,7 @@ func (ka *ecdheKeyAgreement) processServerKeyExchange(config *Config, clientHell ...@@ -297,10 +294,7 @@ func (ka *ecdheKeyAgreement) processServerKeyExchange(config *Config, clientHell
} }
sig = sig[2:] sig = sig[2:]
digest, err := hashForServerKeyExchange(sigType, hashFunc, ka.version, clientHello.random, serverHello.random, serverECDHParams) digest := hashForServerKeyExchange(sigType, hashFunc, ka.version, clientHello.random, serverHello.random, serverECDHParams)
if err != nil {
return err
}
return verifyHandshakeSignature(sigType, cert.PublicKey, hashFunc, digest, sig) return verifyHandshakeSignature(sigType, cert.PublicKey, hashFunc, digest, sig)
} }
......
...@@ -241,7 +241,7 @@ func (check *Checker) arguments(x *operand, call *ast.CallExpr, sig *Signature, ...@@ -241,7 +241,7 @@ func (check *Checker) arguments(x *operand, call *ast.CallExpr, sig *Signature,
if i == n-1 && call.Ellipsis.IsValid() { if i == n-1 && call.Ellipsis.IsValid() {
ellipsis = call.Ellipsis ellipsis = call.Ellipsis
} }
check.argument(call.Fun, sig, i, x, ellipsis, context) check.argument(sig, i, x, ellipsis, context)
} }
} }
...@@ -259,7 +259,7 @@ func (check *Checker) arguments(x *operand, call *ast.CallExpr, sig *Signature, ...@@ -259,7 +259,7 @@ func (check *Checker) arguments(x *operand, call *ast.CallExpr, sig *Signature,
// argument checks passing of argument x to the i'th parameter of the given signature. // argument checks passing of argument x to the i'th parameter of the given signature.
// If ellipsis is valid, the argument is followed by ... at that position in the call. // If ellipsis is valid, the argument is followed by ... at that position in the call.
func (check *Checker) argument(fun ast.Expr, sig *Signature, i int, x *operand, ellipsis token.Pos, context string) { func (check *Checker) argument(sig *Signature, i int, x *operand, ellipsis token.Pos, context string) {
check.singleValue(x) check.singleValue(x)
if x.mode == invalid { if x.mode == invalid {
return return
......
...@@ -183,7 +183,7 @@ func (r *Resolver) exchange(ctx context.Context, server string, q dnsmessage.Que ...@@ -183,7 +183,7 @@ func (r *Resolver) exchange(ctx context.Context, server string, q dnsmessage.Que
} }
// checkHeader performs basic sanity checks on the header. // checkHeader performs basic sanity checks on the header.
func checkHeader(p *dnsmessage.Parser, h dnsmessage.Header, name, server string) error { func checkHeader(p *dnsmessage.Parser, h dnsmessage.Header) error {
if h.RCode == dnsmessage.RCodeNameError { if h.RCode == dnsmessage.RCodeNameError {
return errNoSuchHost return errNoSuchHost
} }
...@@ -214,7 +214,7 @@ func checkHeader(p *dnsmessage.Parser, h dnsmessage.Header, name, server string) ...@@ -214,7 +214,7 @@ func checkHeader(p *dnsmessage.Parser, h dnsmessage.Header, name, server string)
return nil return nil
} }
func skipToAnswer(p *dnsmessage.Parser, qtype dnsmessage.Type, name, server string) error { func skipToAnswer(p *dnsmessage.Parser, qtype dnsmessage.Type) error {
for { for {
h, err := p.AnswerHeader() h, err := p.AnswerHeader()
if err == dnsmessage.ErrSectionDone { if err == dnsmessage.ErrSectionDone {
...@@ -272,7 +272,7 @@ func (r *Resolver) tryOneName(ctx context.Context, cfg *dnsConfig, name string, ...@@ -272,7 +272,7 @@ func (r *Resolver) tryOneName(ctx context.Context, cfg *dnsConfig, name string,
continue continue
} }
if err := checkHeader(&p, h, name, server); err != nil { if err := checkHeader(&p, h); err != nil {
dnsErr := &DNSError{ dnsErr := &DNSError{
Err: err.Error(), Err: err.Error(),
Name: name, Name: name,
...@@ -292,7 +292,7 @@ func (r *Resolver) tryOneName(ctx context.Context, cfg *dnsConfig, name string, ...@@ -292,7 +292,7 @@ func (r *Resolver) tryOneName(ctx context.Context, cfg *dnsConfig, name string,
continue continue
} }
err = skipToAnswer(&p, qtype, name, server) err = skipToAnswer(&p, qtype)
if err == nil { if err == nil {
return p, server, nil return p, server, nil
} }
......
...@@ -499,13 +499,14 @@ func (b *Writer) Flush() error { ...@@ -499,13 +499,14 @@ func (b *Writer) Flush() error {
// don't want to expose. // don't want to expose.
func (b *Writer) flush() (err error) { func (b *Writer) flush() (err error) {
defer b.handlePanic(&err, "Flush") defer b.handlePanic(&err, "Flush")
return b.flushNoDefers() b.flushNoDefers()
return nil
} }
// flushNoDefers is like flush, but without a deferred handlePanic call. This // flushNoDefers is like flush, but without a deferred handlePanic call. This
// can be called from other methods which already have their own deferred // can be called from other methods which already have their own deferred
// handlePanic calls, such as Write, and avoid the extra defer work. // handlePanic calls, such as Write, and avoid the extra defer work.
func (b *Writer) flushNoDefers() (err error) { func (b *Writer) flushNoDefers() {
// add current cell if not empty // add current cell if not empty
if b.cell.size > 0 { if b.cell.size > 0 {
if b.endChar != 0 { if b.endChar != 0 {
...@@ -518,7 +519,6 @@ func (b *Writer) flushNoDefers() (err error) { ...@@ -518,7 +519,6 @@ func (b *Writer) flushNoDefers() (err error) {
// format contents of buffer // format contents of buffer
b.format(0, 0, len(b.lines)) b.format(0, 0, len(b.lines))
b.reset() b.reset()
return nil
} }
var hbar = []byte("---\n") var hbar = []byte("---\n")
...@@ -551,9 +551,7 @@ func (b *Writer) Write(buf []byte) (n int, err error) { ...@@ -551,9 +551,7 @@ func (b *Writer) Write(buf []byte) (n int, err error) {
// the formatting of the following lines (the last cell per // the formatting of the following lines (the last cell per
// line is ignored by format()), thus we can flush the // line is ignored by format()), thus we can flush the
// Writer contents. // Writer contents.
if err = b.flushNoDefers(); err != nil { b.flushNoDefers()
return
}
if ch == '\f' && b.flags&Debug != 0 { if ch == '\f' && b.flags&Debug != 0 {
// indicate section break // indicate section break
b.write0(hbar) b.write0(hbar)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment