aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/exp/ssh
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2011-12-03 02:17:34 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2011-12-03 02:17:34 +0000
commit2fd401c8f190f1fe43e51a7f726f6ed6119a1f96 (patch)
tree7f76eff391f37fe6467ff4ffbc0c582c9959ea30 /libgo/go/exp/ssh
parent02e9018f1616b23f1276151797216717b3564202 (diff)
downloadgcc-2fd401c8f190f1fe43e51a7f726f6ed6119a1f96.zip
gcc-2fd401c8f190f1fe43e51a7f726f6ed6119a1f96.tar.gz
gcc-2fd401c8f190f1fe43e51a7f726f6ed6119a1f96.tar.bz2
libgo: Update to weekly.2011-11-02.
From-SVN: r181964
Diffstat (limited to 'libgo/go/exp/ssh')
-rw-r--r--libgo/go/exp/ssh/channel.go39
-rw-r--r--libgo/go/exp/ssh/client.go40
-rw-r--r--libgo/go/exp/ssh/common.go4
-rw-r--r--libgo/go/exp/ssh/messages.go3
-rw-r--r--libgo/go/exp/ssh/server.go46
-rw-r--r--libgo/go/exp/ssh/server_shell.go10
-rw-r--r--libgo/go/exp/ssh/server_shell_test.go22
-rw-r--r--libgo/go/exp/ssh/session.go16
-rw-r--r--libgo/go/exp/ssh/transport.go28
9 files changed, 103 insertions, 105 deletions
diff --git a/libgo/go/exp/ssh/channel.go b/libgo/go/exp/ssh/channel.go
index f69b735..6ff8203 100644
--- a/libgo/go/exp/ssh/channel.go
+++ b/libgo/go/exp/ssh/channel.go
@@ -5,7 +5,8 @@
package ssh
import (
- "os"
+ "errors"
+ "io"
"sync"
)
@@ -13,19 +14,19 @@ import (
// SSH connection.
type Channel interface {
// Accept accepts the channel creation request.
- Accept() os.Error
+ Accept() error
// Reject rejects the channel creation request. After calling this, no
// other methods on the Channel may be called. If they are then the
// peer is likely to signal a protocol error and drop the connection.
- Reject(reason RejectionReason, message string) os.Error
+ Reject(reason RejectionReason, message string) error
- // Read may return a ChannelRequest as an os.Error.
- Read(data []byte) (int, os.Error)
- Write(data []byte) (int, os.Error)
- Close() os.Error
+ // Read may return a ChannelRequest as an error.
+ Read(data []byte) (int, error)
+ Write(data []byte) (int, error)
+ Close() error
// AckRequest either sends an ack or nack to the channel request.
- AckRequest(ok bool) os.Error
+ AckRequest(ok bool) error
// ChannelType returns the type of the channel, as supplied by the
// client.
@@ -43,7 +44,7 @@ type ChannelRequest struct {
Payload []byte
}
-func (c ChannelRequest) String() string {
+func (c ChannelRequest) Error() string {
return "channel request received"
}
@@ -72,7 +73,7 @@ type channel struct {
myId, theirId uint32
myWindow, theirWindow uint32
maxPacketSize uint32
- err os.Error
+ err error
pendingRequests []ChannelRequest
pendingData []byte
@@ -83,7 +84,7 @@ type channel struct {
cond *sync.Cond
}
-func (c *channel) Accept() os.Error {
+func (c *channel) Accept() error {
c.serverConn.lock.Lock()
defer c.serverConn.lock.Unlock()
@@ -100,7 +101,7 @@ func (c *channel) Accept() os.Error {
return c.serverConn.writePacket(marshal(msgChannelOpenConfirm, confirm))
}
-func (c *channel) Reject(reason RejectionReason, message string) os.Error {
+func (c *channel) Reject(reason RejectionReason, message string) error {
c.serverConn.lock.Lock()
defer c.serverConn.lock.Unlock()
@@ -167,7 +168,7 @@ func (c *channel) handleData(data []byte) {
c.cond.Signal()
}
-func (c *channel) Read(data []byte) (n int, err os.Error) {
+func (c *channel) Read(data []byte) (n int, err error) {
c.lock.Lock()
defer c.lock.Unlock()
@@ -187,7 +188,7 @@ func (c *channel) Read(data []byte) (n int, err os.Error) {
for {
if c.theySentEOF || c.theyClosed || c.dead {
- return 0, os.EOF
+ return 0, io.EOF
}
if len(c.pendingRequests) > 0 {
@@ -223,11 +224,11 @@ func (c *channel) Read(data []byte) (n int, err os.Error) {
panic("unreachable")
}
-func (c *channel) Write(data []byte) (n int, err os.Error) {
+func (c *channel) Write(data []byte) (n int, err error) {
for len(data) > 0 {
c.lock.Lock()
if c.dead || c.weClosed {
- return 0, os.EOF
+ return 0, io.EOF
}
if c.theirWindow == 0 {
@@ -267,7 +268,7 @@ func (c *channel) Write(data []byte) (n int, err os.Error) {
return
}
-func (c *channel) Close() os.Error {
+func (c *channel) Close() error {
c.serverConn.lock.Lock()
defer c.serverConn.lock.Unlock()
@@ -276,7 +277,7 @@ func (c *channel) Close() os.Error {
}
if c.weClosed {
- return os.NewError("ssh: channel already closed")
+ return errors.New("ssh: channel already closed")
}
c.weClosed = true
@@ -286,7 +287,7 @@ func (c *channel) Close() os.Error {
return c.serverConn.writePacket(marshal(msgChannelClose, closeMsg))
}
-func (c *channel) AckRequest(ok bool) os.Error {
+func (c *channel) AckRequest(ok bool) error {
c.serverConn.lock.Lock()
defer c.serverConn.lock.Unlock()
diff --git a/libgo/go/exp/ssh/client.go b/libgo/go/exp/ssh/client.go
index 9eed315..345e707 100644
--- a/libgo/go/exp/ssh/client.go
+++ b/libgo/go/exp/ssh/client.go
@@ -8,10 +8,10 @@ import (
"big"
"crypto"
"crypto/rand"
+ "errors"
"fmt"
"io"
"net"
- "os"
"sync"
)
@@ -26,7 +26,7 @@ type ClientConn struct {
}
// Client returns a new SSH client connection using c as the underlying transport.
-func Client(c net.Conn, config *ClientConfig) (*ClientConn, os.Error) {
+func Client(c net.Conn, config *ClientConfig) (*ClientConn, error) {
conn := &ClientConn{
transport: newTransport(c, config.rand()),
config: config,
@@ -44,7 +44,7 @@ func Client(c net.Conn, config *ClientConfig) (*ClientConn, os.Error) {
}
// handshake performs the client side key exchange. See RFC 4253 Section 7.
-func (c *ClientConn) handshake() os.Error {
+func (c *ClientConn) handshake() error {
var magics handshakeMagics
if _, err := c.Write(clientVersion); err != nil {
@@ -91,7 +91,7 @@ func (c *ClientConn) handshake() os.Error {
kexAlgo, hostKeyAlgo, ok := findAgreedAlgorithms(c.transport, &clientKexInit, &serverKexInit)
if !ok {
- return os.NewError("ssh: no common algorithms")
+ return errors.New("ssh: no common algorithms")
}
if serverKexInit.FirstKexFollows && kexAlgo != serverKexInit.KexAlgos[0] {
@@ -133,7 +133,7 @@ func (c *ClientConn) handshake() os.Error {
// authenticate authenticates with the remote server. See RFC 4252.
// Only "password" authentication is supported.
-func (c *ClientConn) authenticate() os.Error {
+func (c *ClientConn) authenticate() error {
if err := c.writePacket(marshal(msgServiceRequest, serviceRequestMsg{serviceUserAuth})); err != nil {
return err
}
@@ -166,7 +166,7 @@ func (c *ClientConn) authenticate() os.Error {
return nil
}
-func (c *ClientConn) sendUserAuthReq(method string) os.Error {
+func (c *ClientConn) sendUserAuthReq(method string) error {
length := stringLength([]byte(c.config.Password)) + 1
payload := make([]byte, length)
// always false for password auth, see RFC 4252 Section 8.
@@ -183,7 +183,7 @@ func (c *ClientConn) sendUserAuthReq(method string) os.Error {
// kexDH performs Diffie-Hellman key agreement on a ClientConn. The
// returned values are given the same names as in RFC 4253, section 8.
-func (c *ClientConn) kexDH(group *dhGroup, hashFunc crypto.Hash, magics *handshakeMagics, hostKeyAlgo string) ([]byte, []byte, os.Error) {
+func (c *ClientConn) kexDH(group *dhGroup, hashFunc crypto.Hash, magics *handshakeMagics, hostKeyAlgo string) ([]byte, []byte, error) {
x, err := rand.Int(c.config.rand(), group.p)
if err != nil {
return nil, nil, err
@@ -207,7 +207,7 @@ func (c *ClientConn) kexDH(group *dhGroup, hashFunc crypto.Hash, magics *handsha
}
if kexDHReply.Y.Sign() == 0 || kexDHReply.Y.Cmp(group.p) >= 0 {
- return nil, nil, os.NewError("server DH parameter out of bounds")
+ return nil, nil, errors.New("server DH parameter out of bounds")
}
kInt := new(big.Int).Exp(kexDHReply.Y, x, group.p)
@@ -230,7 +230,7 @@ func (c *ClientConn) kexDH(group *dhGroup, hashFunc crypto.Hash, magics *handsha
// openChan opens a new client channel. The most common session type is "session".
// The full set of valid session types are listed in RFC 4250 4.9.1.
-func (c *ClientConn) openChan(typ string) (*clientChan, os.Error) {
+func (c *ClientConn) openChan(typ string) (*clientChan, error) {
ch := c.newChan(c.transport)
if err := c.writePacket(marshal(msgChannelOpen, channelOpenMsg{
ChanType: typ,
@@ -247,10 +247,10 @@ func (c *ClientConn) openChan(typ string) (*clientChan, os.Error) {
ch.peersId = msg.MyId
case *channelOpenFailureMsg:
c.chanlist.remove(ch.id)
- return nil, os.NewError(msg.Message)
+ return nil, errors.New(msg.Message)
default:
c.chanlist.remove(ch.id)
- return nil, os.NewError("Unexpected packet")
+ return nil, errors.New("Unexpected packet")
}
return ch, nil
}
@@ -329,7 +329,7 @@ func (c *ClientConn) mainLoop() {
// Dial connects to the given network address using net.Dial and
// then initiates a SSH handshake, returning the resulting client connection.
-func Dial(network, addr string, config *ClientConfig) (*ClientConn, os.Error) {
+func Dial(network, addr string, config *ClientConfig) (*ClientConn, error) {
conn, err := net.Dial(network, addr)
if err != nil {
return nil, err
@@ -382,13 +382,13 @@ func newClientChan(t *transport, id uint32) *clientChan {
}
// Close closes the channel. This does not close the underlying connection.
-func (c *clientChan) Close() os.Error {
+func (c *clientChan) Close() error {
return c.writePacket(marshal(msgChannelClose, channelCloseMsg{
PeersId: c.id,
}))
}
-func (c *clientChan) sendChanReq(req channelRequestMsg) os.Error {
+func (c *clientChan) sendChanReq(req channelRequestMsg) error {
if err := c.writePacket(marshal(msgChannelRequest, req)); err != nil {
return err
}
@@ -447,12 +447,12 @@ type chanWriter struct {
}
// Write writes data to the remote process's standard input.
-func (w *chanWriter) Write(data []byte) (n int, err os.Error) {
+func (w *chanWriter) Write(data []byte) (n int, err error) {
for {
if w.rwin == 0 {
win, ok := <-w.win
if !ok {
- return 0, os.EOF
+ return 0, io.EOF
}
w.rwin += win
continue
@@ -469,7 +469,7 @@ func (w *chanWriter) Write(data []byte) (n int, err os.Error) {
panic("unreachable")
}
-func (w *chanWriter) Close() os.Error {
+func (w *chanWriter) Close() error {
return w.writePacket(marshal(msgChannelEOF, channelEOFMsg{w.id}))
}
@@ -485,7 +485,7 @@ type chanReader struct {
}
// Read reads data from the remote process's stdout or stderr.
-func (r *chanReader) Read(data []byte) (int, os.Error) {
+func (r *chanReader) Read(data []byte) (int, error) {
var ok bool
for {
if len(r.buf) > 0 {
@@ -499,12 +499,12 @@ func (r *chanReader) Read(data []byte) (int, os.Error) {
}
r.buf, ok = <-r.data
if !ok {
- return 0, os.EOF
+ return 0, io.EOF
}
}
panic("unreachable")
}
-func (r *chanReader) Close() os.Error {
+func (r *chanReader) Close() error {
return r.writePacket(marshal(msgChannelEOF, channelEOFMsg{r.id}))
}
diff --git a/libgo/go/exp/ssh/common.go b/libgo/go/exp/ssh/common.go
index 739bd2f..f68c353 100644
--- a/libgo/go/exp/ssh/common.go
+++ b/libgo/go/exp/ssh/common.go
@@ -53,7 +53,7 @@ type UnexpectedMessageError struct {
expected, got uint8
}
-func (u UnexpectedMessageError) String() string {
+func (u UnexpectedMessageError) Error() string {
return "ssh: unexpected message type " + strconv.Itoa(int(u.got)) + " (expected " + strconv.Itoa(int(u.expected)) + ")"
}
@@ -62,7 +62,7 @@ type ParseError struct {
msgType uint8
}
-func (p ParseError) String() string {
+func (p ParseError) Error() string {
return "ssh: parse error in message type " + strconv.Itoa(int(p.msgType))
}
diff --git a/libgo/go/exp/ssh/messages.go b/libgo/go/exp/ssh/messages.go
index 5f2c447..5eae181 100644
--- a/libgo/go/exp/ssh/messages.go
+++ b/libgo/go/exp/ssh/messages.go
@@ -8,7 +8,6 @@ import (
"big"
"bytes"
"io"
- "os"
"reflect"
)
@@ -192,7 +191,7 @@ type userAuthPubKeyOkMsg struct {
// unmarshal parses the SSH wire data in packet into out using reflection.
// expectedType is the expected SSH message type. It either returns nil on
// success, or a ParseError or UnexpectedMessageError on error.
-func unmarshal(out interface{}, packet []byte, expectedType uint8) os.Error {
+func unmarshal(out interface{}, packet []byte, expectedType uint8) error {
if len(packet) == 0 {
return ParseError{expectedType}
}
diff --git a/libgo/go/exp/ssh/server.go b/libgo/go/exp/ssh/server.go
index 0dd24ec..2ae8079 100644
--- a/libgo/go/exp/ssh/server.go
+++ b/libgo/go/exp/ssh/server.go
@@ -12,9 +12,9 @@ import (
"crypto/rsa"
"crypto/x509"
"encoding/pem"
+ "errors"
"io"
"net"
- "os"
"sync"
)
@@ -53,12 +53,12 @@ func (c *ServerConfig) rand() io.Reader {
// private key configured in order to accept connections. The private key must
// be in the form of a PEM encoded, PKCS#1, RSA private key. The file "id_rsa"
// typically contains such a key.
-func (s *ServerConfig) SetRSAPrivateKey(pemBytes []byte) os.Error {
+func (s *ServerConfig) SetRSAPrivateKey(pemBytes []byte) error {
block, _ := pem.Decode(pemBytes)
if block == nil {
- return os.NewError("ssh: no key found")
+ return errors.New("ssh: no key found")
}
- var err os.Error
+ var err error
s.rsa, err = x509.ParsePKCS1PrivateKey(block.Bytes)
if err != nil {
return err
@@ -140,7 +140,7 @@ type ServerConn struct {
// lock protects err and also allows Channels to serialise their writes
// to out.
lock sync.RWMutex
- err os.Error
+ err error
// cachedPubKeys contains the cache results of tests for public keys.
// Since SSH clients will query whether a public key is acceptable
@@ -162,7 +162,7 @@ func Server(c net.Conn, config *ServerConfig) *ServerConn {
// kexDH performs Diffie-Hellman key agreement on a ServerConnection. The
// returned values are given the same names as in RFC 4253, section 8.
-func (s *ServerConn) kexDH(group *dhGroup, hashFunc crypto.Hash, magics *handshakeMagics, hostKeyAlgo string) (H, K []byte, err os.Error) {
+func (s *ServerConn) kexDH(group *dhGroup, hashFunc crypto.Hash, magics *handshakeMagics, hostKeyAlgo string) (H, K []byte, err error) {
packet, err := s.readPacket()
if err != nil {
return
@@ -173,7 +173,7 @@ func (s *ServerConn) kexDH(group *dhGroup, hashFunc crypto.Hash, magics *handsha
}
if kexDHInit.X.Sign() == 0 || kexDHInit.X.Cmp(group.p) >= 0 {
- return nil, nil, os.NewError("client DH parameter out of bounds")
+ return nil, nil, errors.New("client DH parameter out of bounds")
}
y, err := rand.Int(s.config.rand(), group.p)
@@ -189,7 +189,7 @@ func (s *ServerConn) kexDH(group *dhGroup, hashFunc crypto.Hash, magics *handsha
case hostAlgoRSA:
serializedHostKey = s.config.rsaSerialized
default:
- return nil, nil, os.NewError("internal error")
+ return nil, nil, errors.New("internal error")
}
h := hashFunc.New()
@@ -218,7 +218,7 @@ func (s *ServerConn) kexDH(group *dhGroup, hashFunc crypto.Hash, magics *handsha
return
}
default:
- return nil, nil, os.NewError("internal error")
+ return nil, nil, errors.New("internal error")
}
serializedSig := serializeRSASignature(sig)
@@ -279,7 +279,7 @@ func buildDataSignedForAuth(sessionId []byte, req userAuthRequestMsg, algo, pubK
}
// Handshake performs an SSH transport and client authentication on the given ServerConn.
-func (s *ServerConn) Handshake() os.Error {
+func (s *ServerConn) Handshake() error {
var magics handshakeMagics
if _, err := s.Write(serverVersion); err != nil {
return err
@@ -326,7 +326,7 @@ func (s *ServerConn) Handshake() os.Error {
kexAlgo, hostKeyAlgo, ok := findAgreedAlgorithms(s.transport, &clientKexInit, &serverKexInit)
if !ok {
- return os.NewError("ssh: no common algorithms")
+ return errors.New("ssh: no common algorithms")
}
if clientKexInit.FirstKexFollows && kexAlgo != clientKexInit.KexAlgos[0] {
@@ -345,7 +345,7 @@ func (s *ServerConn) Handshake() os.Error {
dhGroup14Once.Do(initDHGroup14)
H, K, err = s.kexDH(dhGroup14, hashFunc, &magics, hostKeyAlgo)
default:
- err = os.NewError("ssh: unexpected key exchange algorithm " + kexAlgo)
+ err = errors.New("ssh: unexpected key exchange algorithm " + kexAlgo)
}
if err != nil {
return err
@@ -374,7 +374,7 @@ func (s *ServerConn) Handshake() os.Error {
return err
}
if serviceRequest.Service != serviceUserAuth {
- return os.NewError("ssh: requested service '" + serviceRequest.Service + "' before authenticating")
+ return errors.New("ssh: requested service '" + serviceRequest.Service + "' before authenticating")
}
serviceAccept := serviceAcceptMsg{
Service: serviceUserAuth,
@@ -420,9 +420,9 @@ func (s *ServerConn) testPubKey(user, algo string, pubKey []byte) bool {
return result
}
-func (s *ServerConn) authenticate(H []byte) os.Error {
+func (s *ServerConn) authenticate(H []byte) error {
var userAuthReq userAuthRequestMsg
- var err os.Error
+ var err error
var packet []byte
userAuthLoop:
@@ -435,7 +435,7 @@ userAuthLoop:
}
if userAuthReq.Service != serviceSSH {
- return os.NewError("ssh: client attempted to negotiate for unknown service: " + userAuthReq.Service)
+ return errors.New("ssh: client attempted to negotiate for unknown service: " + userAuthReq.Service)
}
switch userAuthReq.Method {
@@ -523,7 +523,7 @@ userAuthLoop:
return ParseError{msgUserAuthRequest}
}
default:
- return os.NewError("ssh: isAcceptableAlgo incorrect")
+ return errors.New("ssh: isAcceptableAlgo incorrect")
}
if s.testPubKey(userAuthReq.User, algo, pubKey) {
break userAuthLoop
@@ -540,7 +540,7 @@ userAuthLoop:
}
if len(failureMsg.Methods) == 0 {
- return os.NewError("ssh: no authentication methods configured but NoClientAuth is also false")
+ return errors.New("ssh: no authentication methods configured but NoClientAuth is also false")
}
if err = s.writePacket(marshal(msgUserAuthFailure, failureMsg)); err != nil {
@@ -560,7 +560,7 @@ const defaultWindowSize = 32768
// Accept reads and processes messages on a ServerConn. It must be called
// in order to demultiplex messages to any resulting Channels.
-func (s *ServerConn) Accept() (Channel, os.Error) {
+func (s *ServerConn) Accept() (Channel, error) {
if s.err != nil {
return nil, s.err
}
@@ -660,7 +660,7 @@ func (s *ServerConn) Accept() (Channel, os.Error) {
case UnexpectedMessageError:
return nil, msg
case *disconnectMsg:
- return nil, os.EOF
+ return nil, io.EOF
default:
// Unknown message. Ignore.
}
@@ -679,7 +679,7 @@ type Listener struct {
// Accept waits for and returns the next incoming SSH connection.
// The receiver should call Handshake() in another goroutine
// to avoid blocking the accepter.
-func (l *Listener) Accept() (*ServerConn, os.Error) {
+func (l *Listener) Accept() (*ServerConn, error) {
c, err := l.listener.Accept()
if err != nil {
return nil, err
@@ -694,13 +694,13 @@ func (l *Listener) Addr() net.Addr {
}
// Close closes the listener.
-func (l *Listener) Close() os.Error {
+func (l *Listener) Close() error {
return l.listener.Close()
}
// Listen creates an SSH listener accepting connections on
// the given network address using net.Listen.
-func Listen(network, addr string, config *ServerConfig) (*Listener, os.Error) {
+func Listen(network, addr string, config *ServerConfig) (*Listener, error) {
l, err := net.Listen(network, addr)
if err != nil {
return nil, err
diff --git a/libgo/go/exp/ssh/server_shell.go b/libgo/go/exp/ssh/server_shell.go
index 0e9967a..5243d0e 100644
--- a/libgo/go/exp/ssh/server_shell.go
+++ b/libgo/go/exp/ssh/server_shell.go
@@ -4,9 +4,7 @@
package ssh
-import (
- "os"
-)
+import "io"
// ServerShell contains the state for running a VT100 terminal that is capable
// of reading lines of input.
@@ -326,12 +324,12 @@ func parsePtyRequest(s []byte) (width, height int, ok bool) {
return
}
-func (ss *ServerShell) Write(buf []byte) (n int, err os.Error) {
+func (ss *ServerShell) Write(buf []byte) (n int, err error) {
return ss.c.Write(buf)
}
// ReadLine returns a line of input from the terminal.
-func (ss *ServerShell) ReadLine() (line string, err os.Error) {
+func (ss *ServerShell) ReadLine() (line string, err error) {
ss.writeLine([]byte(ss.prompt))
ss.c.Write(ss.outBuf)
ss.outBuf = ss.outBuf[:0]
@@ -353,7 +351,7 @@ func (ss *ServerShell) ReadLine() (line string, err os.Error) {
break
}
if key == keyCtrlD {
- return "", os.EOF
+ return "", io.EOF
}
line, lineOk = ss.handleKey(key)
}
diff --git a/libgo/go/exp/ssh/server_shell_test.go b/libgo/go/exp/ssh/server_shell_test.go
index 622cf7c..aa69ef7 100644
--- a/libgo/go/exp/ssh/server_shell_test.go
+++ b/libgo/go/exp/ssh/server_shell_test.go
@@ -5,8 +5,8 @@
package ssh
import (
+ "io"
"testing"
- "os"
)
type MockChannel struct {
@@ -15,15 +15,15 @@ type MockChannel struct {
received []byte
}
-func (c *MockChannel) Accept() os.Error {
+func (c *MockChannel) Accept() error {
return nil
}
-func (c *MockChannel) Reject(RejectionReason, string) os.Error {
+func (c *MockChannel) Reject(RejectionReason, string) error {
return nil
}
-func (c *MockChannel) Read(data []byte) (n int, err os.Error) {
+func (c *MockChannel) Read(data []byte) (n int, err error) {
n = len(data)
if n == 0 {
return
@@ -32,7 +32,7 @@ func (c *MockChannel) Read(data []byte) (n int, err os.Error) {
n = len(c.toSend)
}
if n == 0 {
- return 0, os.EOF
+ return 0, io.EOF
}
if c.bytesPerRead > 0 && n > c.bytesPerRead {
n = c.bytesPerRead
@@ -42,16 +42,16 @@ func (c *MockChannel) Read(data []byte) (n int, err os.Error) {
return
}
-func (c *MockChannel) Write(data []byte) (n int, err os.Error) {
+func (c *MockChannel) Write(data []byte) (n int, err error) {
c.received = append(c.received, data...)
return len(data), nil
}
-func (c *MockChannel) Close() os.Error {
+func (c *MockChannel) Close() error {
return nil
}
-func (c *MockChannel) AckRequest(ok bool) os.Error {
+func (c *MockChannel) AckRequest(ok bool) error {
return nil
}
@@ -70,7 +70,7 @@ func TestClose(t *testing.T) {
if line != "" {
t.Errorf("Expected empty line but got: %s", line)
}
- if err != os.EOF {
+ if err != io.EOF {
t.Errorf("Error should have been EOF but got: %s", err)
}
}
@@ -78,12 +78,12 @@ func TestClose(t *testing.T) {
var keyPressTests = []struct {
in string
line string
- err os.Error
+ err error
}{
{
"",
"",
- os.EOF,
+ io.EOF,
},
{
"\r",
diff --git a/libgo/go/exp/ssh/session.go b/libgo/go/exp/ssh/session.go
index 13df2f0..77154f2 100644
--- a/libgo/go/exp/ssh/session.go
+++ b/libgo/go/exp/ssh/session.go
@@ -9,8 +9,8 @@ package ssh
import (
"encoding/binary"
+ "errors"
"io"
- "os"
)
// A Session represents a connection to a remote command or shell.
@@ -34,7 +34,7 @@ type Session struct {
// Setenv sets an environment variable that will be applied to any
// command executed by Shell or Exec.
-func (s *Session) Setenv(name, value string) os.Error {
+func (s *Session) Setenv(name, value string) error {
n, v := []byte(name), []byte(value)
nlen, vlen := stringLength(n), stringLength(v)
payload := make([]byte, nlen+vlen)
@@ -53,7 +53,7 @@ func (s *Session) Setenv(name, value string) os.Error {
var emptyModeList = []byte{0, 0, 0, 1, 0}
// RequestPty requests the association of a pty with the session on the remote host.
-func (s *Session) RequestPty(term string, h, w int) os.Error {
+func (s *Session) RequestPty(term string, h, w int) error {
buf := make([]byte, 4+len(term)+16+len(emptyModeList))
b := marshalString(buf, []byte(term))
binary.BigEndian.PutUint32(b, uint32(h))
@@ -73,9 +73,9 @@ func (s *Session) RequestPty(term string, h, w int) os.Error {
// Exec runs cmd on the remote host. Typically, the remote
// server passes cmd to the shell for interpretation.
// A Session only accepts one call to Exec or Shell.
-func (s *Session) Exec(cmd string) os.Error {
+func (s *Session) Exec(cmd string) error {
if s.started {
- return os.NewError("session already started")
+ return errors.New("session already started")
}
cmdLen := stringLength([]byte(cmd))
payload := make([]byte, cmdLen)
@@ -92,9 +92,9 @@ func (s *Session) Exec(cmd string) os.Error {
// Shell starts a login shell on the remote host. A Session only
// accepts one call to Exec or Shell.
-func (s *Session) Shell() os.Error {
+func (s *Session) Shell() error {
if s.started {
- return os.NewError("session already started")
+ return errors.New("session already started")
}
s.started = true
@@ -106,7 +106,7 @@ func (s *Session) Shell() os.Error {
}
// NewSession returns a new interactive session on the remote host.
-func (c *ClientConn) NewSession() (*Session, os.Error) {
+func (c *ClientConn) NewSession() (*Session, error) {
ch, err := c.openChan("session")
if err != nil {
return nil, err
diff --git a/libgo/go/exp/ssh/transport.go b/libgo/go/exp/ssh/transport.go
index 97eaf97..579a9d8 100644
--- a/libgo/go/exp/ssh/transport.go
+++ b/libgo/go/exp/ssh/transport.go
@@ -11,10 +11,10 @@ import (
"crypto/cipher"
"crypto/hmac"
"crypto/subtle"
+ "errors"
"hash"
"io"
"net"
- "os"
"sync"
)
@@ -27,7 +27,7 @@ const (
// TODO(dfc) suggestions for a better name will be warmly received.
type filteredConn interface {
// Close closes the connection.
- Close() os.Error
+ Close() error
// LocalAddr returns the local network address.
LocalAddr() net.Addr
@@ -40,7 +40,7 @@ type filteredConn interface {
// an SSH peer.
type packetWriter interface {
// Encrypt and send a packet of data to the remote peer.
- writePacket(packet []byte) os.Error
+ writePacket(packet []byte) error
}
// transport represents the SSH connection to the remote peer.
@@ -79,7 +79,7 @@ type common struct {
}
// Read and decrypt a single packet from the remote peer.
-func (r *reader) readOnePacket() ([]byte, os.Error) {
+func (r *reader) readOnePacket() ([]byte, error) {
var lengthBytes = make([]byte, 5)
var macSize uint32
@@ -108,10 +108,10 @@ func (r *reader) readOnePacket() ([]byte, os.Error) {
paddingLength := uint32(lengthBytes[4])
if length <= paddingLength+1 {
- return nil, os.NewError("invalid packet length")
+ return nil, errors.New("invalid packet length")
}
if length > maxPacketSize {
- return nil, os.NewError("packet too large")
+ return nil, errors.New("packet too large")
}
packet := make([]byte, length-1+macSize)
@@ -126,7 +126,7 @@ func (r *reader) readOnePacket() ([]byte, os.Error) {
if r.mac != nil {
r.mac.Write(packet[:length-1])
if subtle.ConstantTimeCompare(r.mac.Sum(), mac) != 1 {
- return nil, os.NewError("ssh: MAC failure")
+ return nil, errors.New("ssh: MAC failure")
}
}
@@ -135,7 +135,7 @@ func (r *reader) readOnePacket() ([]byte, os.Error) {
}
// Read and decrypt next packet discarding debug and noop messages.
-func (t *transport) readPacket() ([]byte, os.Error) {
+func (t *transport) readPacket() ([]byte, error) {
for {
packet, err := t.readOnePacket()
if err != nil {
@@ -149,7 +149,7 @@ func (t *transport) readPacket() ([]byte, os.Error) {
}
// Encrypt and send a packet of data to the remote peer.
-func (w *writer) writePacket(packet []byte) os.Error {
+func (w *writer) writePacket(packet []byte) error {
w.Mutex.Lock()
defer w.Mutex.Unlock()
@@ -218,7 +218,7 @@ func (w *writer) writePacket(packet []byte) os.Error {
}
// Send a message to the remote peer
-func (t *transport) sendMessage(typ uint8, msg interface{}) os.Error {
+func (t *transport) sendMessage(typ uint8, msg interface{}) error {
packet := marshal(typ, msg)
return t.writePacket(packet)
}
@@ -252,7 +252,7 @@ var (
// setupKeys sets the cipher and MAC keys from K, H and sessionId, as
// described in RFC 4253, section 6.4. direction should either be serverKeys
// (to setup server->client keys) or clientKeys (for client->server keys).
-func (c *common) setupKeys(d direction, K, H, sessionId []byte, hashFunc crypto.Hash) os.Error {
+func (c *common) setupKeys(d direction, K, H, sessionId []byte, hashFunc crypto.Hash) error {
h := hashFunc.New()
blockSize := 16
@@ -308,7 +308,7 @@ type truncatingMAC struct {
hmac hash.Hash
}
-func (t truncatingMAC) Write(data []byte) (int, os.Error) {
+func (t truncatingMAC) Write(data []byte) (int, error) {
return t.hmac.Write(data)
}
@@ -332,7 +332,7 @@ func (t truncatingMAC) Size() int {
const maxVersionStringBytes = 1024
// Read version string as specified by RFC 4253, section 4.2.
-func readVersion(r io.Reader) ([]byte, os.Error) {
+func readVersion(r io.Reader) ([]byte, error) {
versionString := make([]byte, 0, 64)
var ok, seenCR bool
var buf [1]byte
@@ -360,7 +360,7 @@ forEachByte:
}
if !ok {
- return nil, os.NewError("failed to read version string")
+ return nil, errors.New("failed to read version string")
}
// We need to remove the CR from versionString