Debian Codegraph @

ssh/pktline.go

raw symbols SCIP
1 package ssh
2
3 import (
4 "io"
5
6 "github.com/git-lfs/pktline"
7 "github.com/rubyist/tracerx"
8 )
9
10 func pktlineReader(p Pktline) io.Reader {
11 if pl, ok := p.(*pktline.Pktline); ok {
12 return pktline.NewPktlineReaderFromPktline(pl, 65536)
13 }
14 tp := p.(*TraceablePktline)
15 return pktline.NewPktlineReaderFromPktline(tp.pl, 65536)
16 }
17
18 type Pktline interface {
19 ReadPacketList() ([]string, error)
20 ReadPacketTextWithLength() (string, int, error)
21 WritePacket([]byte) error
22 WritePacketText(string) error
23 WriteDelim() error
24 WriteFlush() error
25 }
26
27 type TraceablePktline struct {
28 id int
29 pl *pktline.Pktline
30 }
31
32 func (tp *TraceablePktline) ReadPacketList() ([]string, error) {
33 var list []string
34 for {
35 data, pktLen, err := tp.pl.ReadPacketTextWithLength()
36 if err != nil {
37 return nil, err
38 }
39 if pktLen <= 1 {
40 tracerx.Printf("packet %02x < %04x", tp.id, pktLen)
41 } else {
42 tracerx.Printf("packet %02x < %s", tp.id, data)
43 }
44
45 if pktLen == 0 {
46 break
47 }
48
49 list = append(list, data)
50 }
51
52 return list, nil
53 }
54
55 func (tp *TraceablePktline) ReadPacketTextWithLength() (string, int, error) {
56 s, pktLen, err := tp.pl.ReadPacketTextWithLength()
57 if err != nil {
58 return "", 0, err
59 }
60
61 if pktLen <= 1 {
62 tracerx.Printf("packet %02x < %04x", tp.id, pktLen)
63 } else {
64 tracerx.Printf("packet %02x < %s", tp.id, s)
65 }
66 return s, pktLen, nil
67 }
68
69 func (tp *TraceablePktline) WritePacket(b []byte) error {
70 // Don't trace because this is probably binary data.
71 return tp.pl.WritePacket(b)
72 }
73
74 func (tp *TraceablePktline) WritePacketText(s string) error {
75 tracerx.Printf("packet %02x > %s", tp.id, s)
76 return tp.pl.WritePacketText(s)
77 }
78
79 func (tp *TraceablePktline) WriteDelim() error {
80 tracerx.Printf("packet %02x > 0001", tp.id)
81 return tp.pl.WriteDelim()
82 }
83
84 func (tp *TraceablePktline) WriteFlush() error {
85 tracerx.Printf("packet %02x > 0000", tp.id)
86 return tp.pl.WriteFlush()
87 }