diff options
author | Wim <wim@42.be> | 2017-12-03 01:24:05 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2017-12-03 01:24:05 +0100 |
commit | ed9118b34620f1ecd5f28506328d4ffe1b04793d (patch) | |
tree | 442998012f6779446a463e402fa7c0836edcac91 /vendor/github.com/shazow/ssh-chat/sshd/pty.go | |
parent | 59e55cfbd5cc3c82236c5e8b95e5baff256f7143 (diff) | |
download | matterbridge-msglm-ed9118b34620f1ecd5f28506328d4ffe1b04793d.tar.gz matterbridge-msglm-ed9118b34620f1ecd5f28506328d4ffe1b04793d.tar.bz2 matterbridge-msglm-ed9118b34620f1ecd5f28506328d4ffe1b04793d.zip |
Add sshchat dependencies in vendor
Diffstat (limited to 'vendor/github.com/shazow/ssh-chat/sshd/pty.go')
-rw-r--r-- | vendor/github.com/shazow/ssh-chat/sshd/pty.go | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/vendor/github.com/shazow/ssh-chat/sshd/pty.go b/vendor/github.com/shazow/ssh-chat/sshd/pty.go new file mode 100644 index 00000000..4443fd33 --- /dev/null +++ b/vendor/github.com/shazow/ssh-chat/sshd/pty.go @@ -0,0 +1,70 @@ +package sshd + +import "encoding/binary" + +// Helpers below are borrowed from go.crypto circa 2011: + +// parsePtyRequest parses the payload of the pty-req message and extracts the +// dimensions of the terminal. See RFC 4254, section 6.2. +func parsePtyRequest(s []byte) (width, height int, ok bool) { + _, s, ok = parseString(s) + if !ok { + return + } + width32, s, ok := parseUint32(s) + if !ok { + return + } + height32, _, ok := parseUint32(s) + width = int(width32) + height = int(height32) + if width < 1 { + ok = false + } + if height < 1 { + ok = false + } + return +} + +func parseWinchRequest(s []byte) (width, height int, ok bool) { + width32, _, ok := parseUint32(s) + if !ok { + return + } + height32, _, ok := parseUint32(s) + if !ok { + return + } + + width = int(width32) + height = int(height32) + if width < 1 { + ok = false + } + if height < 1 { + ok = false + } + return +} + +func parseString(in []byte) (out string, rest []byte, ok bool) { + if len(in) < 4 { + return + } + length := binary.BigEndian.Uint32(in) + if uint32(len(in)) < 4+length { + return + } + out = string(in[4 : 4+length]) + rest = in[4+length:] + ok = true + return +} + +func parseUint32(in []byte) (uint32, []byte, bool) { + if len(in) < 4 { + return 0, nil, false + } + return binary.BigEndian.Uint32(in), in[4:], true +} |