package common
+import "core:bytes"
import "core:crypto/ed25519"
+import "core:crypto/sha3"
+import "core:io"
+import "core:net"
+import "core:mem"
-Public_Key_Bytes :: [32]u8
+ROOM_KEY_SIZE :: 32
-Message :: struct {
- room_id: string,
- content: string,
+From_Bytes_Error {
+ Not_Enough_Bytes,
+ Invalid_Public_Key,
+}
+
+Write :: struct {
+ room_key: [ROOM_KEY_SIZE]u8,
+ message: string,
}
Client_Request_Content :: union {
- Message,
+ Write,
}
Client_Request :: struct {
signature: [32]u8,
}
-client_request_parse :: proc(source: []u8) -> (Client_Request, bool) {
- panic("TODO")
+client_request_from_bytes :: proc(bytes: []u8) -> (Client_Request, From_Bytes_Error) {
+ bytes := bytes
+ bytes_buffer := bytes.Buffer{ buf = mem.buffer_from_slice(bytes) }
+ stream := bytes.buffer_to_stream(&bytes_buffer)
+
+ public_key_bytes: [ed25519.PUBLIC_KEY_SIZE]u8
+
+ err1 := io.read_at_least(stream, public_key_bytes, len(public_key_bytes))
+
+ if err1 != nil {
+ return {}, .Not_Enough_Bytes
+ }
+
+ public_key: ed25519.Public_Key
+ ok := ed25519.public_key_set_bytes(&public_key, public_key_bytes[:])
+
+ if !ok {
+ return {}, .Invalid_Public_Key
+ }
+
+ return {
+ public_key = public_key,
+ content = content,
+ timestamp = timestamp,
+ signature = signature,
+ },
+ nil
+}
+
+client_request_to_bytes :: proc(stream: io.Stream, request: Client_Request) {
+
}
client_request_verify :: proc(request: Client_Request, expiration: Maybe(i64)) -> bool {
panic("TODO")
}
-Server_Request :: union {
- Message,
+send_client_request :: proc(server: net.TCP_Socket, request: Client_Request) {
+ panic("TODO")
}
+Server_Request :: union {}
+
send_server_request :: proc(request: Server_Request) {
panic("TODO")
}
// Success: Returns previous cursor state
// Error: Returns ERR
curs_set :: proc(visibility: c.int) -> c.int ---
+
+ notimeout :: proc(win: ^Window, bf: bool) -> c.int ---
+ wtimeout :: proc(win: ^Window, delay: c.int) ---
+ timeout :: proc(delay: c.int) ---
}