encoding: move length const to exported value, I don't expect many to use such low limits.

This commit is contained in:
Cassondra Foesch 2021-03-22 16:21:58 +00:00 committed by Nicola Murino
parent 4974ec701c
commit 1d00d93539
2 changed files with 9 additions and 5 deletions

View File

@ -25,3 +25,10 @@ type Packet interface {
func ComposePacket(header, payload []byte, err error) ([]byte, error) {
return append(header, payload...), err
}
// Default length values,
// Defined in draft-ietf-secsh-filexfer-02 section 3.
const (
DefaultMaxPacketLength = 34000
DefaultMaxDataLength = 32768
)

View File

@ -108,14 +108,11 @@ func (p *RawPacket) UnmarshalBinary(data []byte) error {
return p.UnmarshalFrom(NewBuffer(data))
}
// defaultMaxPacketSize is defined in draft-ietf-secsh-filexfer-02 section 3.
const defaultMaxPacketSize = 34000
// readPacket reads a uint32 length-prefixed binary data packet from r.
// If the given buffer is less than 4-bytes, it allocates a new buffer of size defaultMaxPacketSize.
// If the given buffer is less than 4-bytes, it allocates a new buffer of size DefaultMaxPacketLength.
func readPacket(r io.Reader, b []byte) ([]byte, error) {
if len(b) < 4 {
b = make([]byte, defaultMaxPacketSize)
b = make([]byte, DefaultMaxPacketLength)
}
if _, err := io.ReadFull(r, b[:4]); err != nil {