initial commit

This commit is contained in:
2026-05-12 21:38:14 +09:00
commit bab9ac8733
42 changed files with 6419 additions and 0 deletions

138
crates/rsh-types/src/lib.rs Normal file
View File

@@ -0,0 +1,138 @@
use serde::{Deserialize, Serialize};
pub const PROTOCOL_VERSION: u32 = 1;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StubInfo {
pub hostname: String,
pub user: String,
pub os: String,
pub arch: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SessionView {
pub id: String,
pub has_password: bool,
pub created_at: i64,
pub connection_count: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConnectionView {
pub session_id: String,
pub connection_id: u64,
pub info: StubInfo,
pub connected_at: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SessionRecord {
pub id: String,
pub password_hash: Option<String>,
pub created_at: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "t", content = "c")]
pub enum StubMsg {
Hello {
session_id: String,
password: Option<String>,
info: StubInfo,
},
Stdout(Vec<u8>),
Stderr(Vec<u8>),
Exited { code: Option<i32> },
Pong,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "t", content = "c")]
pub enum BackendStubMsg {
Accepted { connection_id: u64 },
Rejected { reason: String },
Stdin(Vec<u8>),
Resize { cols: u16, rows: u16 },
Kill,
Ping,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "t", content = "c")]
pub enum AttachIOFrame {
Stdin(Vec<u8>),
Resize { cols: u16, rows: u16 },
Eof,
Kill,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "t", content = "c")]
pub enum OpReq {
SessionCreate { name: String, password_hash: Option<String> },
SessionDelete { name: String, disconnect: bool },
SessionUpdate {
name: String,
set_password_hash: Option<Option<String>>,
disconnect: bool,
},
SessionList,
ConnectionList { session: Option<String> },
Attach {
session: String,
connection_id: Option<u64>,
pty: bool,
cols: u16,
rows: u16,
},
AttachIO(AttachIOFrame),
Detach,
KeysList,
KeysAppend { keys: Vec<String> },
KeysRemove { keys: Vec<String> },
KeysReplace { content: String },
Watch { session: Option<String> },
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "t", content = "c")]
pub enum OpResp {
Ok,
Err(String),
Sessions(Vec<SessionView>),
Connections(Vec<ConnectionView>),
AttachReady { connection_id: u64 },
Stdout(Vec<u8>),
Stderr(Vec<u8>),
Exited { code: Option<i32> },
Keys(Vec<String>),
WatchStarted,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "t", content = "c")]
pub enum OpEvent {
NewConnection(ConnectionView),
ConnectionClosed { session: String, connection_id: u64 },
NewSession(SessionView),
SessionDeleted { session: String },
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "t", content = "c")]
pub enum OpMsg {
AuthInit { pubkey_openssh: String },
AuthSign { signature: Vec<u8>, alg: String },
Req { id: u64, body: OpReq },
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "t", content = "c")]
pub enum BackendOpMsg {
Challenge { nonce: [u8; 32] },
AuthOk,
AuthFail { reason: String },
Resp { id: u64, body: OpResp },
Event(OpEvent),
}