diff options
| author | Russ Cox <rsc@golang.org> | 2011-11-01 22:04:37 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2011-11-01 22:04:37 -0400 |
| commit | c2049d2dfeeea3d41fafa91e3e3f0e47c285355b (patch) | |
| tree | 090fd29206a707cf5a1f63eacaa414203d2b1ccb /src/pkg/crypto/openpgp | |
| parent | 68050ac76b94b58d962cf8265a8d4eb31ff35658 (diff) | |
| download | go-c2049d2dfeeea3d41fafa91e3e3f0e47c285355b.tar.xz | |
src/pkg/[a-m]*: gofix -r error -force=error
R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/5322051
Diffstat (limited to 'src/pkg/crypto/openpgp')
28 files changed, 299 insertions, 325 deletions
diff --git a/src/pkg/crypto/openpgp/armor/armor.go b/src/pkg/crypto/openpgp/armor/armor.go index 9c4180d6d6..707bdf354b 100644 --- a/src/pkg/crypto/openpgp/armor/armor.go +++ b/src/pkg/crypto/openpgp/armor/armor.go @@ -9,10 +9,9 @@ package armor import ( "bufio" "bytes" - "crypto/openpgp/error" + error_ "crypto/openpgp/error" "encoding/base64" "io" - "os" ) // A Block represents an OpenPGP armored structure. @@ -36,7 +35,7 @@ type Block struct { oReader openpgpReader } -var ArmorCorrupt os.Error = error.StructuralError("armor invalid") +var ArmorCorrupt error = error_.StructuralError("armor invalid") const crc24Init = 0xb704ce const crc24Poly = 0x1864cfb @@ -69,9 +68,9 @@ type lineReader struct { crc uint32 } -func (l *lineReader) Read(p []byte) (n int, err os.Error) { +func (l *lineReader) Read(p []byte) (n int, err error) { if l.eof { - return 0, os.EOF + return 0, io.EOF } if len(l.buf) > 0 { @@ -101,7 +100,7 @@ func (l *lineReader) Read(p []byte) (n int, err os.Error) { uint32(expectedBytes[2]) line, _, err = l.in.ReadLine() - if err != nil && err != os.EOF { + if err != nil && err != io.EOF { return } if !bytes.HasPrefix(line, armorEnd) { @@ -109,7 +108,7 @@ func (l *lineReader) Read(p []byte) (n int, err os.Error) { } l.eof = true - return 0, os.EOF + return 0, io.EOF } if len(line) > 64 { @@ -138,11 +137,11 @@ type openpgpReader struct { currentCRC uint32 } -func (r *openpgpReader) Read(p []byte) (n int, err os.Error) { +func (r *openpgpReader) Read(p []byte) (n int, err error) { n, err = r.b64Reader.Read(p) r.currentCRC = crc24(r.currentCRC, p[:n]) - if err == os.EOF { + if err == io.EOF { if r.lReader.crc != uint32(r.currentCRC&crc24Mask) { return 0, ArmorCorrupt } @@ -155,7 +154,7 @@ func (r *openpgpReader) Read(p []byte) (n int, err os.Error) { // leading garbage. If it doesn't find a block, it will return nil, os.EOF. The // given Reader is not usable after calling this function: an arbitrary amount // of data may have been read past the end of the block. -func Decode(in io.Reader) (p *Block, err os.Error) { +func Decode(in io.Reader) (p *Block, err error) { r, _ := bufio.NewReaderSize(in, 100) var line []byte ignoreNext := false diff --git a/src/pkg/crypto/openpgp/armor/encode.go b/src/pkg/crypto/openpgp/armor/encode.go index 99dee375ef..6f07582c37 100644 --- a/src/pkg/crypto/openpgp/armor/encode.go +++ b/src/pkg/crypto/openpgp/armor/encode.go @@ -7,7 +7,6 @@ package armor import ( "encoding/base64" "io" - "os" ) var armorHeaderSep = []byte(": ") @@ -16,7 +15,7 @@ var newline = []byte("\n") var armorEndOfLineOut = []byte("-----\n") // writeSlices writes its arguments to the given Writer. -func writeSlices(out io.Writer, slices ...[]byte) (err os.Error) { +func writeSlices(out io.Writer, slices ...[]byte) (err error) { for _, s := range slices { _, err = out.Write(s) if err != nil { @@ -45,7 +44,7 @@ func newLineBreaker(out io.Writer, lineLength int) *lineBreaker { } } -func (l *lineBreaker) Write(b []byte) (n int, err os.Error) { +func (l *lineBreaker) Write(b []byte) (n int, err error) { n = len(b) if n == 0 { @@ -81,7 +80,7 @@ func (l *lineBreaker) Write(b []byte) (n int, err os.Error) { return } -func (l *lineBreaker) Close() (err os.Error) { +func (l *lineBreaker) Close() (err error) { if l.used > 0 { _, err = l.out.Write(l.line[0:l.used]) if err != nil { @@ -106,12 +105,12 @@ type encoding struct { blockType []byte } -func (e *encoding) Write(data []byte) (n int, err os.Error) { +func (e *encoding) Write(data []byte) (n int, err error) { e.crc = crc24(e.crc, data) return e.b64.Write(data) } -func (e *encoding) Close() (err os.Error) { +func (e *encoding) Close() (err error) { err = e.b64.Close() if err != nil { return @@ -131,7 +130,7 @@ func (e *encoding) Close() (err os.Error) { // Encode returns a WriteCloser which will encode the data written to it in // OpenPGP armor. -func Encode(out io.Writer, blockType string, headers map[string]string) (w io.WriteCloser, err os.Error) { +func Encode(out io.Writer, blockType string, headers map[string]string) (w io.WriteCloser, err error) { bType := []byte(blockType) err = writeSlices(out, armorStart, bType, armorEndOfLineOut) if err != nil { diff --git a/src/pkg/crypto/openpgp/canonical_text.go b/src/pkg/crypto/openpgp/canonical_text.go index 293eff3542..fe4557aafc 100644 --- a/src/pkg/crypto/openpgp/canonical_text.go +++ b/src/pkg/crypto/openpgp/canonical_text.go @@ -4,10 +4,7 @@ package openpgp -import ( - "hash" - "os" -) +import "hash" // NewCanonicalTextHash reformats text written to it into the canonical // form and then applies the hash h. See RFC 4880, section 5.2.1. @@ -22,7 +19,7 @@ type canonicalTextHash struct { var newline = []byte{'\r', '\n'} -func (cth *canonicalTextHash) Write(buf []byte) (int, os.Error) { +func (cth *canonicalTextHash) Write(buf []byte) (int, error) { start := 0 for i, c := range buf { diff --git a/src/pkg/crypto/openpgp/canonical_text_test.go b/src/pkg/crypto/openpgp/canonical_text_test.go index ccf2910cc6..ae54f8c83e 100644 --- a/src/pkg/crypto/openpgp/canonical_text_test.go +++ b/src/pkg/crypto/openpgp/canonical_text_test.go @@ -6,7 +6,6 @@ package openpgp import ( "bytes" - "os" "testing" ) @@ -14,7 +13,7 @@ type recordingHash struct { buf *bytes.Buffer } -func (r recordingHash) Write(b []byte) (n int, err os.Error) { +func (r recordingHash) Write(b []byte) (n int, err error) { return r.buf.Write(b) } diff --git a/src/pkg/crypto/openpgp/elgamal/elgamal.go b/src/pkg/crypto/openpgp/elgamal/elgamal.go index 99a6e3e1f2..2ed49f6213 100644 --- a/src/pkg/crypto/openpgp/elgamal/elgamal.go +++ b/src/pkg/crypto/openpgp/elgamal/elgamal.go @@ -16,8 +16,8 @@ import ( "big" "crypto/rand" "crypto/subtle" + "errors" "io" - "os" ) // PublicKey represents an ElGamal public key. @@ -34,10 +34,10 @@ type PrivateKey struct { // Encrypt encrypts the given message to the given public key. The result is a // pair of integers. Errors can result from reading random, or because msg is // too large to be encrypted to the public key. -func Encrypt(random io.Reader, pub *PublicKey, msg []byte) (c1, c2 *big.Int, err os.Error) { +func Encrypt(random io.Reader, pub *PublicKey, msg []byte) (c1, c2 *big.Int, err error) { pLen := (pub.P.BitLen() + 7) / 8 if len(msg) > pLen-11 { - err = os.NewError("elgamal: message too long") + err = errors.New("elgamal: message too long") return } @@ -74,7 +74,7 @@ func Encrypt(random io.Reader, pub *PublicKey, msg []byte) (c1, c2 *big.Int, err // be used to break the cryptosystem. See ``Chosen Ciphertext Attacks // Against Protocols Based on the RSA Encryption Standard PKCS #1'', Daniel // Bleichenbacher, Advances in Cryptology (Crypto '98), -func Decrypt(priv *PrivateKey, c1, c2 *big.Int) (msg []byte, err os.Error) { +func Decrypt(priv *PrivateKey, c1, c2 *big.Int) (msg []byte, err error) { s := new(big.Int).Exp(c1, priv.X, priv.P) s.ModInverse(s, priv.P) s.Mul(s, c2) @@ -97,13 +97,13 @@ func Decrypt(priv *PrivateKey, c1, c2 *big.Int) (msg []byte, err os.Error) { } if firstByteIsTwo != 1 || lookingForIndex != 0 || index < 9 { - return nil, os.NewError("elgamal: decryption error") + return nil, errors.New("elgamal: decryption error") } return em[index+1:], nil } // nonZeroRandomBytes fills the given slice with non-zero random octets. -func nonZeroRandomBytes(s []byte, rand io.Reader) (err os.Error) { +func nonZeroRandomBytes(s []byte, rand io.Reader) (err error) { _, err = io.ReadFull(rand, s) if err != nil { return diff --git a/src/pkg/crypto/openpgp/error/error.go b/src/pkg/crypto/openpgp/error/error.go index 9cc21f1f8f..ceeb054194 100644 --- a/src/pkg/crypto/openpgp/error/error.go +++ b/src/pkg/crypto/openpgp/error/error.go @@ -13,7 +13,7 @@ import ( // invalid. type StructuralError string -func (s StructuralError) String() string { +func (s StructuralError) Error() string { return "OpenPGP data invalid: " + string(s) } @@ -21,7 +21,7 @@ func (s StructuralError) String() string { // makes use of currently unimplemented features. type UnsupportedError string -func (s UnsupportedError) String() string { +func (s UnsupportedError) Error() string { return "OpenPGP feature unsupported: " + string(s) } @@ -29,7 +29,7 @@ func (s UnsupportedError) String() string { // incorrect value. type InvalidArgumentError string -func (i InvalidArgumentError) String() string { +func (i InvalidArgumentError) Error() string { return "OpenPGP argument invalid: " + string(i) } @@ -37,13 +37,13 @@ func (i InvalidArgumentError) String() string { // validate. type SignatureError string -func (b SignatureError) String() string { +func (b SignatureError) Error() string { return "OpenPGP signature invalid: " + string(b) } type keyIncorrectError int -func (ki keyIncorrectError) String() string { +func (ki keyIncorrectError) Error() string { return "the given key was incorrect" } @@ -51,7 +51,7 @@ var KeyIncorrectError = keyIncorrectError(0) type unknownIssuerError int -func (unknownIssuerError) String() string { +func (unknownIssuerError) Error() string { return "signature make by unknown entity" } @@ -59,6 +59,6 @@ var UnknownIssuerError = unknownIssuerError(0) type UnknownPacketTypeError uint8 -func (upte UnknownPacketTypeError) String() string { +func (upte UnknownPacketTypeError) Error() string { return "unknown OpenPGP packet type: " + strconv.Itoa(int(upte)) } diff --git a/src/pkg/crypto/openpgp/keys.go b/src/pkg/crypto/openpgp/keys.go index c70fb79270..b705d226e1 100644 --- a/src/pkg/crypto/openpgp/keys.go +++ b/src/pkg/crypto/openpgp/keys.go @@ -7,11 +7,10 @@ package openpgp import ( "crypto" "crypto/openpgp/armor" - "crypto/openpgp/error" + error_ "crypto/openpgp/error" "crypto/openpgp/packet" "crypto/rsa" "io" - "os" "time" ) @@ -178,16 +177,16 @@ func (el EntityList) DecryptionKeys() (keys []Key) { } // ReadArmoredKeyRing reads one or more public/private keys from an armor keyring file. -func ReadArmoredKeyRing(r io.Reader) (EntityList, os.Error) { +func ReadArmoredKeyRing(r io.Reader) (EntityList, error) { block, err := armor.Decode(r) - if err == os.EOF { - return nil, error.InvalidArgumentError("no armored data found") + if err == io.EOF { + return nil, error_.InvalidArgumentError("no armored data found") } if err != nil { return nil, err } if block.Type != PublicKeyType && block.Type != PrivateKeyType { - return nil, error.InvalidArgumentError("expected public or private key block, got: " + block.Type) + return nil, error_.InvalidArgumentError("expected public or private key block, got: " + block.Type) } return ReadKeyRing(block.Body) @@ -195,19 +194,19 @@ func ReadArmoredKeyRing(r io.Reader) (EntityList, os.Error) { // ReadKeyRing reads one or more public/private keys. Unsupported keys are // ignored as long as at least a single valid key is found. -func ReadKeyRing(r io.Reader) (el EntityList, err os.Error) { +func ReadKeyRing(r io.Reader) (el EntityList, err error) { packets := packet.NewReader(r) - var lastUnsupportedError os.Error + var lastUnsupportedError error for { var e *Entity e, err = readEntity(packets) if err != nil { - if _, ok := err.(error.UnsupportedError); ok { + if _, ok := err.(error_.UnsupportedError); ok { lastUnsupportedError = err err = readToNextPublicKey(packets) } - if err == os.EOF { + if err == io.EOF { err = nil break } @@ -228,14 +227,14 @@ func ReadKeyRing(r io.Reader) (el EntityList, err os.Error) { // readToNextPublicKey reads packets until the start of the entity and leaves // the first packet of the new entity in the Reader. -func readToNextPublicKey(packets *packet.Reader) (err os.Error) { +func readToNextPublicKey(packets *packet.Reader) (err error) { var p packet.Packet for { p, err = packets.Next() - if err == os.EOF { + if err == io.EOF { return } else if err != nil { - if _, ok := err.(error.UnsupportedError); ok { + if _, ok := err.(error_.UnsupportedError); ok { err = nil continue } @@ -253,7 +252,7 @@ func readToNextPublicKey(packets *packet.Reader) (err os.Error) { // readEntity reads an entity (public key, identities, subkeys etc) from the // given Reader. -func readEntity(packets *packet.Reader) (*Entity, os.Error) { +func readEntity(packets *packet.Reader) (*Entity, error) { e := new(Entity) e.Identities = make(map[string]*Identity) @@ -266,21 +265,21 @@ func readEntity(packets *packet.Reader) (*Entity, os.Error) { if e.PrimaryKey, ok = p.(*packet.PublicKey); !ok { if e.PrivateKey, ok = p.(*packet.PrivateKey); !ok { packets.Unread(p) - return nil, error.StructuralError("first packet was not a public/private key") + return nil, error_.StructuralError("first packet was not a public/private key") } else { e.PrimaryKey = &e.PrivateKey.PublicKey } } if !e.PrimaryKey.PubKeyAlgo.CanSign() { - return nil, error.StructuralError("primary key cannot be used for signatures") + return nil, error_.StructuralError("primary key cannot be used for signatures") } var current *Identity EachPacket: for { p, err := packets.Next() - if err == os.EOF { + if err == io.EOF { break } else if err != nil { return nil, err @@ -295,7 +294,7 @@ EachPacket: for { p, err = packets.Next() - if err == os.EOF { + if err == io.EOF { return nil, io.ErrUnexpectedEOF } else if err != nil { return nil, err @@ -303,12 +302,12 @@ EachPacket: sig, ok := p.(*packet.Signature) if !ok { - return nil, error.StructuralError("user ID packet not followed by self-signature") + return nil, error_.StructuralError("user ID packet not followed by self-signature") } if (sig.SigType == packet.SigTypePositiveCert || sig.SigType == packet.SigTypeGenericCert) && sig.IssuerKeyId != nil && *sig.IssuerKeyId == e.PrimaryKey.KeyId { if err = e.PrimaryKey.VerifyUserIdSignature(pkt.Id, sig); err != nil { - return nil, error.StructuralError("user ID self-signature invalid: " + err.String()) + return nil, error_.StructuralError("user ID self-signature invalid: " + err.Error()) } current.SelfSignature = sig break @@ -317,7 +316,7 @@ EachPacket: } case *packet.Signature: if current == nil { - return nil, error.StructuralError("signature packet found before user id packet") + return nil, error_.StructuralError("signature packet found before user id packet") } current.Signatures = append(current.Signatures, pkt) case *packet.PrivateKey: @@ -344,34 +343,34 @@ EachPacket: } if len(e.Identities) == 0 { - return nil, error.StructuralError("entity without any identities") + return nil, error_.StructuralError("entity without any identities") } return e, nil } -func addSubkey(e *Entity, packets *packet.Reader, pub *packet.PublicKey, priv *packet.PrivateKey) os.Error { +func addSubkey(e *Entity, packets *packet.Reader, pub *packet.PublicKey, priv *packet.PrivateKey) error { var subKey Subkey subKey.PublicKey = pub subKey.PrivateKey = priv p, err := packets.Next() - if err == os.EOF { + if err == io.EOF { return io.ErrUnexpectedEOF } if err != nil { - return error.StructuralError("subkey signature invalid: " + err.String()) + return error_.StructuralError("subkey signature invalid: " + err.Error()) } var ok bool subKey.Sig, ok = p.(*packet.Signature) if !ok { - return error.StructuralError("subkey packet not followed by signature") + return error_.StructuralError("subkey packet not followed by signature") } if subKey.Sig.SigType != packet.SigTypeSubkeyBinding { - return error.StructuralError("subkey signature with wrong type") + return error_.StructuralError("subkey signature with wrong type") } err = e.PrimaryKey.VerifyKeySignature(subKey.PublicKey, subKey.Sig) if err != nil { - return error.StructuralError("subkey signature invalid: " + err.String()) + return error_.StructuralError("subkey signature invalid: " + err.Error()) } e.Subkeys = append(e.Subkeys, subKey) return nil @@ -382,10 +381,10 @@ const defaultRSAKeyBits = 2048 // NewEntity returns an Entity that contains a fresh RSA/RSA keypair with a // single identity composed of the given full name, comment and email, any of // which may be empty but must not contain any of "()<>\x00". -func NewEntity(rand io.Reader, currentTimeSecs int64, name, comment, email string) (*Entity, os.Error) { +func NewEntity(rand io.Reader, currentTimeSecs int64, name, comment, email string) (*Entity, error) { uid := packet.NewUserId(name, comment, email) if uid == nil { - return nil, error.InvalidArgumentError("user id field contained invalid characters") + return nil, error_.InvalidArgumentError("user id field contained invalid characters") } signingPriv, err := rsa.GenerateKey(rand, defaultRSAKeyBits) if err != nil { @@ -442,7 +441,7 @@ func NewEntity(rand io.Reader, currentTimeSecs int64, name, comment, email strin // SerializePrivate serializes an Entity, including private key material, to // the given Writer. For now, it must only be used on an Entity returned from // NewEntity. -func (e *Entity) SerializePrivate(w io.Writer) (err os.Error) { +func (e *Entity) SerializePrivate(w io.Writer) (err error) { err = e.PrivateKey.Serialize(w) if err != nil { return @@ -480,7 +479,7 @@ func (e *Entity) SerializePrivate(w io.Writer) (err os.Error) { // Serialize writes the public part of the given Entity to w. (No private // key material will be output). -func (e *Entity) Serialize(w io.Writer) os.Error { +func (e *Entity) Serialize(w io.Writer) error { err := e.PrimaryKey.Serialize(w) if err != nil { return err @@ -518,16 +517,16 @@ func (e *Entity) Serialize(w io.Writer) os.Error { // associated with e. The provided identity must already be an element of // e.Identities and the private key of signer must have been decrypted if // necessary. -func (e *Entity) SignIdentity(identity string, signer *Entity) os.Error { +func (e *Entity) SignIdentity(identity string, signer *Entity) error { if signer.PrivateKey == nil { - return error.InvalidArgumentError("signing Entity must have a private key") + return error_.InvalidArgumentError("signing Entity must have a private key") } if signer.PrivateKey.Encrypted { - return error.InvalidArgumentError("signing Entity's private key must be decrypted") + return error_.InvalidArgumentError("signing Entity's private key must be decrypted") } ident, ok := e.Identities[identity] if !ok { - return error.InvalidArgumentError("given identity string not found in Entity") + return error_.InvalidArgumentError("given identity string not found in Entity") } sig := &packet.Signature{ diff --git a/src/pkg/crypto/openpgp/packet/compressed.go b/src/pkg/crypto/openpgp/packet/compressed.go index 1c15c24c4b..f80d798cfe 100644 --- a/src/pkg/crypto/openpgp/packet/compressed.go +++ b/src/pkg/crypto/openpgp/packet/compressed.go @@ -7,9 +7,8 @@ package packet import ( "compress/flate" "compress/zlib" - "crypto/openpgp/error" + error_ "crypto/openpgp/error" "io" - "os" "strconv" ) @@ -19,7 +18,7 @@ type Compressed struct { Body io.Reader } -func (c *Compressed) parse(r io.Reader) os.Error { +func (c *Compressed) parse(r io.Reader) error { var buf [1]byte _, err := readFull(r, buf[:]) if err != nil { @@ -32,7 +31,7 @@ func (c *Compressed) parse(r io.Reader) os.Error { case 2: c.Body, err = zlib.NewReader(r) default: - err = error.UnsupportedError("unknown compression algorithm: " + strconv.Itoa(int(buf[0]))) + err = error_.UnsupportedError("unknown compression algorithm: " + strconv.Itoa(int(buf[0]))) } return err diff --git a/src/pkg/crypto/openpgp/packet/compressed_test.go b/src/pkg/crypto/openpgp/packet/compressed_test.go index 24fe501edb..cb2d70bd41 100644 --- a/src/pkg/crypto/openpgp/packet/compressed_test.go +++ b/src/pkg/crypto/openpgp/packet/compressed_test.go @@ -7,7 +7,7 @@ package packet import ( "bytes" "encoding/hex" - "os" + "io" "io/ioutil" "testing" ) @@ -26,7 +26,7 @@ func TestCompressed(t *testing.T) { } contents, err := ioutil.ReadAll(c.Body) - if err != nil && err != os.EOF { + if err != nil && err != io.EOF { t.Error(err) return } diff --git a/src/pkg/crypto/openpgp/packet/encrypted_key.go b/src/pkg/crypto/openpgp/packet/encrypted_key.go index b4730cbc9b..d05103fcd8 100644 --- a/src/pkg/crypto/openpgp/packet/encrypted_key.go +++ b/src/pkg/crypto/openpgp/packet/encrypted_key.go @@ -7,12 +7,11 @@ package packet import ( "big" "crypto/openpgp/elgamal" - "crypto/openpgp/error" + error_ "crypto/openpgp/error" "crypto/rand" "crypto/rsa" "encoding/binary" "io" - "os" "strconv" ) @@ -29,14 +28,14 @@ type EncryptedKey struct { encryptedMPI1, encryptedMPI2 []byte } -func (e *EncryptedKey) parse(r io.Reader) (err os.Error) { +func (e *EncryptedKey) parse(r io.Reader) (err error) { var buf [10]byte _, err = readFull(r, buf[:]) if err != nil { return } if buf[0] != encryptedKeyVersion { - return error.UnsupportedError("unknown EncryptedKey version " + strconv.Itoa(int(buf[0]))) + return error_.UnsupportedError("unknown EncryptedKey version " + strconv.Itoa(int(buf[0]))) } e.KeyId = binary.BigEndian.Uint64(buf[1:9]) e.Algo = PublicKeyAlgorithm(buf[9]) @@ -64,8 +63,8 @@ func checksumKeyMaterial(key []byte) uint16 { // Decrypt decrypts an encrypted session key with the given private key. The // private key must have been decrypted first. -func (e *EncryptedKey) Decrypt(priv *PrivateKey) os.Error { - var err os.Error +func (e *EncryptedKey) Decrypt(priv *PrivateKey) error { + var err error var b []byte // TODO(agl): use session key decryption routines here to avoid @@ -78,7 +77,7 @@ func (e *EncryptedKey) Decrypt(priv *PrivateKey) os.Error { c2 := new(big.Int).SetBytes(e.encryptedMPI2) b, err = elgamal.Decrypt(priv.PrivateKey.(*elgamal.PrivateKey), c1, c2) default: - err = error.InvalidArgumentError("cannot decrypted encrypted session key with private key of type " + strconv.Itoa(int(priv.PubKeyAlgo))) + err = error_.InvalidArgumentError("cannot decrypted encrypted session key with private key of type " + strconv.Itoa(int(priv.PubKeyAlgo))) } if err != nil { @@ -90,7 +89,7 @@ func (e *EncryptedKey) Decrypt(priv *PrivateKey) os.Error { expectedChecksum := uint16(b[len(b)-2])<<8 | uint16(b[len(b)-1]) checksum := checksumKeyMaterial(e.Key) if checksum != expectedChecksum { - return error.StructuralError("EncryptedKey checksum incorrect") + return error_.StructuralError("EncryptedKey checksum incorrect") } return nil @@ -98,7 +97,7 @@ func (e *EncryptedKey) Decrypt(priv *PrivateKey) os.Error { // SerializeEncryptedKey serializes an encrypted key packet to w that contains // key, encrypted to pub. -func SerializeEncryptedKey(w io.Writer, rand io.Reader, pub *PublicKey, cipherFunc CipherFunction, key []byte) os.Error { +func SerializeEncryptedKey(w io.Writer, rand io.Reader, pub *PublicKey, cipherFunc CipherFunction, key []byte) error { var buf [10]byte buf[0] = encryptedKeyVersion binary.BigEndian.PutUint64(buf[1:9], pub.KeyId) @@ -117,16 +116,16 @@ func SerializeEncryptedKey(w io.Writer, rand io.Reader, pub *PublicKey, cipherFu case PubKeyAlgoElGamal: return serializeEncryptedKeyElGamal(w, rand, buf, pub.PublicKey.(*elgamal.PublicKey), keyBlock) case PubKeyAlgoDSA, PubKeyAlgoRSASignOnly: - return error.InvalidArgumentError("cannot encrypt to public key of type " + strconv.Itoa(int(pub.PubKeyAlgo))) + return error_.InvalidArgumentError("cannot encrypt to public key of type " + strconv.Itoa(int(pub.PubKeyAlgo))) } - return error.UnsupportedError("encrypting a key to public key of type " + strconv.Itoa(int(pub.PubKeyAlgo))) + return error_.UnsupportedError("encrypting a key to public key of type " + strconv.Itoa(int(pub.PubKeyAlgo))) } -func serializeEncryptedKeyRSA(w io.Writer, rand io.Reader, header [10]byte, pub *rsa.PublicKey, keyBlock []byte) os.Error { +func serializeEncryptedKeyRSA(w io.Writer, rand io.Reader, header [10]byte, pub *rsa.PublicKey, keyBlock []byte) error { cipherText, err := rsa.EncryptPKCS1v15(rand, pub, keyBlock) if err != nil { - return error.InvalidArgumentError("RSA encryption failed: " + err.String()) + return error_.InvalidArgumentError("RSA encryption failed: " + err.Error()) } packetLen := 10 /* header length */ + 2 /* mpi size */ + len(cipherText) @@ -142,10 +141,10 @@ func serializeEncryptedKeyRSA(w io.Writer, rand io.Reader, header [10]byte, pub return writeMPI(w, 8*uint16(len(cipherText)), cipherText) } -func serializeEncryptedKeyElGamal(w io.Writer, rand io.Reader, header [10]byte, pub *elgamal.PublicKey, keyBlock []byte) os.Error { +func serializeEncryptedKeyElGamal(w io.Writer, rand io.Reader, header [10]byte, pub *elgamal.PublicKey, keyBlock []byte) error { c1, c2, err := elgamal.Encrypt(rand, pub, keyBlock) if err != nil { - return error.InvalidArgumentError("ElGamal encryption failed: " + err.String()) + return error_.InvalidArgumentError("ElGamal encryption failed: " + err.Error()) } packetLen := 10 /* header length */ diff --git a/src/pkg/crypto/openpgp/packet/literal.go b/src/pkg/crypto/openpgp/packet/literal.go index 9411572d7c..1a9ec6e51e 100644 --- a/src/pkg/crypto/openpgp/packet/literal.go +++ b/src/pkg/crypto/openpgp/packet/literal.go @@ -7,7 +7,6 @@ package packet import ( "encoding/binary" "io" - "os" ) // LiteralData represents an encrypted file. See RFC 4880, section 5.9. @@ -24,7 +23,7 @@ func (l *LiteralData) ForEyesOnly() bool { return l.FileName == "_CONSOLE" } -func (l *LiteralData) parse(r io.Reader) (err os.Error) { +func (l *LiteralData) parse(r io.Reader) (err error) { var buf [256]byte _, err = readFull(r, buf[:2]) @@ -55,7 +54,7 @@ func (l *LiteralData) parse(r io.Reader) (err os.Error) { // SerializeLiteral serializes a literal data packet to w and returns a // WriteCloser to which the data itself can be written and which MUST be closed // on completion. The fileName is truncated to 255 bytes. -func SerializeLiteral(w io.WriteCloser, isBinary bool, fileName string, time uint32) (plaintext io.WriteCloser, err os.Error) { +func SerializeLiteral(w io.WriteCloser, isBinary bool, fileName string, time uint32) (plaintext io.WriteCloser, err error) { var buf [4]byte buf[0] = 't' if isBinary { diff --git a/src/pkg/crypto/openpgp/packet/one_pass_signature.go b/src/pkg/crypto/openpgp/packet/one_pass_signature.go index ca826e4f4d..13e6aa5aff 100644 --- a/src/pkg/crypto/openpgp/packet/one_pass_signature.go +++ b/src/pkg/crypto/openpgp/packet/one_pass_signature.go @@ -6,11 +6,10 @@ package packet import ( "crypto" - "crypto/openpgp/error" + error_ "crypto/openpgp/error" "crypto/openpgp/s2k" "encoding/binary" "io" - "os" "strconv" ) @@ -26,7 +25,7 @@ type OnePassSignature struct { const onePassSignatureVersion = 3 -func (ops *OnePassSignature) parse(r io.Reader) (err os.Error) { +func (ops *OnePassSignature) parse(r io.Reader) (err error) { var buf [13]byte _, err = readFull(r, buf[:]) @@ -34,13 +33,13 @@ func (ops *OnePassSignature) parse(r io.Reader) (err os.Error) { return } if buf[0] != onePassSignatureVersion { - err = error.UnsupportedError("one-pass-signature packet version " + strconv.Itoa(int(buf[0]))) + err = error_.UnsupportedError("one-pass-signature packet version " + strconv.Itoa(int(buf[0]))) } var ok bool ops.Hash, ok = s2k.HashIdToHash(buf[2]) if !ok { - return error.UnsupportedError("hash function: " + strconv.Itoa(int(buf[2]))) + return error_.UnsupportedError("hash function: " + strconv.Itoa(int(buf[2]))) } ops.SigType = SignatureType(buf[1]) @@ -51,14 +50,14 @@ func (ops *OnePassSignature) parse(r io.Reader) (err os.Error) { } // Serialize marshals the given OnePassSignature to w. -func (ops *OnePassSignature) Serialize(w io.Writer) os.Error { +func (ops *OnePassSignature) Serialize(w io.Writer) error { var buf [13]byte buf[0] = onePassSignatureVersion buf[1] = uint8(ops.SigType) var ok bool buf[2], ok = s2k.HashToHashId(ops.Hash) if !ok { - return error.UnsupportedError("hash type: " + strconv.Itoa(int(ops.Hash))) + return error_.UnsupportedError("hash type: " + strconv.Itoa(int(ops.Hash))) } buf[3] = uint8(ops.PubKeyAlgo) binary.BigEndian.PutUint64(buf[4:12], ops.KeyId) diff --git a/src/pkg/crypto/openpgp/packet/packet.go b/src/pkg/crypto/openpgp/packet/packet.go index 1d7297e388..f7ed3536c5 100644 --- a/src/pkg/crypto/openpgp/packet/packet.go +++ b/src/pkg/crypto/openpgp/packet/packet.go @@ -11,23 +11,22 @@ import ( "crypto/aes" "crypto/cast5" "crypto/cipher" - "crypto/openpgp/error" + error_ "crypto/openpgp/error" "io" - "os" ) // readFull is the same as io.ReadFull except that reading zero bytes returns // ErrUnexpectedEOF rather than EOF. -func readFull(r io.Reader, buf []byte) (n int, err os.Error) { +func readFull(r io.Reader, buf []byte) (n int, err error) { n, err = io.ReadFull(r, buf) - if err == os.EOF { + if err == io.EOF { err = io.ErrUnexpectedEOF } return } // readLength reads an OpenPGP length from r. See RFC 4880, section 4.2.2. -func readLength(r io.Reader) (length int64, isPartial bool, err os.Error) { +func readLength(r io.Reader) (length int64, isPartial bool, err error) { var buf [4]byte _, err = readFull(r, buf[:1]) if err != nil { @@ -68,10 +67,10 @@ type partialLengthReader struct { isPartial bool } -func (r *partialLengthReader) Read(p []byte) (n int, err os.Error) { +func (r *partialLengthReader) Read(p []byte) (n int, err error) { for r.remaining == 0 { if !r.isPartial { - return 0, os.EOF + return 0, io.EOF } r.remaining, r.isPartial, err = readLength(r.r) if err != nil { @@ -86,7 +85,7 @@ func (r *partialLengthReader) Read(p []byte) (n int, err os.Error) { n, err = r.r.Read(p[:int(toRead)]) r.remaining -= int64(n) - if n < int(toRead) && err == os.EOF { + if n < int(toRead) && err == io.EOF { err = io.ErrUnexpectedEOF } return @@ -99,7 +98,7 @@ type partialLengthWriter struct { lengthByte [1]byte } -func (w *partialLengthWriter) Write(p []byte) (n int, err os.Error) { +func (w *partialLengthWriter) Write(p []byte) (n int, err error) { for len(p) > 0 { for power := uint(14); power < 32; power-- { l := 1 << power @@ -123,7 +122,7 @@ func (w *partialLengthWriter) Write(p []byte) (n int, err os.Error) { return } -func (w *partialLengthWriter) Close() os.Error { +func (w *partialLengthWriter) Close() error { w.lengthByte[0] = 0 _, err := w.w.Write(w.lengthByte[:]) if err != nil { @@ -139,16 +138,16 @@ type spanReader struct { n int64 } -func (l *spanReader) Read(p []byte) (n int, err os.Error) { +func (l *spanReader) Read(p []byte) (n int, err error) { if l.n <= 0 { - return 0, os.EOF + return 0, io.EOF } if int64(len(p)) > l.n { p = p[0:l.n] } n, err = l.r.Read(p) l.n -= int64(n) - if l.n > 0 && err == os.EOF { + if l.n > 0 && err == io.EOF { err = io.ErrUnexpectedEOF } return @@ -156,14 +155,14 @@ func (l *spanReader) Read(p []byte) (n int, err os.Error) { // readHeader parses a packet header and returns an io.Reader which will return // the contents of the packet. See RFC 4880, section 4.2. -func readHeader(r io.Reader) (tag packetType, length int64, contents io.Reader, err os.Error) { +func readHeader(r io.Reader) (tag packetType, length int64, contents io.Reader, err error) { var buf [4]byte _, err = io.ReadFull(r, buf[:1]) if err != nil { return } if buf[0]&0x80 == 0 { - err = error.StructuralError("tag byte does not have MSB set") + err = error_.StructuralError("tag byte does not have MSB set") return } if buf[0]&0x40 == 0 { @@ -209,7 +208,7 @@ func readHeader(r io.Reader) (tag packetType, length int64, contents io.Reader, // serializeHeader writes an OpenPGP packet header to w. See RFC 4880, section // 4.2. -func serializeHeader(w io.Writer, ptype packetType, length int) (err os.Error) { +func serializeHeader(w io.Writer, ptype packetType, length int) (err error) { var buf [6]byte var n int @@ -238,7 +237,7 @@ func serializeHeader(w io.Writer, ptype packetType, length int) (err os.Error) { // serializeStreamHeader writes an OpenPGP packet header to w where the // length of the packet is unknown. It returns a io.WriteCloser which can be // used to write the contents of the packet. See RFC 4880, section 4.2. -func serializeStreamHeader(w io.WriteCloser, ptype packetType) (out io.WriteCloser, err os.Error) { +func serializeStreamHeader(w io.WriteCloser, ptype packetType) (out io.WriteCloser, err error) { var buf [1]byte buf[0] = 0x80 | 0x40 | byte(ptype) _, err = w.Write(buf[:]) @@ -252,19 +251,19 @@ func serializeStreamHeader(w io.WriteCloser, ptype packetType) (out io.WriteClos // Packet represents an OpenPGP packet. Users are expected to try casting // instances of this interface to specific packet types. type Packet interface { - parse(io.Reader) os.Error + parse(io.Reader) error } // consumeAll reads from the given Reader until error, returning the number of // bytes read. -func consumeAll(r io.Reader) (n int64, err os.Error) { +func consumeAll(r io.Reader) (n int64, err error) { var m int var buf [1024]byte for { m, err = r.Read(buf[:]) n += int64(m) - if err == os.EOF { + if err == io.EOF { err = nil return } @@ -298,7 +297,7 @@ const ( // Read reads a single OpenPGP packet from the given io.Reader. If there is an // error parsing a packet, the whole packet is consumed from the input. -func Read(r io.Reader) (p Packet, err os.Error) { +func Read(r io.Reader) (p Packet, err error) { tag, _, contents, err := readHeader(r) if err != nil { return @@ -338,7 +337,7 @@ func Read(r io.Reader) (p Packet, err os.Error) { se.MDC = true p = se default: - err = error.UnknownPacketTypeError(tag) + err = error_.UnknownPacketTypeError(tag) } if p != nil { err = p.parse(contents) @@ -447,7 +446,7 @@ func (cipher CipherFunction) new(key []byte) (block cipher.Block) { // readMPI reads a big integer from r. The bit length returned is the bit // length that was specified in r. This is preserved so that the integer can be // reserialized exactly. -func readMPI(r io.Reader) (mpi []byte, bitLength uint16, err os.Error) { +func readMPI(r io.Reader) (mpi []byte, bitLength uint16, err error) { var buf [2]byte _, err = readFull(r, buf[0:]) if err != nil { @@ -469,7 +468,7 @@ func mpiLength(n *big.Int) (mpiLengthInBytes int) { } // writeMPI serializes a big integer to w. -func writeMPI(w io.Writer, bitLength uint16, mpiBytes []byte) (err os.Error) { +func writeMPI(w io.Writer, bitLength uint16, mpiBytes []byte) (err error) { _, err = w.Write([]byte{byte(bitLength >> 8), byte(bitLength)}) if err == nil { _, err = w.Write(mpiBytes) @@ -478,6 +477,6 @@ func writeMPI(w io.Writer, bitLength uint16, mpiBytes []byte) (err os.Error) { } // writeBig serializes a *big.Int to w. -func writeBig(w io.Writer, i *big.Int) os.Error { +func writeBig(w io.Writer, i *big.Int) error { return writeMPI(w, uint16(i.BitLen()), i.Bytes()) } diff --git a/src/pkg/crypto/openpgp/packet/packet_test.go b/src/pkg/crypto/openpgp/packet/packet_test.go index 23d9978ae1..53266413c8 100644 --- a/src/pkg/crypto/openpgp/packet/packet_test.go +++ b/src/pkg/crypto/openpgp/packet/packet_test.go @@ -6,12 +6,11 @@ package packet import ( "bytes" - "crypto/openpgp/error" + error_ "crypto/openpgp/error" "encoding/hex" "fmt" "io" "io/ioutil" - "os" "testing" ) @@ -49,7 +48,7 @@ var readLengthTests = []struct { hexInput string length int64 isPartial bool - err os.Error + err error }{ {"", 0, false, io.ErrUnexpectedEOF}, {"1f", 31, false, nil}, @@ -87,7 +86,7 @@ func TestReadLength(t *testing.T) { var partialLengthReaderTests = []struct { hexInput string - err os.Error + err error hexOutput string }{ {"e0", io.ErrUnexpectedEOF, ""}, @@ -153,14 +152,14 @@ func TestReadHeader(t *testing.T) { for i, test := range readHeaderTests { tag, length, contents, err := readHeader(readerFromHex(test.hexInput)) if test.structuralError { - if _, ok := err.(error.StructuralError); ok { + if _, ok := err.(error_.StructuralError); ok { continue } t.Errorf("%d: expected StructuralError, got:%s", i, err) continue } if err != nil { - if len(test.hexInput) == 0 && err == os.EOF { + if len(test.hexInput) == 0 && err == io.EOF { continue } if !test.unexpectedEOF || err != io.ErrUnexpectedEOF { diff --git a/src/pkg/crypto/openpgp/packet/private_key.go b/src/pkg/crypto/openpgp/packet/private_key.go index 6f8133d981..742ac51e6e 100644 --- a/src/pkg/crypto/openpgp/packet/private_key.go +++ b/src/pkg/crypto/openpgp/packet/private_key.go @@ -10,13 +10,12 @@ import ( "crypto/cipher" "crypto/dsa" "crypto/openpgp/elgamal" - "crypto/openpgp/error" + error_ "crypto/openpgp/error" "crypto/openpgp/s2k" "crypto/rsa" "crypto/sha1" "io" "io/ioutil" - "os" "strconv" ) @@ -40,7 +39,7 @@ func NewRSAPrivateKey(currentTimeSecs uint32, priv *rsa.PrivateKey, isSubkey boo return pk } -func (pk *PrivateKey) parse(r io.Reader) (err os.Error) { +func (pk *PrivateKey) parse(r io.Reader) (err error) { err = (&pk.PublicKey).parse(r) if err != nil { return @@ -72,13 +71,13 @@ func (pk *PrivateKey) parse(r io.Reader) (err os.Error) { pk.sha1Checksum = true } default: - return error.UnsupportedError("deprecated s2k function in private key") + return error_.UnsupportedError("deprecated s2k function in private key") } if pk.Encrypted { blockSize := pk.cipher.blockSize() if blockSize == 0 { - return error.UnsupportedError("unsupported cipher in private key: " + strconv.Itoa(int(pk.cipher))) + return error_.UnsupportedError("unsupported cipher in private key: " + strconv.Itoa(int(pk.cipher))) } pk.iv = make([]byte, blockSize) _, err = readFull(r, pk.iv) @@ -111,7 +110,7 @@ func mod64kHash(d []byte) uint16 { return h } -func (pk *PrivateKey) Serialize(w io.Writer) (err os.Error) { +func (pk *PrivateKey) Serialize(w io.Writer) (err error) { // TODO(agl): support encrypted private keys buf := bytes.NewBuffer(nil) err = pk.PublicKey.serializeWithoutHeaders(buf) @@ -126,7 +125,7 @@ func (pk *PrivateKey) Serialize(w io.Writer) (err os.Error) { case *rsa.PrivateKey: err = serializeRSAPrivateKey(privateKeyBuf, priv) default: - err = error.InvalidArgumentError("non-RSA private key") + err = error_.InvalidArgumentError("non-RSA private key") } if err != nil { return @@ -160,7 +159,7 @@ func (pk *PrivateKey) Serialize(w io.Writer) (err os.Error) { return } -func serializeRSAPrivateKey(w io.Writer, priv *rsa.PrivateKey) os.Error { +func serializeRSAPrivateKey(w io.Writer, priv *rsa.PrivateKey) error { err := writeBig(w, priv.D) if err != nil { return err @@ -177,7 +176,7 @@ func serializeRSAPrivateKey(w io.Writer, priv *rsa.PrivateKey) os.Error { } // Decrypt decrypts an encrypted private key using a passphrase. -func (pk *PrivateKey) Decrypt(passphrase []byte) os.Error { +func (pk *PrivateKey) Decrypt(passphrase []byte) error { if !pk.Encrypted { return nil } @@ -192,18 +191,18 @@ func (pk *PrivateKey) Decrypt(passphrase []byte) os.Error { if pk.sha1Checksum { if len(data) < sha1.Size { - return error.StructuralError("truncated private key data") + return error_.StructuralError("truncated private key data") } h := sha1.New() h.Write(data[:len(data)-sha1.Size]) sum := h.Sum() if !bytes.Equal(sum, data[len(data)-sha1.Size:]) { - return error.StructuralError("private key checksum failure") + return error_.StructuralError("private key checksum failure") } data = data[:len(data)-sha1.Size] } else { if len(data) < 2 { - return error.StructuralError("truncated private key data") + return error_.StructuralError("truncated private key data") } var sum uint16 for i := 0; i < len(data)-2; i++ { @@ -211,7 +210,7 @@ func (pk *PrivateKey) Decrypt(passphrase []byte) os.Error { } if data[len(data)-2] != uint8(sum>>8) || data[len(data)-1] != uint8(sum) { - return error.StructuralError("private key checksum failure") + return error_.StructuralError("private key checksum failure") } data = data[:len(data)-2] } @@ -219,7 +218,7 @@ func (pk *PrivateKey) Decrypt(passphrase []byte) os.Error { return pk.parsePrivateKey(data) } -func (pk *PrivateKey) parsePrivateKey(data []byte) (err os.Error) { +func (pk *PrivateKey) parsePrivateKey(data []byte) (err error) { switch pk.PublicKey.PubKeyAlgo { case PubKeyAlgoRSA, PubKeyAlgoRSASignOnly, PubKeyAlgoRSAEncryptOnly: return pk.parseRSAPrivateKey(data) @@ -231,7 +230,7 @@ func (pk *PrivateKey) parsePrivateKey(data []byte) (err os.Error) { panic("impossible") } -func (pk *PrivateKey) parseRSAPrivateKey(data []byte) (err os.Error) { +func (pk *PrivateKey) parseRSAPrivateKey(data []byte) (err error) { rsaPub := pk.PublicKey.PublicKey.(*rsa.PublicKey) rsaPriv := new(rsa.PrivateKey) rsaPriv.PublicKey = *rsaPub @@ -262,7 +261,7 @@ func (pk *PrivateKey) parseRSAPrivateKey(data []byte) (err os.Error) { return nil } -func (pk *PrivateKey) parseDSAPrivateKey(data []byte) (err os.Error) { +func (pk *PrivateKey) parseDSAPrivateKey(data []byte) (err error) { dsaPub := pk.PublicKey.PublicKey.(*dsa.PublicKey) dsaPriv := new(dsa.PrivateKey) dsaPriv.PublicKey = *dsaPub @@ -281,7 +280,7 @@ func (pk *PrivateKey) parseDSAPrivateKey(data []byte) (err os.Error) { return nil } -func (pk *PrivateKey) parseElGamalPrivateKey(data []byte) (err os.Error) { +func (pk *PrivateKey) parseElGamalPrivateKey(data []byte) (err error) { pub := pk.PublicKey.PublicKey.(*elgamal.PublicKey) priv := new(elgamal.PrivateKey) priv.PublicKey = *pub diff --git a/src/pkg/crypto/openpgp/packet/public_key.go b/src/pkg/crypto/openpgp/packet/public_key.go index e6b0ae5f3a..af0bc2273f 100644 --- a/src/pkg/crypto/openpgp/packet/public_key.go +++ b/src/pkg/crypto/openpgp/packet/public_key.go @@ -8,14 +8,13 @@ import ( "big" "crypto/dsa" "crypto/openpgp/elgamal" - "crypto/openpgp/error" + error_ "crypto/openpgp/error" "crypto/rsa" "crypto/sha1" "encoding/binary" "fmt" "hash" "io" - "os" "strconv" ) @@ -53,7 +52,7 @@ func NewRSAPublicKey(creationTimeSecs uint32, pub *rsa.PublicKey, isSubkey bool) return pk } -func (pk *PublicKey) parse(r io.Reader) (err os.Error) { +func (pk *PublicKey) parse(r io.Reader) (err error) { // RFC 4880, section 5.5.2 var buf [6]byte _, err = readFull(r, buf[:]) @@ -61,7 +60,7 @@ func (pk *PublicKey) parse(r io.Reader) (err os.Error) { return } if buf[0] != 4 { - return error.UnsupportedError("public key version") + return error_.UnsupportedError("public key version") } pk.CreationTime = uint32(buf[1])<<24 | uint32(buf[2])<<16 | uint32(buf[3])<<8 | uint32(buf[4]) pk.PubKeyAlgo = PublicKeyAlgorithm(buf[5]) @@ -73,7 +72,7 @@ func (pk *PublicKey) parse(r io.Reader) (err os.Error) { case PubKeyAlgoElGamal: err = pk.parseElGamal(r) default: - err = error.UnsupportedError("public key type: " + strconv.Itoa(int(pk.PubKeyAlgo))) + err = error_.UnsupportedError("public key type: " + strconv.Itoa(int(pk.PubKeyAlgo))) } if err != nil { return @@ -94,7 +93,7 @@ func (pk *PublicKey) setFingerPrintAndKeyId() { // parseRSA parses RSA public key material from the given Reader. See RFC 4880, // section 5.5.2. -func (pk *PublicKey) parseRSA(r io.Reader) (err os.Error) { +func (pk *PublicKey) parseRSA(r io.Reader) (err error) { pk.n.bytes, pk.n.bitLength, err = readMPI(r) if err != nil { return @@ -105,7 +104,7 @@ func (pk *PublicKey) parseRSA(r io.Reader) (err os.Error) { } if len(pk.e.bytes) > 3 { - err = error.UnsupportedError("large public exponent") + err = error_.UnsupportedError("large public exponent") return } rsa := &rsa.PublicKey{ @@ -122,7 +121,7 @@ func (pk *PublicKey) parseRSA(r io.Reader) (err os.Error) { // parseDSA parses DSA public key material from the given Reader. See RFC 4880, // section 5.5.2. -func (pk *PublicKey) parseDSA(r io.Reader) (err os.Error) { +func (pk *PublicKey) parseDSA(r io.Reader) (err error) { pk.p.bytes, pk.p.bitLength, err = readMPI(r) if err != nil { return @@ -151,7 +150,7 @@ func (pk *PublicKey) parseDSA(r io.Reader) (err os.Error) { // parseElGamal parses ElGamal public key material from the given Reader. See // RFC 4880, section 5.5.2. -func (pk *PublicKey) parseElGamal(r io.Reader) (err os.Error) { +func (pk *PublicKey) parseElGamal(r io.Reader) (err error) { pk.p.bytes, pk.p.bitLength, err = readMPI(r) if err != nil { return @@ -199,7 +198,7 @@ func (pk *PublicKey) SerializeSignaturePrefix(h hash.Hash) { return } -func (pk *PublicKey) Serialize(w io.Writer) (err os.Error) { +func (pk *PublicKey) Serialize(w io.Writer) (err error) { length := 6 // 6 byte header switch pk.PubKeyAlgo { @@ -232,7 +231,7 @@ func (pk *PublicKey) Serialize(w io.Writer) (err os.Error) { // serializeWithoutHeaders marshals the PublicKey to w in the form of an // OpenPGP public key packet, not including the packet header. -func (pk *PublicKey) serializeWithoutHeaders(w io.Writer) (err os.Error) { +func (pk *PublicKey) serializeWithoutHeaders(w io.Writer) (err error) { var buf [6]byte buf[0] = 4 buf[1] = byte(pk.CreationTime >> 24) @@ -254,7 +253,7 @@ func (pk *PublicKey) serializeWithoutHeaders(w io.Writer) (err os.Error) { case PubKeyAlgoElGamal: return writeMPIs(w, pk.p, pk.g, pk.y) } - return error.InvalidArgumentError("bad public-key algorithm") + return error_.InvalidArgumentError("bad public-key algorithm") } // CanSign returns true iff this public key can generate signatures @@ -264,20 +263,20 @@ func (pk *PublicKey) CanSign() bool { // VerifySignature returns nil iff sig is a valid signature, made by this // public key, of the data hashed into signed. signed is mutated by this call. -func (pk *PublicKey) VerifySignature(signed hash.Hash, sig *Signature) (err os.Error) { +func (pk *PublicKey) VerifySignature(signed hash.Hash, sig *Signature) (err error) { if !pk.CanSign() { - return error.InvalidArgumentError("public key cannot generate signatures") + return error_.InvalidArgumentError("public key cannot generate signatures") } signed.Write(sig.HashSuffix) hashBytes := signed.Sum() if hashBytes[0] != sig.HashTag[0] || hashBytes[1] != sig.HashTag[1] { - return error.SignatureError("hash tag doesn't match") + return error_.SignatureError("hash tag doesn't match") } if pk.PubKeyAlgo != sig.PubKeyAlgo { - return error.InvalidArgumentError("public key and signature use different algorithms") + return error_.InvalidArgumentError("public key and signature use different algorithms") } switch pk.PubKeyAlgo { @@ -285,13 +284,13 @@ func (pk *PublicKey) VerifySignature(signed hash.Hash, sig *Signature) (err os.E rsaPublicKey, _ := pk.PublicKey.(*rsa.PublicKey) err = rsa.VerifyPKCS1v15(rsaPublicKey, sig.Hash, hashBytes, sig.RSASignature.bytes) if err != nil { - return error.SignatureError("RSA verification failure") + return error_.SignatureError("RSA verification failure") } return nil case PubKeyAlgoDSA: dsaPublicKey, _ := pk.PublicKey.(*dsa.PublicKey) if !dsa.Verify(dsaPublicKey, hashBytes, new(big.Int).SetBytes(sig.DSASigR.bytes), new(big.Int).SetBytes(sig.DSASigS.bytes)) { - return error.SignatureError("DSA verification failure") + return error_.SignatureError("DSA verification failure") } return nil default: @@ -302,10 +301,10 @@ func (pk *PublicKey) VerifySignature(signed hash.Hash, sig *Signature) (err os.E // keySignatureHash returns a Hash of the message that needs to be signed for // pk to assert a subkey relationship to signed. -func keySignatureHash(pk, signed *PublicKey, sig *Signature) (h hash.Hash, err os.Error) { +func keySignatureHash(pk, signed *PublicKey, sig *Signature) (h hash.Hash, err error) { h = sig.Hash.New() if h == nil { - return nil, error.UnsupportedError("hash function") + return nil, error_.UnsupportedError("hash function") } // RFC 4880, section 5.2.4 @@ -318,7 +317,7 @@ func keySignatureHash(pk, signed *PublicKey, sig *Signature) (h hash.Hash, err o // VerifyKeySignature returns nil iff sig is a valid signature, made by this // public key, of signed. -func (pk *PublicKey) VerifyKeySignature(signed *PublicKey, sig *Signature) (err os.Error) { +func (pk *PublicKey) VerifyKeySignature(signed *PublicKey, sig *Signature) (err error) { h, err := keySignatureHash(pk, signed, sig) if err != nil { return err @@ -328,10 +327,10 @@ func (pk *PublicKey) VerifyKeySignature(signed *PublicKey, sig *Signature) (err // userIdSignatureHash returns a Hash of the message that needs to be signed // to assert that pk is a valid key for id. -func userIdSignatureHash(id string, pk *PublicKey, sig *Signature) (h hash.Hash, err os.Error) { +func userIdSignatureHash(id string, pk *PublicKey, sig *Signature) (h hash.Hash, err error) { h = sig.Hash.New() if h == nil { - return nil, error.UnsupportedError("hash function") + return nil, error_.UnsupportedError("hash function") } // RFC 4880, section 5.2.4 @@ -352,7 +351,7 @@ func userIdSignatureHash(id string, pk *PublicKey, sig *Signature) (h hash.Hash, // VerifyUserIdSignature returns nil iff sig is a valid signature, made by this // public key, of id. -func (pk *PublicKey) VerifyUserIdSignature(id string, sig *Signature) (err os.Error) { +func (pk *PublicKey) VerifyUserIdSignature(id string, sig *Signature) (err error) { h, err := userIdSignatureHash(id, pk, sig) if err != nil { return err @@ -382,7 +381,7 @@ type parsedMPI struct { // writeMPIs is a utility function for serializing several big integers to the // given Writer. -func writeMPIs(w io.Writer, mpis ...parsedMPI) (err os.Error) { +func writeMPIs(w io.Writer, mpis ...parsedMPI) (err error) { for _, mpi := range mpis { err = writeMPI(w, mpi.bitLength, mpi.bytes) if err != nil { diff --git a/src/pkg/crypto/openpgp/packet/reader.go b/src/pkg/crypto/openpgp/packet/reader.go index 5febc3bc8d..e3d733cb02 100644 --- a/src/pkg/crypto/openpgp/packet/reader.go +++ b/src/pkg/crypto/openpgp/packet/reader.go @@ -5,9 +5,8 @@ package packet import ( - "crypto/openpgp/error" + error_ "crypto/openpgp/error" "io" - "os" ) // Reader reads packets from an io.Reader and allows packets to be 'unread' so @@ -19,7 +18,7 @@ type Reader struct { // Next returns the most recently unread Packet, or reads another packet from // the top-most io.Reader. Unknown packet types are skipped. -func (r *Reader) Next() (p Packet, err os.Error) { +func (r *Reader) Next() (p Packet, err error) { if len(r.q) > 0 { p = r.q[len(r.q)-1] r.q = r.q[:len(r.q)-1] @@ -31,16 +30,16 @@ func (r *Reader) Next() (p Packet, err os.Error) { if err == nil { return } - if err == os.EOF { + if err == io.EOF { r.readers = r.readers[:len(r.readers)-1] continue } - if _, ok := err.(error.UnknownPacketTypeError); !ok { + if _, ok := err.(error_.UnknownPacketTypeError); !ok { return nil, err } } - return nil, os.EOF + return nil, io.EOF } // Push causes the Reader to start reading from a new io.Reader. When an EOF diff --git a/src/pkg/crypto/openpgp/packet/signature.go b/src/pkg/crypto/openpgp/packet/signature.go index 7577e28758..4ebb906cad 100644 --- a/src/pkg/crypto/openpgp/packet/signature.go +++ b/src/pkg/crypto/openpgp/packet/signature.go @@ -7,14 +7,13 @@ package packet import ( "crypto" "crypto/dsa" - "crypto/openpgp/error" + error_ "crypto/openpgp/error" "crypto/openpgp/s2k" "crypto/rand" "crypto/rsa" "encoding/binary" "hash" "io" - "os" "strconv" ) @@ -53,7 +52,7 @@ type Signature struct { outSubpackets []outputSubpacket } -func (sig *Signature) parse(r io.Reader) (err os.Error) { +func (sig *Signature) parse(r io.Reader) (err error) { // RFC 4880, section 5.2.3 var buf [5]byte _, err = readFull(r, buf[:1]) @@ -61,7 +60,7 @@ func (sig *Signature) parse(r io.Reader) (err os.Error) { return } if buf[0] != 4 { - err = error.UnsupportedError("signature packet version " + strconv.Itoa(int(buf[0]))) + err = error_.UnsupportedError("signature packet version " + strconv.Itoa(int(buf[0]))) return } @@ -74,14 +73,14 @@ func (sig *Signature) parse(r io.Reader) (err os.Error) { switch sig.PubKeyAlgo { case PubKeyAlgoRSA, PubKeyAlgoRSASignOnly, PubKeyAlgoDSA: default: - err = error.UnsupportedError("public key algorithm " + strconv.Itoa(int(sig.PubKeyAlgo))) + err = error_.UnsupportedError("public key algorithm " + strconv.Itoa(int(sig.PubKeyAlgo))) return } var ok bool sig.Hash, ok = s2k.HashIdToHash(buf[2]) if !ok { - return error.UnsupportedError("hash function " + strconv.Itoa(int(buf[2]))) + return error_.UnsupportedError("hash function " + strconv.Itoa(int(buf[2]))) } hashedSubpacketsLength := int(buf[3])<<8 | int(buf[4]) @@ -144,7 +143,7 @@ func (sig *Signature) parse(r io.Reader) (err os.Error) { // parseSignatureSubpackets parses subpackets of the main signature packet. See // RFC 4880, section 5.2.3.1. -func parseSignatureSubpackets(sig *Signature, subpackets []byte, isHashed bool) (err os.Error) { +func parseSignatureSubpackets(sig *Signature, subpackets []byte, isHashed bool) (err error) { for len(subpackets) > 0 { subpackets, err = parseSignatureSubpacket(sig, subpackets, isHashed) if err != nil { @@ -153,7 +152,7 @@ func parseSignatureSubpackets(sig *Signature, subpackets []byte, isHashed bool) } if sig.CreationTime == 0 { - err = error.StructuralError("no creation time in signature") + err = error_.StructuralError("no creation time in signature") } return @@ -174,7 +173,7 @@ const ( ) // parseSignatureSubpacket parses a single subpacket. len(subpacket) is >= 1. -func parseSignatureSubpacket(sig *Signature, subpacket []byte, isHashed bool) (rest []byte, err os.Error) { +func parseSignatureSubpacket(sig *Signature, subpacket []byte, isHashed bool) (rest []byte, err error) { // RFC 4880, section 5.2.3.1 var ( length uint32 @@ -207,7 +206,7 @@ func parseSignatureSubpacket(sig *Signature, subpacket []byte, isHashed bool) (r rest = subpacket[length:] subpacket = subpacket[:length] if len(subpacket) == 0 { - err = error.StructuralError("zero length signature subpacket") + err = error_.StructuralError("zero length signature subpacket") return } packetType = signatureSubpacketType(subpacket[0] & 0x7f) @@ -217,11 +216,11 @@ func parseSignatureSubpacket(sig *Signature, subpacket []byte, isHashed bool) (r switch packetType { case creationTimeSubpacket: if !isHashed { - err = error.StructuralError("signature creation time in non-hashed area") + err = error_.StructuralError("signature creation time in non-hashed area") return } if len(subpacket) != 4 { - err = error.StructuralError("signature creation time not four bytes") + err = error_.StructuralError("signature creation time not four bytes") return } sig.CreationTime = binary.BigEndian.Uint32(subpacket) @@ -231,7 +230,7 @@ func parseSignatureSubpacket(sig *Signature, subpacket []byte, isHashed bool) (r return } if len(subpacket) != 4 { - err = error.StructuralError("expiration subpacket with bad length") + err = error_.StructuralError("expiration subpacket with bad length") return } sig.SigLifetimeSecs = new(uint32) @@ -242,7 +241,7 @@ func parseSignatureSubpacket(sig *Signature, subpacket []byte, isHashed bool) (r return } if len(subpacket) != 4 { - err = error.StructuralError("key expiration subpacket with bad length") + err = error_.StructuralError("key expiration subpacket with bad length") return } sig.KeyLifetimeSecs = new(uint32) @@ -257,7 +256,7 @@ func parseSignatureSubpacket(sig *Signature, subpacket []byte, isHashed bool) (r case issuerSubpacket: // Issuer, section 5.2.3.5 if len(subpacket) != 8 { - err = error.StructuralError("issuer subpacket with bad length") + err = error_.StructuralError("issuer subpacket with bad length") return } sig.IssuerKeyId = new(uint64) @@ -282,7 +281,7 @@ func parseSignatureSubpacket(sig *Signature, subpacket []byte, isHashed bool) (r return } if len(subpacket) != 1 { - err = error.StructuralError("primary user id subpacket with bad length") + err = error_.StructuralError("primary user id subpacket with bad length") return } sig.IsPrimaryId = new(bool) @@ -295,7 +294,7 @@ func parseSignatureSubpacket(sig *Signature, subpacket []byte, isHashed bool) (r return } if len(subpacket) == 0 { - err = error.StructuralError("empty key flags subpacket") + err = error_.StructuralError("empty key flags subpacket") return } sig.FlagsValid = true @@ -314,14 +313,14 @@ func parseSignatureSubpacket(sig *Signature, subpacket []byte, isHashed bool) (r default: if isCritical { - err = error.UnsupportedError("unknown critical signature subpacket type " + strconv.Itoa(int(packetType))) + err = error_.UnsupportedError("unknown critical signature subpacket type " + strconv.Itoa(int(packetType))) return } } return Truncated: - err = error.StructuralError("signature subpacket truncated") + err = error_.StructuralError("signature subpacket truncated") return } @@ -384,7 +383,7 @@ func serializeSubpackets(to []byte, subpackets []outputSubpacket, hashed bool) { } // buildHashSuffix constructs the HashSuffix member of sig in preparation for signing. -func (sig *Signature) buildHashSuffix() (err os.Error) { +func (sig *Signature) buildHashSuffix() (err error) { hashedSubpacketsLen := subpacketsLength(sig.outSubpackets, true) var ok bool @@ -396,7 +395,7 @@ func (sig *Signature) buildHashSuffix() (err os.Error) { sig.HashSuffix[3], ok = s2k.HashToHashId(sig.Hash) if !ok { sig.HashSuffix = nil - return error.InvalidArgumentError("hash cannot be represented in OpenPGP: " + strconv.Itoa(int(sig.Hash))) + return error_.InvalidArgumentError("hash cannot be represented in OpenPGP: " + strconv.Itoa(int(sig.Hash))) } sig.HashSuffix[4] = byte(hashedSubpacketsLen >> 8) sig.HashSuffix[5] = byte(hashedSubpacketsLen) @@ -411,7 +410,7 @@ func (sig *Signature) buildHashSuffix() (err os.Error) { return } -func (sig *Signature) signPrepareHash(h hash.Hash) (digest []byte, err os.Error) { +func (sig *Signature) signPrepareHash(h hash.Hash) (digest []byte, err error) { err = sig.buildHashSuffix() if err != nil { return @@ -426,7 +425,7 @@ func (sig *Signature) signPrepareHash(h hash.Hash) (digest []byte, err os.Error) // Sign signs a message with a private key. The hash, h, must contain // the hash of the message to be signed and will be mutated by this function. // On success, the signature is stored in sig. Call Serialize to write it out. -func (sig *Signature) Sign(h hash.Hash, priv *PrivateKey) (err os.Error) { +func (sig *Signature) Sign(h hash.Hash, priv *PrivateKey) (err error) { sig.outSubpackets = sig.buildSubpackets() digest, err := sig.signPrepareHash(h) if err != nil { @@ -446,7 +445,7 @@ func (sig *Signature) Sign(h hash.Hash, priv *PrivateKey) (err os.Error) { sig.DSASigS.bitLength = uint16(8 * len(sig.DSASigS.bytes)) } default: - err = error.UnsupportedError("public key algorithm: " + strconv.Itoa(int(sig.PubKeyAlgo))) + err = error_.UnsupportedError("public key algorithm: " + strconv.Itoa(int(sig.PubKeyAlgo))) } return @@ -455,7 +454,7 @@ func (sig *Signature) Sign(h hash.Hash, priv *PrivateKey) (err os.Error) { // SignUserId computes a signature from priv, asserting that pub is a valid // key for the identity id. On success, the signature is stored in sig. Call // Serialize to write it out. -func (sig *Signature) SignUserId(id string, pub *PublicKey, priv *PrivateKey) os.Error { +func (sig *Signature) SignUserId(id string, pub *PublicKey, priv *PrivateKey) error { h, err := userIdSignatureHash(id, pub, sig) if err != nil { return nil @@ -465,7 +464,7 @@ func (sig *Signature) SignUserId(id string, pub *PublicKey, priv *PrivateKey) os // SignKey computes a signature from priv, asserting that pub is a subkey. On // success, the signature is stored in sig. Call Serialize to write it out. -func (sig *Signature) SignKey(pub *PublicKey, priv *PrivateKey) os.Error { +func (sig *Signature) SignKey(pub *PublicKey, priv *PrivateKey) error { h, err := keySignatureHash(&priv.PublicKey, pub, sig) if err != nil { return err @@ -474,12 +473,12 @@ func (sig *Signature) SignKey(pub *PublicKey, priv *PrivateKey) os.Error { } // Serialize marshals sig to w. SignRSA or SignDSA must have been called first. -func (sig *Signature) Serialize(w io.Writer) (err os.Error) { +func (sig *Signature) Serialize(w io.Writer) (err error) { if len(sig.outSubpackets) == 0 { sig.outSubpackets = sig.rawSubpackets } if sig.RSASignature.bytes == nil && sig.DSASigR.bytes == nil { - return error.InvalidArgumentError("Signature: need to call SignRSA or SignDSA before Serialize") + return error_.InvalidArgumentError("Signature: need to call SignRSA or SignDSA before Serialize") } sigLength := 0 diff --git a/src/pkg/crypto/openpgp/packet/symmetric_key_encrypted.go b/src/pkg/crypto/openpgp/packet/symmetric_key_encrypted.go index ad4f1d6212..76d5151379 100644 --- a/src/pkg/crypto/openpgp/packet/symmetric_key_encrypted.go +++ b/src/pkg/crypto/openpgp/packet/symmetric_key_encrypted.go @@ -7,10 +7,9 @@ package packet import ( "bytes" "crypto/cipher" - "crypto/openpgp/error" + error_ "crypto/openpgp/error" "crypto/openpgp/s2k" "io" - "os" "strconv" ) @@ -30,7 +29,7 @@ type SymmetricKeyEncrypted struct { const symmetricKeyEncryptedVersion = 4 -func (ske *SymmetricKeyEncrypted) parse(r io.Reader) (err os.Error) { +func (ske *SymmetricKeyEncrypted) parse(r io.Reader) (err error) { // RFC 4880, section 5.3. var buf [2]byte _, err = readFull(r, buf[:]) @@ -38,12 +37,12 @@ func (ske *SymmetricKeyEncrypted) parse(r io.Reader) (err os.Error) { return } if buf[0] != symmetricKeyEncryptedVersion { - return error.UnsupportedError("SymmetricKeyEncrypted version") + return error_.UnsupportedError("SymmetricKeyEncrypted version") } ske.CipherFunc = CipherFunction(buf[1]) if ske.CipherFunc.KeySize() == 0 { - return error.UnsupportedError("unknown cipher: " + strconv.Itoa(int(buf[1]))) + return error_.UnsupportedError("unknown cipher: " + strconv.Itoa(int(buf[1]))) } ske.s2k, err = s2k.Parse(r) @@ -61,7 +60,7 @@ func (ske *SymmetricKeyEncrypted) parse(r io.Reader) (err os.Error) { err = nil if n != 0 { if n == maxSessionKeySizeInBytes { - return error.UnsupportedError("oversized encrypted session key") + return error_.UnsupportedError("oversized encrypted session key") } ske.encryptedKey = encryptedKey[:n] } @@ -73,7 +72,7 @@ func (ske *SymmetricKeyEncrypted) parse(r io.Reader) (err os.Error) { // Decrypt attempts to decrypt an encrypted session key. If it returns nil, // ske.Key will contain the session key. -func (ske *SymmetricKeyEncrypted) Decrypt(passphrase []byte) os.Error { +func (ske *SymmetricKeyEncrypted) Decrypt(passphrase []byte) error { if !ske.Encrypted { return nil } @@ -90,13 +89,13 @@ func (ske *SymmetricKeyEncrypted) Decrypt(passphrase []byte) os.Error { c.XORKeyStream(ske.encryptedKey, ske.encryptedKey) ske.CipherFunc = CipherFunction(ske.encryptedKey[0]) if ske.CipherFunc.blockSize() == 0 { - return error.UnsupportedError("unknown cipher: " + strconv.Itoa(int(ske.CipherFunc))) + return error_.UnsupportedError("unknown cipher: " + strconv.Itoa(int(ske.CipherFunc))) } ske.CipherFunc = CipherFunction(ske.encryptedKey[0]) ske.Key = ske.encryptedKey[1:] if len(ske.Key)%ske.CipherFunc.blockSize() != 0 { ske.Key = nil - return error.StructuralError("length of decrypted key not a multiple of block size") + return error_.StructuralError("length of decrypted key not a multiple of block size") } } @@ -108,10 +107,10 @@ func (ske *SymmetricKeyEncrypted) Decrypt(passphrase []byte) os.Error { // packet contains a random session key, encrypted by a key derived from the // given passphrase. The session key is returned and must be passed to // SerializeSymmetricallyEncrypted. -func SerializeSymmetricKeyEncrypted(w io.Writer, rand io.Reader, passphrase []byte, cipherFunc CipherFunction) (key []byte, err os.Error) { +func SerializeSymmetricKeyEncrypted(w io.Writer, rand io.Reader, passphrase []byte, cipherFunc CipherFunction) (key []byte, err error) { keySize := cipherFunc.KeySize() if keySize == 0 { - return nil, error.UnsupportedError("unknown cipher: " + strconv.Itoa(int(cipherFunc))) + return nil, error_.UnsupportedError("unknown cipher: " + strconv.Itoa(int(cipherFunc))) } s2kBuf := new(bytes.Buffer) diff --git a/src/pkg/crypto/openpgp/packet/symmetric_key_encrypted_test.go b/src/pkg/crypto/openpgp/packet/symmetric_key_encrypted_test.go index 823ec400d4..87690f0b7b 100644 --- a/src/pkg/crypto/openpgp/packet/symmetric_key_encrypted_test.go +++ b/src/pkg/crypto/openpgp/packet/symmetric_key_encrypted_test.go @@ -8,8 +8,8 @@ import ( "bytes" "crypto/rand" "encoding/hex" + "io" "io/ioutil" - "os" "testing" ) @@ -48,7 +48,7 @@ func TestSymmetricKeyEncrypted(t *testing.T) { } contents, err := ioutil.ReadAll(r) - if err != nil && err != os.EOF { + if err != nil && err != io.EOF { t.Error(err) return } diff --git a/src/pkg/crypto/openpgp/packet/symmetrically_encrypted.go b/src/pkg/crypto/openpgp/packet/symmetrically_encrypted.go index e33c9f3a06..8225db6d2f 100644 --- a/src/pkg/crypto/openpgp/packet/symmetrically_encrypted.go +++ b/src/pkg/crypto/openpgp/packet/symmetrically_encrypted.go @@ -6,13 +6,12 @@ package packet import ( "crypto/cipher" - "crypto/openpgp/error" + error_ "crypto/openpgp/error" "crypto/rand" "crypto/sha1" "crypto/subtle" "hash" "io" - "os" "strconv" ) @@ -27,7 +26,7 @@ type SymmetricallyEncrypted struct { const symmetricallyEncryptedVersion = 1 -func (se *SymmetricallyEncrypted) parse(r io.Reader) os.Error { +func (se *SymmetricallyEncrypted) parse(r io.Reader) error { if se.MDC { // See RFC 4880, section 5.13. var buf [1]byte @@ -36,7 +35,7 @@ func (se *SymmetricallyEncrypted) parse(r io.Reader) os.Error { return err } if buf[0] != symmetricallyEncryptedVersion { - return error.UnsupportedError("unknown SymmetricallyEncrypted version") + return error_.UnsupportedError("unknown SymmetricallyEncrypted version") } } se.contents = r @@ -46,13 +45,13 @@ func (se *SymmetricallyEncrypted) parse(r io.Reader) os.Error { // Decrypt returns a ReadCloser, from which the decrypted contents of the // packet can be read. An incorrect key can, with high probability, be detected // immediately and this will result in a KeyIncorrect error being returned. -func (se *SymmetricallyEncrypted) Decrypt(c CipherFunction, key []byte) (io.ReadCloser, os.Error) { +func (se *SymmetricallyEncrypted) Decrypt(c CipherFunction, key []byte) (io.ReadCloser, error) { keySize := c.KeySize() if keySize == 0 { - return nil, error.UnsupportedError("unknown cipher: " + strconv.Itoa(int(c))) + return nil, error_.UnsupportedError("unknown cipher: " + strconv.Itoa(int(c))) } if len(key) != keySize { - return nil, error.InvalidArgumentError("SymmetricallyEncrypted: incorrect key length") + return nil, error_.InvalidArgumentError("SymmetricallyEncrypted: incorrect key length") } if se.prefix == nil { @@ -62,7 +61,7 @@ func (se *SymmetricallyEncrypted) Decrypt(c CipherFunction, key []byte) (io.Read return nil, err } } else if len(se.prefix) != c.blockSize()+2 { - return nil, error.InvalidArgumentError("can't try ciphers with different block lengths") + return nil, error_.InvalidArgumentError("can't try ciphers with different block lengths") } ocfbResync := cipher.OCFBResync @@ -73,7 +72,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, error.KeyIncorrectError + return nil, error_.KeyIncorrectError } plaintext := cipher.StreamReader{S: s, R: se.contents} @@ -94,11 +93,11 @@ type seReader struct { in io.Reader } -func (ser seReader) Read(buf []byte) (int, os.Error) { +func (ser seReader) Read(buf []byte) (int, error) { return ser.in.Read(buf) } -func (ser seReader) Close() os.Error { +func (ser seReader) Close() error { return nil } @@ -118,13 +117,13 @@ type seMDCReader struct { eof bool } -func (ser *seMDCReader) Read(buf []byte) (n int, err os.Error) { +func (ser *seMDCReader) Read(buf []byte) (n int, err error) { if ser.error { err = io.ErrUnexpectedEOF return } if ser.eof { - err = os.EOF + err = io.EOF return } @@ -133,7 +132,7 @@ func (ser *seMDCReader) Read(buf []byte) (n int, err os.Error) { for ser.trailerUsed < mdcTrailerSize { n, err = ser.in.Read(ser.trailer[ser.trailerUsed:]) ser.trailerUsed += n - if err == os.EOF { + if err == io.EOF { if ser.trailerUsed != mdcTrailerSize { n = 0 err = io.ErrUnexpectedEOF @@ -161,7 +160,7 @@ func (ser *seMDCReader) Read(buf []byte) (n int, err os.Error) { copy(ser.trailer[mdcTrailerSize-n:], ser.scratch[:]) if n < len(buf) { ser.eof = true - err = os.EOF + err = io.EOF } return } @@ -171,7 +170,7 @@ func (ser *seMDCReader) Read(buf []byte) (n int, err os.Error) { ser.h.Write(buf[:n]) copy(ser.trailer[:], buf[n:]) - if err == os.EOF { + if err == io.EOF { ser.eof = true } return @@ -180,31 +179,31 @@ func (ser *seMDCReader) Read(buf []byte) (n int, err os.Error) { // This is a new-format packet tag byte for a type 19 (MDC) packet. const mdcPacketTagByte = byte(0x80) | 0x40 | 19 -func (ser *seMDCReader) Close() os.Error { +func (ser *seMDCReader) Close() error { if ser.error { - return error.SignatureError("error during reading") + return error_.SignatureError("error during reading") } for !ser.eof { // We haven't seen EOF so we need to read to the end var buf [1024]byte _, err := ser.Read(buf[:]) - if err == os.EOF { + if err == io.EOF { break } if err != nil { - return error.SignatureError("error during reading") + return error_.SignatureError("error during reading") } } if ser.trailer[0] != mdcPacketTagByte || ser.trailer[1] != sha1.Size { - return error.SignatureError("MDC packet not found") + return error_.SignatureError("MDC packet not found") } ser.h.Write(ser.trailer[:2]) final := ser.h.Sum() if subtle.ConstantTimeCompare(final, ser.trailer[2:]) != 1 { - return error.SignatureError("hash mismatch") + return error_.SignatureError("hash mismatch") } return nil } @@ -217,12 +216,12 @@ type seMDCWriter struct { h hash.Hash } -func (w *seMDCWriter) Write(buf []byte) (n int, err os.Error) { +func (w *seMDCWriter) Write(buf []byte) (n int, err error) { w.h.Write(buf) return w.w.Write(buf) } -func (w *seMDCWriter) Close() (err os.Error) { +func (w *seMDCWriter) Close() (err error) { var buf [mdcTrailerSize]byte buf[0] = mdcPacketTagByte @@ -243,20 +242,20 @@ type noOpCloser struct { w io.Writer } -func (c noOpCloser) Write(data []byte) (n int, err os.Error) { +func (c noOpCloser) Write(data []byte) (n int, err error) { return c.w.Write(data) } -func (c noOpCloser) Close() os.Error { +func (c noOpCloser) Close() error { return nil } // SerializeSymmetricallyEncrypted serializes a symmetrically encrypted packet // to w and returns a WriteCloser to which the to-be-encrypted packets can be // written. -func SerializeSymmetricallyEncrypted(w io.Writer, c CipherFunction, key []byte) (contents io.WriteCloser, err os.Error) { +func SerializeSymmetricallyEncrypted(w io.Writer, c CipherFunction, key []byte) (contents io.WriteCloser, err error) { if c.KeySize() != len(key) { - return nil, error.InvalidArgumentError("SymmetricallyEncrypted.Serialize: bad key length") + return nil, error_.InvalidArgumentError("SymmetricallyEncrypted.Serialize: bad key length") } writeCloser := noOpCloser{w} ciphertext, err := serializeStreamHeader(writeCloser, packetTypeSymmetricallyEncryptedMDC) diff --git a/src/pkg/crypto/openpgp/packet/symmetrically_encrypted_test.go b/src/pkg/crypto/openpgp/packet/symmetrically_encrypted_test.go index 1054fc2f91..8eee971398 100644 --- a/src/pkg/crypto/openpgp/packet/symmetrically_encrypted_test.go +++ b/src/pkg/crypto/openpgp/packet/symmetrically_encrypted_test.go @@ -6,12 +6,11 @@ package packet import ( "bytes" - "crypto/openpgp/error" + error_ "crypto/openpgp/error" "crypto/sha1" "encoding/hex" "io" "io/ioutil" - "os" "testing" ) @@ -21,7 +20,7 @@ type testReader struct { stride int } -func (t *testReader) Read(buf []byte) (n int, err os.Error) { +func (t *testReader) Read(buf []byte) (n int, err error) { n = t.stride if n > len(t.data) { n = len(t.data) @@ -32,7 +31,7 @@ func (t *testReader) Read(buf []byte) (n int, err os.Error) { copy(buf, t.data) t.data = t.data[n:] if len(t.data) == 0 { - err = os.EOF + err = io.EOF } return } @@ -71,7 +70,7 @@ func testMDCReader(t *testing.T) { err = mdcReader.Close() if err == nil { t.Error("corruption: no error") - } else if _, ok := err.(*error.SignatureError); !ok { + } else if _, ok := err.(*error_.SignatureError); !ok { t.Errorf("corruption: expected SignatureError, got: %s", err) } } diff --git a/src/pkg/crypto/openpgp/packet/userid.go b/src/pkg/crypto/openpgp/packet/userid.go index 0580ba3edc..d6bea7d4ac 100644 --- a/src/pkg/crypto/openpgp/packet/userid.go +++ b/src/pkg/crypto/openpgp/packet/userid.go @@ -7,7 +7,6 @@ package packet import ( "io" "io/ioutil" - "os" "strings" ) @@ -65,7 +64,7 @@ func NewUserId(name, comment, email string) *UserId { return uid } -func (uid *UserId) parse(r io.Reader) (err os.Error) { +func (uid *UserId) parse(r io.Reader) (err error) { // RFC 4880, section 5.11 b, err := ioutil.ReadAll(r) if err != nil { @@ -78,7 +77,7 @@ func (uid *UserId) parse(r io.Reader) (err os.Error) { // Serialize marshals uid to w in the form of an OpenPGP packet, including // header. -func (uid *UserId) Serialize(w io.Writer) os.Error { +func (uid *UserId) Serialize(w io.Writer) error { err := serializeHeader(w, packetTypeUserId, len(uid.Id)) if err != nil { return err diff --git a/src/pkg/crypto/openpgp/read.go b/src/pkg/crypto/openpgp/read.go index d95f613c62..76fb1ead9f 100644 --- a/src/pkg/crypto/openpgp/read.go +++ b/src/pkg/crypto/openpgp/read.go @@ -8,12 +8,11 @@ package openpgp import ( "crypto" "crypto/openpgp/armor" - "crypto/openpgp/error" + error_ "crypto/openpgp/error" "crypto/openpgp/packet" _ "crypto/sha256" "hash" "io" - "os" "strconv" ) @@ -21,14 +20,14 @@ import ( var SignatureType = "PGP SIGNATURE" // readArmored reads an armored block with the given type. -func readArmored(r io.Reader, expectedType string) (body io.Reader, err os.Error) { +func readArmored(r io.Reader, expectedType string) (body io.Reader, err error) { block, err := armor.Decode(r) if err != nil { return } if block.Type != expectedType { - return nil, error.InvalidArgumentError("expected '" + expectedType + "', got: " + block.Type) + return nil, error_.InvalidArgumentError("expected '" + expectedType + "', got: " + block.Type) } return block.Body, nil @@ -56,7 +55,7 @@ type MessageDetails struct { // been consumed. Once EOF has been seen, the following fields are // valid. (An authentication code failure is reported as a // SignatureError error when reading from UnverifiedBody.) - SignatureError os.Error // nil if the signature is good. + SignatureError error // nil if the signature is good. Signature *packet.Signature // the signature packet itself. decrypted io.ReadCloser @@ -69,7 +68,7 @@ type MessageDetails struct { // passphrase to try. If the decrypted private key or given passphrase isn't // correct, the function will be called again, forever. Any error returned will // be passed up. -type PromptFunction func(keys []Key, symmetric bool) ([]byte, os.Error) +type PromptFunction func(keys []Key, symmetric bool) ([]byte, error) // A keyEnvelopePair is used to store a private key with the envelope that // contains a symmetric key, encrypted with that key. @@ -81,7 +80,7 @@ type keyEnvelopePair struct { // ReadMessage parses an OpenPGP message that may be signed and/or encrypted. // The given KeyRing should contain both public keys (for signature // verification) and, possibly encrypted, private keys for decrypting. -func ReadMessage(r io.Reader, keyring KeyRing, prompt PromptFunction) (md *MessageDetails, err os.Error) { +func ReadMessage(r io.Reader, keyring KeyRing, prompt PromptFunction) (md *MessageDetails, err error) { var p packet.Packet var symKeys []*packet.SymmetricKeyEncrypted @@ -131,7 +130,7 @@ ParsePackets: case *packet.Compressed, *packet.LiteralData, *packet.OnePassSignature: // This message isn't encrypted. if len(symKeys) != 0 || len(pubKeys) != 0 { - return nil, error.StructuralError("key material not followed by encrypted message") + return nil, error_.StructuralError("key material not followed by encrypted message") } packets.Unread(p) return readSignedMessage(packets, nil, keyring) @@ -162,7 +161,7 @@ FindKey: continue } decrypted, err = se.Decrypt(pk.encryptedKey.CipherFunc, pk.encryptedKey.Key) - if err != nil && err != error.KeyIncorrectError { + if err != nil && err != error_.KeyIncorrectError { return nil, err } if decrypted != nil { @@ -180,11 +179,11 @@ FindKey: } if len(candidates) == 0 && len(symKeys) == 0 { - return nil, error.KeyIncorrectError + return nil, error_.KeyIncorrectError } if prompt == nil { - return nil, error.KeyIncorrectError + return nil, error_.KeyIncorrectError } passphrase, err := prompt(candidates, len(symKeys) != 0) @@ -198,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 != error.KeyIncorrectError { + if err != nil && err != error_.KeyIncorrectError { return nil, err } if decrypted != nil { @@ -218,7 +217,7 @@ FindKey: // readSignedMessage reads a possibly signed message if mdin is non-zero then // that structure is updated and returned. Otherwise a fresh MessageDetails is // used. -func readSignedMessage(packets *packet.Reader, mdin *MessageDetails, keyring KeyRing) (md *MessageDetails, err os.Error) { +func readSignedMessage(packets *packet.Reader, mdin *MessageDetails, keyring KeyRing) (md *MessageDetails, err error) { if mdin == nil { mdin = new(MessageDetails) } @@ -238,7 +237,7 @@ FindLiteralData: packets.Push(p.Body) case *packet.OnePassSignature: if !p.IsLast { - return nil, error.UnsupportedError("nested signatures") + return nil, error_.UnsupportedError("nested signatures") } h, wrappedHash, err = hashForSignature(p.Hash, p.SigType) @@ -279,10 +278,10 @@ FindLiteralData: // should be preprocessed (i.e. to normalize line endings). Thus this function // returns two hashes. The second should be used to hash the message itself and // performs any needed preprocessing. -func hashForSignature(hashId crypto.Hash, sigType packet.SignatureType) (hash.Hash, hash.Hash, os.Error) { +func hashForSignature(hashId crypto.Hash, sigType packet.SignatureType) (hash.Hash, hash.Hash, error) { h := hashId.New() if h == nil { - return nil, nil, error.UnsupportedError("hash not available: " + strconv.Itoa(int(hashId))) + return nil, nil, error_.UnsupportedError("hash not available: " + strconv.Itoa(int(hashId))) } switch sigType { @@ -292,7 +291,7 @@ func hashForSignature(hashId crypto.Hash, sigType packet.SignatureType) (hash.Ha return h, NewCanonicalTextHash(h), nil } - return nil, nil, error.UnsupportedError("unsupported signature type: " + strconv.Itoa(int(sigType))) + return nil, nil, error_.UnsupportedError("unsupported signature type: " + strconv.Itoa(int(sigType))) } // checkReader wraps an io.Reader from a LiteralData packet. When it sees EOF @@ -302,9 +301,9 @@ type checkReader struct { md *MessageDetails } -func (cr checkReader) Read(buf []byte) (n int, err os.Error) { +func (cr checkReader) Read(buf []byte) (n int, err error) { n, err = cr.md.LiteralData.Body.Read(buf) - if err == os.EOF { + if err == io.EOF { mdcErr := cr.md.decrypted.Close() if mdcErr != nil { err = mdcErr @@ -322,10 +321,10 @@ type signatureCheckReader struct { md *MessageDetails } -func (scr *signatureCheckReader) Read(buf []byte) (n int, err os.Error) { +func (scr *signatureCheckReader) Read(buf []byte) (n int, err error) { n, err = scr.md.LiteralData.Body.Read(buf) scr.wrappedHash.Write(buf[:n]) - if err == os.EOF { + if err == io.EOF { var p packet.Packet p, scr.md.SignatureError = scr.packets.Next() if scr.md.SignatureError != nil { @@ -334,7 +333,7 @@ func (scr *signatureCheckReader) Read(buf []byte) (n int, err os.Error) { var ok bool if scr.md.Signature, ok = p.(*packet.Signature); !ok { - scr.md.SignatureError = error.StructuralError("LiteralData not followed by Signature") + scr.md.SignatureError = error_.StructuralError("LiteralData not followed by Signature") return } @@ -356,7 +355,7 @@ func (scr *signatureCheckReader) Read(buf []byte) (n int, err os.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. -func CheckDetachedSignature(keyring KeyRing, signed, signature io.Reader) (signer *Entity, err os.Error) { +func CheckDetachedSignature(keyring KeyRing, signed, signature io.Reader) (signer *Entity, err error) { p, err := packet.Read(signature) if err != nil { return @@ -364,16 +363,16 @@ func CheckDetachedSignature(keyring KeyRing, signed, signature io.Reader) (signe sig, ok := p.(*packet.Signature) if !ok { - return nil, error.StructuralError("non signature packet found") + return nil, error_.StructuralError("non signature packet found") } if sig.IssuerKeyId == nil { - return nil, error.StructuralError("signature doesn't have an issuer") + return nil, error_.StructuralError("signature doesn't have an issuer") } keys := keyring.KeysById(*sig.IssuerKeyId) if len(keys) == 0 { - return nil, error.UnknownIssuerError + return nil, error_.UnknownIssuerError } h, wrappedHash, err := hashForSignature(sig.Hash, sig.SigType) @@ -382,7 +381,7 @@ func CheckDetachedSignature(keyring KeyRing, signed, signature io.Reader) (signe } _, err = io.Copy(wrappedHash, signed) - if err != nil && err != os.EOF { + if err != nil && err != io.EOF { return } @@ -400,12 +399,12 @@ func CheckDetachedSignature(keyring KeyRing, signed, signature io.Reader) (signe return } - return nil, error.UnknownIssuerError + return nil, error_.UnknownIssuerError } // CheckArmoredDetachedSignature performs the same actions as // CheckDetachedSignature but expects the signature to be armored. -func CheckArmoredDetachedSignature(keyring KeyRing, signed, signature io.Reader) (signer *Entity, err os.Error) { +func CheckArmoredDetachedSignature(keyring KeyRing, signed, signature io.Reader) (signer *Entity, err error) { body, err := readArmored(signature, SignatureType) if err != nil { return diff --git a/src/pkg/crypto/openpgp/read_test.go b/src/pkg/crypto/openpgp/read_test.go index 4dc290ef29..e8a6bf5992 100644 --- a/src/pkg/crypto/openpgp/read_test.go +++ b/src/pkg/crypto/openpgp/read_test.go @@ -6,11 +6,10 @@ package openpgp import ( "bytes" - "crypto/openpgp/error" + error_ "crypto/openpgp/error" "encoding/hex" "io" "io/ioutil" - "os" "testing" ) @@ -149,21 +148,21 @@ func TestSignedEncryptedMessage(t *testing.T) { for i, test := range signedEncryptedMessageTests { expected := "Signed and encrypted message\n" kring, _ := ReadKeyRing(readerFromHex(test.keyRingHex)) - prompt := func(keys []Key, symmetric bool) ([]byte, os.Error) { + prompt := func(keys []Key, symmetric bool) ([]byte, error) { if symmetric { t.Errorf("prompt: message was marked as symmetrically encrypted") - return nil, error.KeyIncorrectError + return nil, error_.KeyIncorrectError } if len(keys) == 0 { t.Error("prompt: no keys requested") - return nil, error.KeyIncorrectError + return nil, error_.KeyIncorrectError } err := keys[0].PrivateKey.Decrypt([]byte("passphrase")) if err != nil { t.Errorf("prompt: error decrypting key: %s", err) - return nil, error.KeyIncorrectError + return nil, error_.KeyIncorrectError } return nil, nil @@ -215,7 +214,7 @@ func TestUnspecifiedRecipient(t *testing.T) { func TestSymmetricallyEncrypted(t *testing.T) { expected := "Symmetrically encrypted.\n" - prompt := func(keys []Key, symmetric bool) ([]byte, os.Error) { + prompt := func(keys []Key, symmetric bool) ([]byte, error) { if len(keys) != 0 { t.Errorf("prompt: len(keys) = %d (want 0)", len(keys)) } @@ -287,7 +286,7 @@ func TestReadingArmoredPrivateKey(t *testing.T) { func TestNoArmoredData(t *testing.T) { _, err := ReadArmoredKeyRing(bytes.NewBufferString("foo")) - if _, ok := err.(error.InvalidArgumentError); !ok { + if _, ok := err.(error_.InvalidArgumentError); !ok { t.Errorf("error was not an InvalidArgumentError: %s", err) } } diff --git a/src/pkg/crypto/openpgp/s2k/s2k.go b/src/pkg/crypto/openpgp/s2k/s2k.go index 013b15c149..2a753db16b 100644 --- a/src/pkg/crypto/openpgp/s2k/s2k.go +++ b/src/pkg/crypto/openpgp/s2k/s2k.go @@ -8,10 +8,9 @@ package s2k import ( "crypto" - "crypto/openpgp/error" + error_ "crypto/openpgp/error" "hash" "io" - "os" "strconv" ) @@ -76,7 +75,7 @@ func Iterated(out []byte, h hash.Hash, in []byte, salt []byte, count int) { // Parse reads a binary specification for a string-to-key transformation from r // and returns a function which performs that transform. -func Parse(r io.Reader) (f func(out, in []byte), err os.Error) { +func Parse(r io.Reader) (f func(out, in []byte), err error) { var buf [9]byte _, err = io.ReadFull(r, buf[:2]) @@ -86,11 +85,11 @@ func Parse(r io.Reader) (f func(out, in []byte), err os.Error) { hash, ok := HashIdToHash(buf[1]) if !ok { - return nil, error.UnsupportedError("hash for S2K function: " + strconv.Itoa(int(buf[1]))) + return nil, error_.UnsupportedError("hash for S2K function: " + strconv.Itoa(int(buf[1]))) } h := hash.New() if h == nil { - return nil, error.UnsupportedError("hash not available: " + strconv.Itoa(int(hash))) + return nil, error_.UnsupportedError("hash not available: " + strconv.Itoa(int(hash))) } switch buf[0] { @@ -120,12 +119,12 @@ func Parse(r io.Reader) (f func(out, in []byte), err os.Error) { return f, nil } - return nil, error.UnsupportedError("S2K function") + return nil, error_.UnsupportedError("S2K function") } // Serialize salts and stretches the given passphrase and writes the resulting // key into key. It also serializes an S2K descriptor to w. -func Serialize(w io.Writer, key []byte, rand io.Reader, passphrase []byte) os.Error { +func Serialize(w io.Writer, key []byte, rand io.Reader, passphrase []byte) error { var buf [11]byte buf[0] = 3 /* iterated and salted */ buf[1], _ = HashToHashId(crypto.SHA1) diff --git a/src/pkg/crypto/openpgp/write.go b/src/pkg/crypto/openpgp/write.go index 9884472ce7..6f3450c9cd 100644 --- a/src/pkg/crypto/openpgp/write.go +++ b/src/pkg/crypto/openpgp/write.go @@ -7,45 +7,44 @@ package openpgp import ( "crypto" "crypto/openpgp/armor" - "crypto/openpgp/error" + error_ "crypto/openpgp/error" "crypto/openpgp/packet" "crypto/openpgp/s2k" "crypto/rand" _ "crypto/sha256" "hash" "io" - "os" "strconv" "time" ) // DetachSign signs message with the private key from signer (which must // already have been decrypted) and writes the signature to w. -func DetachSign(w io.Writer, signer *Entity, message io.Reader) os.Error { +func DetachSign(w io.Writer, signer *Entity, message io.Reader) error { return detachSign(w, signer, message, packet.SigTypeBinary) } // ArmoredDetachSign signs message with the private key from signer (which // must already have been decrypted) and writes an armored signature to w. -func ArmoredDetachSign(w io.Writer, signer *Entity, message io.Reader) (err os.Error) { +func ArmoredDetachSign(w io.Writer, signer *Entity, message io.Reader) (err error) { return armoredDetachSign(w, signer, message, packet.SigTypeBinary) } // DetachSignText signs message (after canonicalising the line endings) with // the private key from signer (which must already have been decrypted) and // writes the signature to w. -func DetachSignText(w io.Writer, signer *Entity, message io.Reader) os.Error { +func DetachSignText(w io.Writer, signer *Entity, message io.Reader) error { return detachSign(w, signer, message, packet.SigTypeText) } // ArmoredDetachSignText signs message (after canonicalising the line endings) // with the private key from signer (which must already have been decrypted) // and writes an armored signature to w. -func ArmoredDetachSignText(w io.Writer, signer *Entity, message io.Reader) os.Error { +func ArmoredDetachSignText(w io.Writer, signer *Entity, message io.Reader) error { return armoredDetachSign(w, signer, message, packet.SigTypeText) } -func armoredDetachSign(w io.Writer, signer *Entity, message io.Reader, sigType packet.SignatureType) (err os.Error) { +func armoredDetachSign(w io.Writer, signer *Entity, message io.Reader, sigType packet.SignatureType) (err error) { out, err := armor.Encode(w, SignatureType, nil) if err != nil { return @@ -57,12 +56,12 @@ func armoredDetachSign(w io.Writer, signer *Entity, message io.Reader, sigType p return out.Close() } -func detachSign(w io.Writer, signer *Entity, message io.Reader, sigType packet.SignatureType) (err os.Error) { +func detachSign(w io.Writer, signer *Entity, message io.Reader, sigType packet.SignatureType) (err error) { if signer.PrivateKey == nil { - return error.InvalidArgumentError("signing key doesn't have a private key") + return error_.InvalidArgumentError("signing key doesn't have a private key") } if signer.PrivateKey.Encrypted { - return error.InvalidArgumentError("signing key is encrypted") + return error_.InvalidArgumentError("signing key is encrypted") } sig := new(packet.Signature) @@ -103,7 +102,7 @@ type FileHints struct { // SymmetricallyEncrypt acts like gpg -c: it encrypts a file with a passphrase. // The resulting WriteCloser must be closed after the contents of the file have // been written. -func SymmetricallyEncrypt(ciphertext io.Writer, passphrase []byte, hints *FileHints) (plaintext io.WriteCloser, err os.Error) { +func SymmetricallyEncrypt(ciphertext io.Writer, passphrase []byte, hints *FileHints) (plaintext io.WriteCloser, err error) { if hints == nil { hints = &FileHints{} } @@ -148,12 +147,12 @@ func hashToHashId(h crypto.Hash) uint8 { // it. hints contains optional information, that is also encrypted, that aids // the recipients in processing the message. The resulting WriteCloser must // be closed after the contents of the file have been written. -func Encrypt(ciphertext io.Writer, to []*Entity, signed *Entity, hints *FileHints) (plaintext io.WriteCloser, err os.Error) { +func Encrypt(ciphertext io.Writer, to []*Entity, signed *Entity, hints *FileHints) (plaintext io.WriteCloser, err error) { var signer *packet.PrivateKey if signed != nil { signer = signed.signingKey().PrivateKey if signer == nil || signer.Encrypted { - return nil, error.InvalidArgumentError("signing key must be decrypted") + return nil, error_.InvalidArgumentError("signing key must be decrypted") } } @@ -180,7 +179,7 @@ func Encrypt(ciphertext io.Writer, to []*Entity, signed *Entity, hints *FileHint for i := range to { encryptKeys[i] = to[i].encryptionKey() if encryptKeys[i].PublicKey == nil { - return nil, error.InvalidArgumentError("cannot encrypt a message to key id " + strconv.Uitob64(to[i].PrimaryKey.KeyId, 16) + " because it has no encryption keys") + return nil, error_.InvalidArgumentError("cannot encrypt a message to key id " + strconv.Uitob64(to[i].PrimaryKey.KeyId, 16) + " because it has no encryption keys") } sig := to[i].primaryIdentity().SelfSignature @@ -198,7 +197,7 @@ func Encrypt(ciphertext io.Writer, to []*Entity, signed *Entity, hints *FileHint } if len(candidateCiphers) == 0 || len(candidateHashes) == 0 { - return nil, error.InvalidArgumentError("cannot encrypt because recipient set shares no common algorithms") + return nil, error_.InvalidArgumentError("cannot encrypt because recipient set shares no common algorithms") } cipher := packet.CipherFunction(candidateCiphers[0]) @@ -266,12 +265,12 @@ type signatureWriter struct { signer *packet.PrivateKey } -func (s signatureWriter) Write(data []byte) (int, os.Error) { +func (s signatureWriter) Write(data []byte) (int, error) { s.h.Write(data) return s.literalData.Write(data) } -func (s signatureWriter) Close() os.Error { +func (s signatureWriter) Close() error { sig := &packet.Signature{ SigType: packet.SigTypeBinary, PubKeyAlgo: s.signer.PubKeyAlgo, @@ -299,10 +298,10 @@ type noOpCloser struct { w io.Writer } -func (c noOpCloser) Write(data []byte) (n int, err os.Error) { +func (c noOpCloser) Write(data []byte) (n int, err error) { return c.w.Write(data) } -func (c noOpCloser) Close() os.Error { +func (c noOpCloser) Close() error { return nil } diff --git a/src/pkg/crypto/openpgp/write_test.go b/src/pkg/crypto/openpgp/write_test.go index c542dfa45d..3cadf4cc95 100644 --- a/src/pkg/crypto/openpgp/write_test.go +++ b/src/pkg/crypto/openpgp/write_test.go @@ -7,7 +7,6 @@ package openpgp import ( "bytes" "crypto/rand" - "os" "io" "io/ioutil" "testing" @@ -106,7 +105,7 @@ func TestSymmetricEncryption(t *testing.T) { t.Errorf("error closing plaintext writer: %s", err) } - md, err := ReadMessage(buf, nil, func(keys []Key, symmetric bool) ([]byte, os.Error) { + md, err := ReadMessage(buf, nil, func(keys []Key, symmetric bool) ([]byte, error) { return []byte("testing"), nil }) if err != nil { |
