| 1 | package sshfx |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | type ExtensionPair struct { |
| 8 | Name string |
| 9 | Data string |
| 10 | } |
| 11 | |
| 12 | |
| 13 | func (e *ExtensionPair) Len() int { |
| 14 | return 4 + len(e.Name) + 4 + len(e.Data) |
| 15 | } |
| 16 | |
| 17 | |
| 18 | func (e *ExtensionPair) MarshalInto(buf *Buffer) { |
| 19 | buf.AppendString(e.Name) |
| 20 | buf.AppendString(e.Data) |
| 21 | } |
| 22 | |
| 23 | |
| 24 | func (e *ExtensionPair) MarshalBinary() ([]byte, error) { |
| 25 | buf := NewBuffer(make([]byte, 0, e.Len())) |
| 26 | e.MarshalInto(buf) |
| 27 | return buf.Bytes(), nil |
| 28 | } |
| 29 | |
| 30 | |
| 31 | func (e *ExtensionPair) UnmarshalFrom(buf *Buffer) (err error) { |
| 32 | *e = ExtensionPair{ |
| 33 | Name: buf.ConsumeString(), |
| 34 | Data: buf.ConsumeString(), |
| 35 | } |
| 36 | |
| 37 | return buf.Err |
| 38 | } |
| 39 | |
| 40 | |
| 41 | func (e *ExtensionPair) UnmarshalBinary(data []byte) error { |
| 42 | return e.UnmarshalFrom(NewBuffer(data)) |
| 43 | } |