跳到主要内容

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

浏览文件

open_packets.go

86 行 · 2.3 KB历史下载
1package sshfx
2
3// SSH_FXF_* flags.
4const (
5 FlagRead = 1 << iota // SSH_FXF_READ
6 FlagWrite // SSH_FXF_WRITE
7 FlagAppend // SSH_FXF_APPEND
8 FlagCreate // SSH_FXF_CREAT
9 FlagTruncate // SSH_FXF_TRUNC
10 FlagExclusive // SSH_FXF_EXCL
11)
12
13// OpenPacket defines the SSH_FXP_OPEN packet.
14type OpenPacket struct {
15 Filename string
16 PFlags uint32
17 Attrs Attributes
18}
19
20// Type returns the SSH_FXP_xy value associated with this packet type.
21func (p *OpenPacket) Type() PacketType {
22 return PacketTypeOpen
23}
24
25// MarshalPacket returns p as a two-part binary encoding of p.
26func (p *OpenPacket) MarshalPacket(reqid uint32, b []byte) (header, payload []byte, err error) {
27 buf := NewBuffer(b)
28 if buf.Cap() < 9 {
29 // string(filename) + uint32(pflags) + ATTRS(attrs)
30 size := 4 + len(p.Filename) + 4 + p.Attrs.Len()
31 buf = NewMarshalBuffer(size)
32 }
33
34 buf.StartPacket(PacketTypeOpen, reqid)
35 buf.AppendString(p.Filename)
36 buf.AppendUint32(p.PFlags)
37
38 p.Attrs.MarshalInto(buf)
39
40 return buf.Packet(payload)
41}
42
43// UnmarshalPacketBody unmarshals the packet body from the given Buffer.
44// It is assumed that the uint32(request-id) has already been consumed.
45func (p *OpenPacket) UnmarshalPacketBody(buf *Buffer) (err error) {
46 *p = OpenPacket{
47 Filename: buf.ConsumeString(),
48 PFlags: buf.ConsumeUint32(),
49 }
50
51 return p.Attrs.UnmarshalFrom(buf)
52}
53
54// OpenDirPacket defines the SSH_FXP_OPENDIR packet.
55type OpenDirPacket struct {
56 Path string
57}
58
59// Type returns the SSH_FXP_xy value associated with this packet type.
60func (p *OpenDirPacket) Type() PacketType {
61 return PacketTypeOpenDir
62}
63
64// MarshalPacket returns p as a two-part binary encoding of p.
65func (p *OpenDirPacket) MarshalPacket(reqid uint32, b []byte) (header, payload []byte, err error) {
66 buf := NewBuffer(b)
67 if buf.Cap() < 9 {
68 size := 4 + len(p.Path) // string(path)
69 buf = NewMarshalBuffer(size)
70 }
71
72 buf.StartPacket(PacketTypeOpenDir, reqid)
73 buf.AppendString(p.Path)
74
75 return buf.Packet(payload)
76}
77
78// UnmarshalPacketBody unmarshals the packet body from the given Buffer.
79// It is assumed that the uint32(request-id) has already been consumed.
80func (p *OpenDirPacket) UnmarshalPacketBody(buf *Buffer) (err error) {
81 *p = OpenDirPacket{
82 Path: buf.ConsumeString(),
83 }
84
85 return buf.Err
86}