mirror of
https://github.com/Blah-IM/blahrs.git
synced 2025-06-30 19:45:34 +00:00
refactor(types): WithSig
-> Signed
This commit is contained in:
parent
73eb441a26
commit
93d1589730
7 changed files with 39 additions and 39 deletions
|
@ -8,7 +8,7 @@ use std::task::{Context, Poll};
|
|||
|
||||
use anyhow::{bail, Context as _, Result};
|
||||
use axum::extract::ws::{Message, WebSocket};
|
||||
use blah_types::{AuthPayload, SignedChatMsg, WithSig};
|
||||
use blah_types::{AuthPayload, Signed, SignedChatMsg};
|
||||
use futures_util::future::Either;
|
||||
use futures_util::stream::SplitSink;
|
||||
use futures_util::{stream_select, SinkExt as _, Stream, StreamExt};
|
||||
|
@ -113,7 +113,7 @@ pub async fn handle_ws(st: Arc<AppState>, ws: &mut WebSocket) -> Result<Infallib
|
|||
.await
|
||||
.context("authentication timeout")?
|
||||
.ok_or(StreamEnded)??;
|
||||
let auth = serde_json::from_str::<WithSig<AuthPayload>>(&payload)?;
|
||||
let auth = serde_json::from_str::<Signed<AuthPayload>>(&payload)?;
|
||||
st.verify_signed_data(&auth)?;
|
||||
|
||||
st.db
|
||||
|
|
|
@ -12,8 +12,8 @@ use axum::{Json, Router};
|
|||
use axum_extra::extract::WithRejection as R;
|
||||
use blah_types::{
|
||||
ChatPayload, CreateGroup, CreatePeerChat, CreateRoomPayload, Id, MemberPermission, RoomAdminOp,
|
||||
RoomAdminPayload, RoomAttrs, RoomMetadata, ServerPermission, SignedChatMsg, Signee, UserKey,
|
||||
WithMsgId, WithSig,
|
||||
RoomAdminPayload, RoomAttrs, RoomMetadata, ServerPermission, Signed, SignedChatMsg, Signee,
|
||||
UserKey, WithMsgId,
|
||||
};
|
||||
use config::ServerConfig;
|
||||
use ed25519_dalek::SIGNATURE_LENGTH;
|
||||
|
@ -59,7 +59,7 @@ impl AppState {
|
|||
}
|
||||
}
|
||||
|
||||
fn verify_signed_data<T: Serialize>(&self, data: &WithSig<T>) -> Result<(), ApiError> {
|
||||
fn verify_signed_data<T: Serialize>(&self, data: &Signed<T>) -> Result<(), ApiError> {
|
||||
let Ok(()) = data.verify() else {
|
||||
return Err(error_response!(
|
||||
StatusCode::BAD_REQUEST,
|
||||
|
|
|
@ -6,7 +6,7 @@ use axum::extract::{FromRef, FromRequest, FromRequestParts, Request};
|
|||
use axum::http::{header, request, StatusCode};
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use axum::{async_trait, Json};
|
||||
use blah_types::{AuthPayload, UserKey, WithSig};
|
||||
use blah_types::{AuthPayload, Signed, UserKey};
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
@ -95,7 +95,7 @@ impl From<rusqlite::Error> for ApiError {
|
|||
|
||||
/// Extractor for verified JSON payload.
|
||||
#[derive(Debug)]
|
||||
pub struct SignedJson<T>(pub WithSig<T>);
|
||||
pub struct SignedJson<T>(pub Signed<T>);
|
||||
|
||||
#[async_trait]
|
||||
impl<S, T> FromRequest<S> for SignedJson<T>
|
||||
|
@ -107,7 +107,7 @@ where
|
|||
type Rejection = ApiError;
|
||||
|
||||
async fn from_request(req: Request, state: &S) -> Result<Self, Self::Rejection> {
|
||||
let Json(data) = <Json<WithSig<T>> as FromRequest<S>>::from_request(req, state).await?;
|
||||
let Json(data) = <Json<Signed<T>> as FromRequest<S>>::from_request(req, state).await?;
|
||||
let st = <Arc<AppState>>::from_ref(state);
|
||||
st.verify_signed_data(&data)?;
|
||||
Ok(Self(data))
|
||||
|
@ -178,7 +178,7 @@ where
|
|||
|
||||
let st = <Arc<AppState>>::from_ref(state);
|
||||
let data =
|
||||
serde_json::from_slice::<WithSig<AuthPayload>>(auth.as_bytes()).map_err(|err| {
|
||||
serde_json::from_slice::<Signed<AuthPayload>>(auth.as_bytes()).map_err(|err| {
|
||||
AuthRejection::Invalid(error_response!(
|
||||
StatusCode::BAD_REQUEST,
|
||||
"deserialization",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue