more work on identity->chat hello/handshake

This commit is contained in:
sam 2024-01-18 21:44:53 +01:00
parent 1e53661b0a
commit 041531e88a
12 changed files with 96 additions and 40 deletions

View file

@ -27,15 +27,15 @@ pub fn is_valid_domain(domain: &str) -> bool {
pub async fn get<R: DeserializeOwned>(
private_key: &RsaPrivateKey,
self_domain: String,
host: String,
path: String,
self_domain: &str,
host: &str,
path: &str,
user_id: Option<&str>,
) -> Result<R> {
let (signature, date) = build_signature(
private_key,
host.clone(),
path.clone(),
host,
path,
None,
user_id.clone(),
);
@ -58,9 +58,9 @@ pub async fn get<R: DeserializeOwned>(
pub async fn post<T: Serialize, R: DeserializeOwned>(
private_key: &RsaPrivateKey,
self_domain: String,
host: String,
path: String,
self_domain: &str,
host: &str,
path: &str,
user_id: Option<&str>,
body: &T,
) -> Result<R> {
@ -68,8 +68,8 @@ pub async fn post<T: Serialize, R: DeserializeOwned>(
let (signature, date) = build_signature(
private_key,
host.clone(),
path.clone(),
host,
path,
Some(body.len()),
user_id.clone(),
);

View file

@ -10,8 +10,8 @@ use crate::FoxError;
pub fn build_signature(
private_key: &RsaPrivateKey,
host: String,
request_path: String,
host: &str,
request_path: &str,
content_length: Option<usize>,
user_id: Option<&str>,
) -> (String, DateTime<Utc>) {

View file

@ -0,0 +1,18 @@
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug)]
pub struct HelloRequest {
pub host: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct HelloResponse {
pub public_key: String,
pub host: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct NodeResponse {
pub software: String,
pub public_key: String,
}

View file

@ -0,0 +1,3 @@
mod hello;
pub use hello::{HelloRequest, HelloResponse, NodeResponse};

View file

@ -1,3 +1,4 @@
mod event;
pub mod http;
pub use event::{DispatchEvent, Payload};