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/packet | |
| 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/packet')
| -rw-r--r-- | src/pkg/crypto/openpgp/packet/compressed.go | 7 | ||||
| -rw-r--r-- | src/pkg/crypto/openpgp/packet/compressed_test.go | 4 | ||||
| -rw-r--r-- | src/pkg/crypto/openpgp/packet/encrypted_key.go | 29 | ||||
| -rw-r--r-- | src/pkg/crypto/openpgp/packet/literal.go | 5 | ||||
| -rw-r--r-- | src/pkg/crypto/openpgp/packet/one_pass_signature.go | 13 | ||||
| -rw-r--r-- | src/pkg/crypto/openpgp/packet/packet.go | 49 | ||||
| -rw-r--r-- | src/pkg/crypto/openpgp/packet/packet_test.go | 11 | ||||
| -rw-r--r-- | src/pkg/crypto/openpgp/packet/private_key.go | 33 | ||||
| -rw-r--r-- | src/pkg/crypto/openpgp/packet/public_key.go | 49 | ||||
| -rw-r--r-- | src/pkg/crypto/openpgp/packet/reader.go | 11 | ||||
| -rw-r--r-- | src/pkg/crypto/openpgp/packet/signature.go | 55 | ||||
| -rw-r--r-- | src/pkg/crypto/openpgp/packet/symmetric_key_encrypted.go | 21 | ||||
| -rw-r--r-- | src/pkg/crypto/openpgp/packet/symmetric_key_encrypted_test.go | 4 | ||||
| -rw-r--r-- | src/pkg/crypto/openpgp/packet/symmetrically_encrypted.go | 55 | ||||
| -rw-r--r-- | src/pkg/crypto/openpgp/packet/symmetrically_encrypted_test.go | 9 | ||||
| -rw-r--r-- | src/pkg/crypto/openpgp/packet/userid.go | 5 |
16 files changed, 173 insertions, 187 deletions
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 |
