diff options
| author | Dave Cheney <dave@cheney.net> | 2012-07-20 10:33:35 +1000 |
|---|---|---|
| committer | Dave Cheney <dave@cheney.net> | 2012-07-20 10:33:35 +1000 |
| commit | d1bf83abcbf80a644ecdaabdecf1f429b9c8f63a (patch) | |
| tree | b10bb4878e2f6229377bef2ca0f0524ac8fd8e67 | |
| parent | f77e98d970f686788dc59c872b6dc73c29adabf0 (diff) | |
| download | go-x-crypto-d1bf83abcbf80a644ecdaabdecf1f429b9c8f63a.tar.xz | |
go.crypto/ssh: use binary.BigEndian throughout
A small cleanup.
R=agl, gustav.paul
CC=golang-dev
https://golang.org/cl/6406043
| -rw-r--r-- | ssh/client.go | 11 | ||||
| -rw-r--r-- | ssh/server.go | 5 | ||||
| -rw-r--r-- | ssh/transport.go | 3 |
3 files changed, 11 insertions, 8 deletions
diff --git a/ssh/client.go b/ssh/client.go index 235a733..e5748e3 100644 --- a/ssh/client.go +++ b/ssh/client.go @@ -7,6 +7,7 @@ package ssh import ( "crypto" "crypto/rand" + "encoding/binary" "errors" "fmt" "io" @@ -212,8 +213,8 @@ func (c *ClientConn) mainLoop() { // malformed data packet return } - remoteId := uint32(packet[1])<<24 | uint32(packet[2])<<16 | uint32(packet[3])<<8 | uint32(packet[4]) - length := uint32(packet[5])<<24 | uint32(packet[6])<<16 | uint32(packet[7])<<8 | uint32(packet[8]) + remoteId := binary.BigEndian.Uint32(packet[1:5]) + length := binary.BigEndian.Uint32(packet[5:9]) packet = packet[9:] if length != uint32(len(packet)) { @@ -229,9 +230,9 @@ func (c *ClientConn) mainLoop() { // malformed data packet return } - remoteId := uint32(packet[1])<<24 | uint32(packet[2])<<16 | uint32(packet[3])<<8 | uint32(packet[4]) - datatype := uint32(packet[5])<<24 | uint32(packet[6])<<16 | uint32(packet[7])<<8 | uint32(packet[8]) - length := uint32(packet[9])<<24 | uint32(packet[10])<<16 | uint32(packet[11])<<8 | uint32(packet[12]) + remoteId := binary.BigEndian.Uint32(packet[1:5]) + datatype := binary.BigEndian.Uint32(packet[5:9]) + length := binary.BigEndian.Uint32(packet[9:13]) packet = packet[13:] if length != uint32(len(packet)) { diff --git a/ssh/server.go b/ssh/server.go index 158a0ae..5c640a7 100644 --- a/ssh/server.go +++ b/ssh/server.go @@ -10,6 +10,7 @@ import ( "crypto/rand" "crypto/rsa" "crypto/x509" + "encoding/binary" "encoding/pem" "errors" "io" @@ -548,14 +549,14 @@ func (s *ServerConn) Accept() (Channel, error) { // malformed data packet return nil, ParseError{msgChannelData} } - remoteId := uint32(packet[1])<<24 | uint32(packet[2])<<16 | uint32(packet[3])<<8 | uint32(packet[4]) + remoteId := binary.BigEndian.Uint32(packet[1:5]) s.lock.Lock() c, ok := s.channels[remoteId] if !ok { s.lock.Unlock() continue } - if length := int(packet[5])<<24 | int(packet[6])<<16 | int(packet[7])<<8 | int(packet[8]); length > 0 { + if length := binary.BigEndian.Uint32(packet[5:9]); length > 0 { packet = packet[9:] c.handleData(packet[:length]) } diff --git a/ssh/transport.go b/ssh/transport.go index 4c24a37..020d6d7 100644 --- a/ssh/transport.go +++ b/ssh/transport.go @@ -9,6 +9,7 @@ import ( "crypto" "crypto/cipher" "crypto/subtle" + "encoding/binary" "errors" "hash" "io" @@ -90,7 +91,7 @@ func (r *reader) readOnePacket() ([]byte, error) { macSize = uint32(r.mac.Size()) } - length := uint32(lengthBytes[0])<<24 | uint32(lengthBytes[1])<<16 | uint32(lengthBytes[2])<<8 | uint32(lengthBytes[3]) + length := binary.BigEndian.Uint32(lengthBytes[0:4]) paddingLength := uint32(lengthBytes[4]) if length <= paddingLength+1 { |
