json schema generation
This commit is contained in:
@@ -70,6 +70,7 @@ impl VeilidAPI {
|
||||
}
|
||||
Err(VeilidAPIError::not_initialized())
|
||||
}
|
||||
#[cfg(feature = "unstable-blockstore")]
|
||||
pub fn block_store(&self) -> VeilidAPIResult<BlockStore> {
|
||||
let inner = self.inner.lock();
|
||||
if let Some(context) = &inner.context {
|
||||
|
@@ -18,49 +18,210 @@ pub struct CryptoSystemResponse {
|
||||
#[serde(tag = "cs_op")]
|
||||
pub enum CryptoSystemRequestOp {
|
||||
Release,
|
||||
CachedDh,
|
||||
ComputeDh,
|
||||
RandomBytes,
|
||||
CachedDh {
|
||||
#[schemars(with = "String")]
|
||||
key: PublicKey,
|
||||
#[schemars(with = "String")]
|
||||
secret: SecretKey,
|
||||
},
|
||||
ComputeDh {
|
||||
#[schemars(with = "String")]
|
||||
key: PublicKey,
|
||||
#[schemars(with = "String")]
|
||||
secret: SecretKey,
|
||||
},
|
||||
RandomBytes {
|
||||
len: u32,
|
||||
},
|
||||
DefaultSaltLength,
|
||||
HashPassword,
|
||||
VerifyPassword,
|
||||
DeriveSharedSecret,
|
||||
HashPassword {
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
password: Vec<u8>,
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
salt: Vec<u8>,
|
||||
},
|
||||
VerifyPassword {
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
password: Vec<u8>,
|
||||
password_hash: String,
|
||||
},
|
||||
DeriveSharedSecret {
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
password: Vec<u8>,
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
salt: Vec<u8>,
|
||||
},
|
||||
RandomNonce,
|
||||
RandomSharedSecret,
|
||||
GenerateKeyPair,
|
||||
GenerateHash,
|
||||
ValidateKeyPair,
|
||||
ValidateHash,
|
||||
Distance,
|
||||
Sign,
|
||||
Verify,
|
||||
GenerateHash {
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
data: Vec<u8>,
|
||||
},
|
||||
ValidateKeyPair {
|
||||
#[schemars(with = "String")]
|
||||
key: PublicKey,
|
||||
#[schemars(with = "String")]
|
||||
secret: SecretKey,
|
||||
},
|
||||
ValidateHash {
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
data: Vec<u8>,
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
hash_digest: Vec<u8>,
|
||||
},
|
||||
Distance {
|
||||
#[schemars(with = "String")]
|
||||
key1: CryptoKey,
|
||||
#[schemars(with = "String")]
|
||||
key2: CryptoKey,
|
||||
},
|
||||
Sign {
|
||||
#[schemars(with = "String")]
|
||||
key: PublicKey,
|
||||
#[schemars(with = "String")]
|
||||
secret: SecretKey,
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
data: Vec<u8>,
|
||||
},
|
||||
Verify {
|
||||
#[schemars(with = "String")]
|
||||
key: PublicKey,
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
data: Vec<u8>,
|
||||
#[schemars(with = "String")]
|
||||
secret: Signature,
|
||||
},
|
||||
AeadOverhead,
|
||||
DecryptAead,
|
||||
EncryptAead,
|
||||
CryptNoAuth,
|
||||
DecryptAead {
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
body: Vec<u8>,
|
||||
#[schemars(with = "String")]
|
||||
nonce: Nonce,
|
||||
#[schemars(with = "String")]
|
||||
shared_secret: SharedSecret,
|
||||
#[serde(with = "opt_json_as_base64")]
|
||||
#[schemars(with = "Option<String>")]
|
||||
associated_data: Option<Vec<u8>>,
|
||||
},
|
||||
EncryptAead {
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
body: Vec<u8>,
|
||||
#[schemars(with = "String")]
|
||||
nonce: Nonce,
|
||||
#[schemars(with = "String")]
|
||||
shared_secret: SharedSecret,
|
||||
#[serde(with = "opt_json_as_base64")]
|
||||
#[schemars(with = "Option<String>")]
|
||||
associated_data: Option<Vec<u8>>,
|
||||
},
|
||||
CryptNoAuth {
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
body: Vec<u8>,
|
||||
#[schemars(with = "String")]
|
||||
nonce: Nonce,
|
||||
#[schemars(with = "String")]
|
||||
shared_secret: SharedSecret,
|
||||
},
|
||||
}
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(tag = "cs_op")]
|
||||
pub enum CryptoSystemResponseOp {
|
||||
Release,
|
||||
CachedDh,
|
||||
ComputeDh,
|
||||
RandomBytes,
|
||||
DefaultSaltLength,
|
||||
HashPassword,
|
||||
VerifyPassword,
|
||||
DeriveSharedSecret,
|
||||
RandomNonce,
|
||||
RandomSharedSecret,
|
||||
GenerateKeyPair,
|
||||
GenerateHash,
|
||||
ValidateKeyPair,
|
||||
ValidateHash,
|
||||
Distance,
|
||||
Sign,
|
||||
Verify,
|
||||
AeadOverhead,
|
||||
DecryptAead,
|
||||
EncryptAead,
|
||||
CryptNoAuth,
|
||||
CachedDh {
|
||||
#[serde(flatten)]
|
||||
#[schemars(with = "ApiResult<String>")]
|
||||
result: ApiResultWithString<SharedSecret>,
|
||||
},
|
||||
ComputeDh {
|
||||
#[serde(flatten)]
|
||||
#[schemars(with = "ApiResult<String>")]
|
||||
result: ApiResultWithString<SharedSecret>,
|
||||
},
|
||||
RandomBytes {
|
||||
#[serde(flatten)]
|
||||
#[schemars(with = "ApiResult<String>")]
|
||||
result: ApiResultWithVecU8,
|
||||
},
|
||||
DefaultSaltLength {
|
||||
value: u32,
|
||||
},
|
||||
HashPassword {
|
||||
#[serde(flatten)]
|
||||
result: ApiResult<String>,
|
||||
},
|
||||
VerifyPassword {
|
||||
#[serde(flatten)]
|
||||
result: ApiResult<bool>,
|
||||
},
|
||||
DeriveSharedSecret {
|
||||
#[serde(flatten)]
|
||||
#[schemars(with = "ApiResult<String>")]
|
||||
result: ApiResultWithString<SharedSecret>,
|
||||
},
|
||||
RandomNonce {
|
||||
#[schemars(with = "String")]
|
||||
value: Nonce,
|
||||
},
|
||||
RandomSharedSecret {
|
||||
#[schemars(with = "String")]
|
||||
value: SharedSecret,
|
||||
},
|
||||
GenerateKeyPair {
|
||||
#[schemars(with = "String")]
|
||||
value: KeyPair,
|
||||
},
|
||||
GenerateHash {
|
||||
#[schemars(with = "String")]
|
||||
value: HashDigest,
|
||||
},
|
||||
ValidateKeyPair {
|
||||
value: bool,
|
||||
},
|
||||
ValidateHash {
|
||||
value: bool,
|
||||
},
|
||||
Distance {
|
||||
#[schemars(with = "String")]
|
||||
value: CryptoKeyDistance,
|
||||
},
|
||||
Sign {
|
||||
#[schemars(with = "String")]
|
||||
value: Signature,
|
||||
},
|
||||
Verify {
|
||||
#[serde(flatten)]
|
||||
result: ApiResult<()>,
|
||||
},
|
||||
AeadOverhead {
|
||||
value: u32,
|
||||
},
|
||||
DecryptAead {
|
||||
#[serde(flatten)]
|
||||
#[schemars(with = "ApiResult<String>")]
|
||||
result: ApiResultWithVecU8,
|
||||
},
|
||||
EncryptAead {
|
||||
#[serde(flatten)]
|
||||
#[schemars(with = "ApiResult<String>")]
|
||||
result: ApiResultWithVecU8,
|
||||
},
|
||||
CryptNoAuth {
|
||||
#[serde(flatten)]
|
||||
#[schemars(with = "ApiResult<String>")]
|
||||
result: ApiResultWithVecU8,
|
||||
},
|
||||
}
|
||||
|
@@ -11,7 +11,8 @@ pub use crypto_system::*;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct Request {
|
||||
/// Operation Id (pairs with Response)
|
||||
/// Operation Id (pairs with Response, or empty if unidirectional)
|
||||
#[serde(default)]
|
||||
id: String,
|
||||
/// The request operation variant
|
||||
#[serde(flatten)]
|
||||
@@ -20,7 +21,8 @@ pub struct Request {
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct Response {
|
||||
/// Operation Id (pairs with Request)
|
||||
/// Operation Id (pairs with Request, or empty if unidirectional)
|
||||
#[serde(default)]
|
||||
id: String,
|
||||
/// The response operation variant
|
||||
#[serde(flatten)]
|
||||
@@ -36,17 +38,14 @@ pub enum RequestOp {
|
||||
NewPrivateRoute,
|
||||
NewCustomPrivateRoute {
|
||||
#[schemars(with = "Vec<String>")]
|
||||
crypto_kinds: Vec<CryptoKind>,
|
||||
kinds: Vec<CryptoKind>,
|
||||
#[serde(default)]
|
||||
stability: Stability,
|
||||
#[serde(default)]
|
||||
sequencing: Sequencing,
|
||||
},
|
||||
ImportRemotePrivateRoute {
|
||||
#[serde(
|
||||
serialize_with = "json_as_base64::serialize",
|
||||
deserialize_with = "json_as_base64::deserialize"
|
||||
)]
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
blob: Vec<u8>,
|
||||
},
|
||||
@@ -57,10 +56,7 @@ pub enum RequestOp {
|
||||
AppCallReply {
|
||||
#[schemars(with = "String")]
|
||||
call_id: OperationId,
|
||||
#[serde(
|
||||
serialize_with = "json_as_base64::serialize",
|
||||
deserialize_with = "json_as_base64::deserialize"
|
||||
)]
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
message: Vec<u8>,
|
||||
},
|
||||
@@ -79,27 +75,21 @@ pub enum RequestOp {
|
||||
// Crypto
|
||||
GetCryptoSystem {
|
||||
#[schemars(with = "String")]
|
||||
crypto_kind: CryptoKind,
|
||||
kind: CryptoKind,
|
||||
},
|
||||
BestCryptoSystem,
|
||||
CryptoSystem(CryptoSystemRequest),
|
||||
VerifySignatures {
|
||||
#[schemars(with = "Vec<String>")]
|
||||
node_ids: Vec<TypedKey>,
|
||||
#[serde(
|
||||
serialize_with = "json_as_base64::serialize",
|
||||
deserialize_with = "json_as_base64::deserialize"
|
||||
)]
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
data: Vec<u8>,
|
||||
#[schemars(with = "Vec<String>")]
|
||||
signatures: Vec<TypedSignature>,
|
||||
},
|
||||
GenerateSignatures {
|
||||
#[serde(
|
||||
serialize_with = "json_as_base64::serialize",
|
||||
deserialize_with = "json_as_base64::deserialize"
|
||||
)]
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
data: Vec<u8>,
|
||||
#[schemars(with = "Vec<String>")]
|
||||
@@ -107,7 +97,7 @@ pub enum RequestOp {
|
||||
},
|
||||
GenerateKeyPair {
|
||||
#[schemars(with = "String")]
|
||||
crypto_kind: CryptoKind,
|
||||
kind: CryptoKind,
|
||||
},
|
||||
// Misc
|
||||
Now,
|
||||
@@ -122,10 +112,7 @@ pub enum RequestOp {
|
||||
pub struct NewPrivateRouteResult {
|
||||
#[schemars(with = "String")]
|
||||
route_id: RouteId,
|
||||
#[serde(
|
||||
serialize_with = "json_as_base64::serialize",
|
||||
deserialize_with = "json_as_base64::deserialize"
|
||||
)]
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
blob: Vec<u8>,
|
||||
}
|
||||
@@ -133,6 +120,9 @@ pub struct NewPrivateRouteResult {
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(tag = "op")]
|
||||
pub enum ResponseOp {
|
||||
Update {
|
||||
value: VeilidUpdate,
|
||||
},
|
||||
GetState {
|
||||
#[serde(flatten)]
|
||||
result: ApiResult<VeilidState>,
|
||||
@@ -153,28 +143,74 @@ pub enum ResponseOp {
|
||||
#[serde(flatten)]
|
||||
result: ApiResult<NewPrivateRouteResult>,
|
||||
},
|
||||
ImportRemotePrivateRoute,
|
||||
ReleasePrivateRoute,
|
||||
AppCallReply,
|
||||
ImportRemotePrivateRoute {
|
||||
#[serde(flatten)]
|
||||
#[schemars(with = "ApiResult<String>")]
|
||||
result: ApiResultWithString<RouteId>,
|
||||
},
|
||||
ReleasePrivateRoute {
|
||||
#[serde(flatten)]
|
||||
result: ApiResult<()>,
|
||||
},
|
||||
AppCallReply {
|
||||
#[serde(flatten)]
|
||||
result: ApiResult<()>,
|
||||
},
|
||||
// Routing Context
|
||||
NewRoutingContext,
|
||||
NewRoutingContext {
|
||||
value: String,
|
||||
},
|
||||
RoutingContext(RoutingContextResponse),
|
||||
// TableDb
|
||||
OpenTableDb,
|
||||
DeleteTableDb,
|
||||
OpenTableDb {
|
||||
#[serde(flatten)]
|
||||
result: ApiResult<String>,
|
||||
},
|
||||
DeleteTableDb {
|
||||
#[serde(flatten)]
|
||||
result: ApiResult<bool>,
|
||||
},
|
||||
TableDb(TableDbResponse),
|
||||
// Crypto
|
||||
GetCryptoSystem,
|
||||
BestCryptoSystem,
|
||||
GetCryptoSystem {
|
||||
#[serde(flatten)]
|
||||
result: ApiResult<String>,
|
||||
},
|
||||
BestCryptoSystem {
|
||||
value: String,
|
||||
},
|
||||
CryptoSystem(CryptoSystemResponse),
|
||||
VerifySignatures,
|
||||
GenerateSignatures,
|
||||
GenerateKeyPair,
|
||||
VerifySignatures {
|
||||
#[serde(flatten)]
|
||||
#[schemars(with = "ApiResult<Vec<String>>")]
|
||||
result: ApiResultWithVecString<TypedKeySet>,
|
||||
},
|
||||
GenerateSignatures {
|
||||
#[serde(flatten)]
|
||||
#[schemars(with = "ApiResult<Vec<String>>")]
|
||||
result: ApiResultWithVecString<TypedSignatureSet>,
|
||||
},
|
||||
GenerateKeyPair {
|
||||
#[serde(flatten)]
|
||||
#[schemars(with = "ApiResult<String>")]
|
||||
result: ApiResultWithString<TypedKeyPair>,
|
||||
},
|
||||
// Misc
|
||||
Now,
|
||||
Debug,
|
||||
VeilidVersionString,
|
||||
VeilidVersion,
|
||||
Now {
|
||||
#[schemars(with = "String")]
|
||||
value: Timestamp,
|
||||
},
|
||||
Debug {
|
||||
value: String,
|
||||
},
|
||||
VeilidVersionString {
|
||||
value: String,
|
||||
},
|
||||
VeilidVersion {
|
||||
major: u32,
|
||||
minor: u32,
|
||||
patch: u32,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
@@ -187,6 +223,49 @@ where
|
||||
Err { error: VeilidAPIError },
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(untagged)]
|
||||
pub enum ApiResultWithString<T>
|
||||
where
|
||||
T: Clone + fmt::Debug,
|
||||
{
|
||||
Ok {
|
||||
#[schemars(with = "String")]
|
||||
value: T,
|
||||
},
|
||||
Err {
|
||||
error: VeilidAPIError,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(untagged)]
|
||||
pub enum ApiResultWithVecU8 {
|
||||
Ok {
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
value: Vec<u8>,
|
||||
},
|
||||
Err {
|
||||
error: VeilidAPIError,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(untagged)]
|
||||
pub enum ApiResultWithVecString<T>
|
||||
where
|
||||
T: Clone + fmt::Debug,
|
||||
{
|
||||
Ok {
|
||||
#[schemars(with = "Vec<String>")]
|
||||
value: T,
|
||||
},
|
||||
Err {
|
||||
error: VeilidAPIError,
|
||||
},
|
||||
}
|
||||
|
||||
pub fn emit_schemas(out: &mut HashMap<String, String>) {
|
||||
let schema_request = schema_for!(Request);
|
||||
let schema_response = schema_for!(Response);
|
||||
|
@@ -19,34 +19,122 @@ pub struct RoutingContextResponse {
|
||||
pub enum RoutingContextRequestOp {
|
||||
Release,
|
||||
WithPrivacy,
|
||||
WithCustomPrivacy,
|
||||
WithSequencing,
|
||||
AppCall,
|
||||
AppMessage,
|
||||
CreateDhtRecord,
|
||||
OpenDhtRecord,
|
||||
CloseDhtRecord,
|
||||
DeleteDhtRecord,
|
||||
GetDhtValue,
|
||||
SetDhtValue,
|
||||
WatchDhtValues,
|
||||
CancelDhtWatch,
|
||||
WithCustomPrivacy {
|
||||
stability: Stability,
|
||||
},
|
||||
WithSequencing {
|
||||
sequencing: Sequencing,
|
||||
},
|
||||
AppCall {
|
||||
target: String,
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
request: Vec<u8>,
|
||||
},
|
||||
AppMessage {
|
||||
target: String,
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
message: Vec<u8>,
|
||||
},
|
||||
CreateDhtRecord {
|
||||
#[schemars(with = "String")]
|
||||
kind: CryptoKind,
|
||||
schema: DHTSchema,
|
||||
},
|
||||
OpenDhtRecord {
|
||||
#[schemars(with = "String")]
|
||||
key: TypedKey,
|
||||
#[schemars(with = "Option<String>")]
|
||||
writer: Option<KeyPair>,
|
||||
},
|
||||
CloseDhtRecord {
|
||||
#[schemars(with = "String")]
|
||||
key: TypedKey,
|
||||
},
|
||||
DeleteDhtRecord {
|
||||
#[schemars(with = "String")]
|
||||
key: TypedKey,
|
||||
},
|
||||
GetDhtValue {
|
||||
#[schemars(with = "String")]
|
||||
key: TypedKey,
|
||||
subkey: ValueSubkey,
|
||||
force_refresh: bool,
|
||||
},
|
||||
SetDhtValue {
|
||||
#[schemars(with = "String")]
|
||||
key: TypedKey,
|
||||
subkey: ValueSubkey,
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
data: Vec<u8>,
|
||||
},
|
||||
WatchDhtValues {
|
||||
#[schemars(with = "String")]
|
||||
key: TypedKey,
|
||||
subkeys: ValueSubkeyRangeSet,
|
||||
expiration: Timestamp,
|
||||
count: u32,
|
||||
},
|
||||
CancelDhtWatch {
|
||||
#[schemars(with = "String")]
|
||||
key: TypedKey,
|
||||
subkeys: ValueSubkeyRangeSet,
|
||||
},
|
||||
}
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(tag = "rc_op")]
|
||||
pub enum RoutingContextResponseOp {
|
||||
Release,
|
||||
WithPrivacy,
|
||||
WithCustomPrivacy,
|
||||
WithSequencing,
|
||||
AppCall,
|
||||
AppMessage,
|
||||
CreateDhtRecord,
|
||||
OpenDhtRecord,
|
||||
CloseDhtRecord,
|
||||
DeleteDhtRecord,
|
||||
GetDhtValue,
|
||||
SetDhtValue,
|
||||
WatchDhtValues,
|
||||
CancelDhtWatch,
|
||||
WithPrivacy {
|
||||
value: String,
|
||||
},
|
||||
WithCustomPrivacy {
|
||||
value: String,
|
||||
},
|
||||
WithSequencing {
|
||||
value: String,
|
||||
},
|
||||
AppCall {
|
||||
#[serde(flatten)]
|
||||
#[schemars(with = "ApiResult<String>")]
|
||||
result: ApiResultWithVecU8,
|
||||
},
|
||||
AppMessage {
|
||||
#[serde(flatten)]
|
||||
result: ApiResult<()>,
|
||||
},
|
||||
CreateDhtRecord {
|
||||
#[serde(flatten)]
|
||||
result: ApiResult<DHTRecordDescriptor>,
|
||||
},
|
||||
OpenDhtRecord {
|
||||
#[serde(flatten)]
|
||||
result: ApiResult<DHTRecordDescriptor>,
|
||||
},
|
||||
CloseDhtRecord {
|
||||
#[serde(flatten)]
|
||||
result: ApiResult<()>,
|
||||
},
|
||||
DeleteDhtRecord {
|
||||
#[serde(flatten)]
|
||||
result: ApiResult<()>,
|
||||
},
|
||||
GetDhtValue {
|
||||
#[serde(flatten)]
|
||||
result: ApiResult<Option<ValueData>>,
|
||||
},
|
||||
SetDhtValue {
|
||||
#[serde(flatten)]
|
||||
result: ApiResult<Option<ValueData>>,
|
||||
},
|
||||
WatchDhtValues {
|
||||
#[serde(flatten)]
|
||||
result: ApiResult<Timestamp>,
|
||||
},
|
||||
CancelDhtWatch {
|
||||
#[serde(flatten)]
|
||||
result: ApiResult<bool>,
|
||||
},
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ pub use alloc::string::ToString;
|
||||
pub use attachment_manager::AttachmentManager;
|
||||
pub use core::str::FromStr;
|
||||
pub use crypto::*;
|
||||
#[cfg(feature = "unstable-blockstore")]
|
||||
pub use intf::BlockStore;
|
||||
pub use intf::ProtectedStore;
|
||||
pub use network_manager::NetworkManager;
|
||||
|
@@ -290,10 +290,12 @@ impl RoutingContext {
|
||||
///////////////////////////////////
|
||||
/// Block Store
|
||||
|
||||
#[cfg(feature = "unstable-blockstore")]
|
||||
pub async fn find_block(&self, _block_id: PublicKey) -> VeilidAPIResult<Vec<u8>> {
|
||||
panic!("unimplemented");
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable-blockstore")]
|
||||
pub async fn supply_block(&self, _block_id: PublicKey) -> VeilidAPIResult<bool> {
|
||||
panic!("unimplemented");
|
||||
}
|
||||
|
@@ -55,6 +55,27 @@ pub mod json_as_base64 {
|
||||
}
|
||||
}
|
||||
|
||||
pub mod opt_json_as_base64 {
|
||||
use data_encoding::BASE64URL_NOPAD;
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
|
||||
pub fn serialize<S: Serializer>(v: &Option<Vec<u8>>, s: S) -> Result<S::Ok, S::Error> {
|
||||
let base64 = v.as_ref().map(|x| BASE64URL_NOPAD.encode(&x));
|
||||
Option::<String>::serialize(&base64, s)
|
||||
}
|
||||
|
||||
pub fn deserialize<'de, D: Deserializer<'de>>(d: D) -> Result<Option<Vec<u8>>, D::Error> {
|
||||
let base64 = Option::<String>::deserialize(d)?;
|
||||
base64
|
||||
.map(|x| {
|
||||
BASE64URL_NOPAD
|
||||
.decode(x.as_bytes())
|
||||
.map_err(|e| serde::de::Error::custom(e))
|
||||
})
|
||||
.transpose()
|
||||
}
|
||||
}
|
||||
|
||||
pub mod json_as_string {
|
||||
use std::fmt::Display;
|
||||
use std::str::FromStr;
|
||||
|
@@ -24,10 +24,7 @@ use super::*;
|
||||
#[archive_attr(repr(C, align(8)), derive(CheckBytes))]
|
||||
#[serde(transparent)]
|
||||
pub struct AlignedU64(
|
||||
#[serde(
|
||||
serialize_with = "json_as_string::serialize",
|
||||
deserialize_with = "json_as_string::deserialize"
|
||||
)]
|
||||
#[serde(with = "json_as_string")]
|
||||
#[schemars(with = "String")]
|
||||
u64,
|
||||
);
|
||||
|
@@ -16,18 +16,12 @@ use super::*;
|
||||
#[archive_attr(repr(C), derive(CheckBytes))]
|
||||
pub struct VeilidAppMessage {
|
||||
/// Some(sender) if the message was sent directly, None if received via a private/safety route
|
||||
#[serde(
|
||||
serialize_with = "opt_json_as_string::serialize",
|
||||
deserialize_with = "opt_json_as_string::deserialize"
|
||||
)]
|
||||
#[serde(with = "opt_json_as_string")]
|
||||
#[schemars(with = "Option<String>")]
|
||||
sender: Option<TypedKey>,
|
||||
|
||||
/// The content of the message to deliver to the application
|
||||
#[serde(
|
||||
serialize_with = "json_as_base64::serialize",
|
||||
deserialize_with = "json_as_base64::deserialize"
|
||||
)]
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
message: Vec<u8>,
|
||||
}
|
||||
@@ -61,26 +55,17 @@ impl VeilidAppMessage {
|
||||
#[archive_attr(repr(C), derive(CheckBytes))]
|
||||
pub struct VeilidAppCall {
|
||||
/// Some(sender) if the request was sent directly, None if received via a private/safety route
|
||||
#[serde(
|
||||
serialize_with = "opt_json_as_string::serialize",
|
||||
deserialize_with = "opt_json_as_string::deserialize"
|
||||
)]
|
||||
#[serde(with = "opt_json_as_string")]
|
||||
#[schemars(with = "Option<String>")]
|
||||
sender: Option<TypedKey>,
|
||||
|
||||
/// The content of the request to deliver to the application
|
||||
#[serde(
|
||||
serialize_with = "json_as_base64::serialize",
|
||||
deserialize_with = "json_as_base64::deserialize"
|
||||
)]
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
message: Vec<u8>,
|
||||
|
||||
/// The id to reply to
|
||||
#[serde(
|
||||
serialize_with = "json_as_string::serialize",
|
||||
deserialize_with = "json_as_string::deserialize"
|
||||
)]
|
||||
#[serde(with = "json_as_string")]
|
||||
#[schemars(with = "String")]
|
||||
id: OperationId,
|
||||
}
|
||||
|
@@ -21,10 +21,7 @@ pub struct ValueData {
|
||||
seq: ValueSeqNum,
|
||||
|
||||
/// The contents of a DHT Record
|
||||
#[serde(
|
||||
serialize_with = "json_as_base64::serialize",
|
||||
deserialize_with = "json_as_base64::deserialize"
|
||||
)]
|
||||
#[serde(with = "json_as_base64")]
|
||||
#[schemars(with = "String")]
|
||||
data: Vec<u8>,
|
||||
|
||||
|
@@ -18,12 +18,10 @@ use range_set_blaze::*;
|
||||
JsonSchema,
|
||||
)]
|
||||
#[archive_attr(repr(C), derive(CheckBytes))]
|
||||
#[serde(transparent)]
|
||||
pub struct ValueSubkeyRangeSet {
|
||||
#[with(RkyvRangeSetBlaze)]
|
||||
#[serde(
|
||||
serialize_with = "serialize_range_set_blaze::serialize",
|
||||
deserialize_with = "serialize_range_set_blaze::deserialize"
|
||||
)]
|
||||
#[serde(with = "serialize_range_set_blaze")]
|
||||
#[schemars(with = "Vec<(u32,u32)>")]
|
||||
data: RangeSetBlaze<ValueSubkey>,
|
||||
}
|
||||
|
Reference in New Issue
Block a user