Commit da6d835b authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

crypto: rename some FooError to ErrFoo

Also, add an explicit error type when the right hand side is an unexported
function.

R=golang-dev, gri, rogpeppe, agl, rsc
CC=golang-dev
https://golang.org/cl/5564048
parent 0e919ff2
......@@ -35,11 +35,11 @@ func (invalidPublicKeyError) Error() string {
return "crypto/dsa: invalid public key"
}
// InvalidPublicKeyError results when a public key is not usable by this code.
// ErrInvalidPublicKey results when a public key is not usable by this code.
// FIPS is quite strict about the format of DSA keys, but other code may be
// less so. Thus, when using keys which may have been generated by other code,
// this error must be handled.
var InvalidPublicKeyError = invalidPublicKeyError(0)
var ErrInvalidPublicKey error = invalidPublicKeyError(0)
// ParameterSizes is a enumeration of the acceptable bit lengths of the primes
// in a set of DSA parameters. See FIPS 186-3, section 4.2.
......@@ -194,7 +194,7 @@ func Sign(rand io.Reader, priv *PrivateKey, hash []byte) (r, s *big.Int, err err
n := priv.Q.BitLen()
if n&7 != 0 {
err = InvalidPublicKeyError
err = ErrInvalidPublicKey
return
}
n >>= 3
......
......@@ -47,7 +47,7 @@ func (ki keyIncorrectError) Error() string {
return "the given key was incorrect"
}
var KeyIncorrectError = keyIncorrectError(0)
var ErrKeyIncorrect error = keyIncorrectError(0)
type unknownIssuerError int
......@@ -55,7 +55,7 @@ func (unknownIssuerError) Error() string {
return "signature make by unknown entity"
}
var UnknownIssuerError = unknownIssuerError(0)
var ErrUnknownIssuer error = unknownIssuerError(0)
type UnknownPacketTypeError uint8
......
......@@ -71,7 +71,7 @@ func (se *SymmetricallyEncrypted) Decrypt(c CipherFunction, key []byte) (io.Read
s := cipher.NewOCFBDecrypter(c.new(key), se.prefix, ocfbResync)
if s == nil {
return nil, errors.KeyIncorrectError
return nil, errors.ErrKeyIncorrect
}
plaintext := cipher.StreamReader{S: s, R: se.contents}
......
......@@ -161,7 +161,7 @@ FindKey:
continue
}
decrypted, err = se.Decrypt(pk.encryptedKey.CipherFunc, pk.encryptedKey.Key)
if err != nil && err != errors.KeyIncorrectError {
if err != nil && err != errors.ErrKeyIncorrect {
return nil, err
}
if decrypted != nil {
......@@ -179,11 +179,11 @@ FindKey:
}
if len(candidates) == 0 && len(symKeys) == 0 {
return nil, errors.KeyIncorrectError
return nil, errors.ErrKeyIncorrect
}
if prompt == nil {
return nil, errors.KeyIncorrectError
return nil, errors.ErrKeyIncorrect
}
passphrase, err := prompt(candidates, len(symKeys) != 0)
......@@ -197,7 +197,7 @@ FindKey:
err = s.Decrypt(passphrase)
if err == nil && !s.Encrypted {
decrypted, err = se.Decrypt(s.CipherFunc, s.Key)
if err != nil && err != errors.KeyIncorrectError {
if err != nil && err != errors.ErrKeyIncorrect {
return nil, err
}
if decrypted != nil {
......@@ -353,8 +353,8 @@ func (scr *signatureCheckReader) Read(buf []byte) (n int, err error) {
}
// CheckDetachedSignature takes a signed file and a detached signature and
// returns the signer if the signature is valid. If the signer isn't know,
// UnknownIssuerError is returned.
// returns the signer if the signature is valid. If the signer isn't known,
// ErrUnknownIssuer is returned.
func CheckDetachedSignature(keyring KeyRing, signed, signature io.Reader) (signer *Entity, err error) {
p, err := packet.Read(signature)
if err != nil {
......@@ -372,7 +372,7 @@ func CheckDetachedSignature(keyring KeyRing, signed, signature io.Reader) (signe
keys := keyring.KeysById(*sig.IssuerKeyId)
if len(keys) == 0 {
return nil, errors.UnknownIssuerError
return nil, errors.ErrUnknownIssuer
}
h, wrappedHash, err := hashForSignature(sig.Hash, sig.SigType)
......@@ -399,7 +399,7 @@ func CheckDetachedSignature(keyring KeyRing, signed, signature io.Reader) (signe
return
}
return nil, errors.UnknownIssuerError
return nil, errors.ErrUnknownIssuer
}
// CheckArmoredDetachedSignature performs the same actions as
......
......@@ -161,18 +161,18 @@ func TestSignedEncryptedMessage(t *testing.T) {
prompt := func(keys []Key, symmetric bool) ([]byte, error) {
if symmetric {
t.Errorf("prompt: message was marked as symmetrically encrypted")
return nil, errors.KeyIncorrectError
return nil, errors.ErrKeyIncorrect
}
if len(keys) == 0 {
t.Error("prompt: no keys requested")
return nil, errors.KeyIncorrectError
return nil, errors.ErrKeyIncorrect
}
err := keys[0].PrivateKey.Decrypt([]byte("passphrase"))
if err != nil {
t.Errorf("prompt: error decrypting key: %s", err)
return nil, errors.KeyIncorrectError
return nil, errors.ErrKeyIncorrect
}
return nil, nil
......
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