Skip to main content

doublecrypt_core/
proto.rs

1//! Protobuf types for the doublecrypt block-store protocol.
2//!
3//! These are hand-written prost structs matching `proto/blockstore.proto`.
4//! They are wire-compatible with the length-prefixed protobuf protocol used
5//! by `doublecrypt-server` and can be imported directly by both the client
6//! ([`NetworkBlockStore`](crate::network_store::NetworkBlockStore)) and the
7//! server, avoiding any need for `protoc` or `prost-build`.
8//!
9//! # Usage from `doublecrypt-server`
10//!
11//! ```toml
12//! [dependencies]
13//! doublecrypt-core = { version = "0.1", default-features = false }
14//! ```
15//!
16//! ```rust,ignore
17//! use doublecrypt_core::proto::{Request, Response, request, response};
18//! ```
19
20// ── Requests ────────────────────────────────────────────────
21
22#[derive(Clone, PartialEq, ::prost::Message)]
23pub struct Request {
24    #[prost(uint64, tag = "1")]
25    pub request_id: u64,
26    #[prost(oneof = "request::Command", tags = "2, 3, 4, 5, 6")]
27    pub command: ::core::option::Option<request::Command>,
28}
29
30pub mod request {
31    #[derive(Clone, PartialEq, ::prost::Oneof)]
32    pub enum Command {
33        #[prost(message, tag = "2")]
34        ReadBlock(super::ReadBlockRequest),
35        #[prost(message, tag = "3")]
36        WriteBlock(super::WriteBlockRequest),
37        #[prost(message, tag = "4")]
38        Sync(super::SyncRequest),
39        #[prost(message, tag = "5")]
40        GetInfo(super::GetInfoRequest),
41        #[prost(message, tag = "6")]
42        Authenticate(super::AuthenticateRequest),
43    }
44}
45
46#[derive(Clone, PartialEq, ::prost::Message)]
47pub struct ReadBlockRequest {
48    #[prost(uint64, tag = "1")]
49    pub block_id: u64,
50}
51
52#[derive(Clone, PartialEq, ::prost::Message)]
53pub struct WriteBlockRequest {
54    #[prost(uint64, tag = "1")]
55    pub block_id: u64,
56    #[prost(bytes = "vec", tag = "2")]
57    pub data: Vec<u8>,
58}
59
60#[derive(Clone, PartialEq, ::prost::Message)]
61pub struct SyncRequest {}
62
63#[derive(Clone, PartialEq, ::prost::Message)]
64pub struct GetInfoRequest {}
65
66#[derive(Clone, PartialEq, ::prost::Message)]
67pub struct AuthenticateRequest {
68    /// HKDF-derived auth token (32 bytes, independent of the encryption key).
69    #[prost(bytes = "vec", tag = "1")]
70    pub auth_token: Vec<u8>,
71}
72
73// ── Responses ───────────────────────────────────────────────
74
75#[derive(Clone, PartialEq, ::prost::Message)]
76pub struct Response {
77    #[prost(uint64, tag = "1")]
78    pub request_id: u64,
79    #[prost(oneof = "response::Result", tags = "2, 3, 4, 5, 6, 7")]
80    pub result: ::core::option::Option<response::Result>,
81}
82
83pub mod response {
84    #[derive(Clone, PartialEq, ::prost::Oneof)]
85    pub enum Result {
86        #[prost(message, tag = "2")]
87        ReadBlock(super::ReadBlockResponse),
88        #[prost(message, tag = "3")]
89        WriteBlock(super::WriteBlockResponse),
90        #[prost(message, tag = "4")]
91        Sync(super::SyncResponse),
92        #[prost(message, tag = "5")]
93        GetInfo(super::GetInfoResponse),
94        #[prost(message, tag = "6")]
95        Error(super::ErrorResponse),
96        #[prost(message, tag = "7")]
97        Authenticate(super::AuthenticateResponse),
98    }
99}
100
101#[derive(Clone, PartialEq, ::prost::Message)]
102pub struct ReadBlockResponse {
103    #[prost(bytes = "vec", tag = "1")]
104    pub data: Vec<u8>,
105}
106
107#[derive(Clone, PartialEq, ::prost::Message)]
108pub struct WriteBlockResponse {}
109
110#[derive(Clone, PartialEq, ::prost::Message)]
111pub struct SyncResponse {}
112
113#[derive(Clone, PartialEq, ::prost::Message)]
114pub struct GetInfoResponse {
115    #[prost(uint32, tag = "1")]
116    pub block_size: u32,
117    #[prost(uint64, tag = "2")]
118    pub total_blocks: u64,
119}
120
121#[derive(Clone, PartialEq, ::prost::Message)]
122pub struct AuthenticateResponse {}
123
124#[derive(Clone, PartialEq, ::prost::Message)]
125pub struct ErrorResponse {
126    #[prost(int32, tag = "1")]
127    pub code: i32,
128    #[prost(string, tag = "2")]
129    pub message: String,
130}