跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

init_packets.go

99 行 · 2.3 KB历史下载
1package sshfx
2
3// InitPacket defines the SSH_FXP_INIT packet.
4type InitPacket struct {
5 Version uint32
6 Extensions []*ExtensionPair
7}
8
9// MarshalBinary returns p as the binary encoding of p.
10func (p *InitPacket) MarshalBinary() ([]byte, error) {
11 size := 1 + 4 // byte(type) + uint32(version)
12
13 for _, ext := range p.Extensions {
14 size += ext.Len()
15 }
16
17 b := NewBuffer(make([]byte, 4, 4+size))
18 b.AppendUint8(uint8(PacketTypeInit))
19 b.AppendUint32(p.Version)
20
21 for _, ext := range p.Extensions {
22 ext.MarshalInto(b)
23 }
24
25 b.PutLength(size)
26
27 return b.Bytes(), nil
28}
29
30// UnmarshalBinary unmarshals a full raw packet out of the given data.
31// It is assumed that the uint32(length) has already been consumed to receive the data.
32// It is also assumed that the uint8(type) has already been consumed to which packet to unmarshal into.
33func (p *InitPacket) UnmarshalBinary(data []byte) (err error) {
34 buf := NewBuffer(data)
35
36 *p = InitPacket{
37 Version: buf.ConsumeUint32(),
38 }
39
40 for buf.Len() > 0 {
41 var ext ExtensionPair
42 if err := ext.UnmarshalFrom(buf); err != nil {
43 return err
44 }
45
46 p.Extensions = append(p.Extensions, &ext)
47 }
48
49 return buf.Err
50}
51
52// VersionPacket defines the SSH_FXP_VERSION packet.
53type VersionPacket struct {
54 Version uint32
55 Extensions []*ExtensionPair
56}
57
58// MarshalBinary returns p as the binary encoding of p.
59func (p *VersionPacket) MarshalBinary() ([]byte, error) {
60 size := 1 + 4 // byte(type) + uint32(version)
61
62 for _, ext := range p.Extensions {
63 size += ext.Len()
64 }
65
66 b := NewBuffer(make([]byte, 4, 4+size))
67 b.AppendUint8(uint8(PacketTypeVersion))
68 b.AppendUint32(p.Version)
69
70 for _, ext := range p.Extensions {
71 ext.MarshalInto(b)
72 }
73
74 b.PutLength(size)
75
76 return b.Bytes(), nil
77}
78
79// UnmarshalBinary unmarshals a full raw packet out of the given data.
80// It is assumed that the uint32(length) has already been consumed to receive the data.
81// It is also assumed that the uint8(type) has already been consumed to which packet to unmarshal into.
82func (p *VersionPacket) UnmarshalBinary(data []byte) (err error) {
83 buf := NewBuffer(data)
84
85 *p = VersionPacket{
86 Version: buf.ConsumeUint32(),
87 }
88
89 for buf.Len() > 0 {
90 var ext ExtensionPair
91 if err := ext.UnmarshalFrom(buf); err != nil {
92 return err
93 }
94
95 p.Extensions = append(p.Extensions, &ext)
96 }
97
98 return nil
99}