parent
ae075b4f95
commit
b3dac33990
2 changed files with 21 additions and 12 deletions
|
|
@ -57,7 +57,7 @@ impl Keypair {
|
||||||
///
|
///
|
||||||
/// Note that this method is very slow in debug mode. To make it faster, follow
|
/// Note that this method is very slow in debug mode. To make it faster, follow
|
||||||
/// instructions in the RSA crate's readme.
|
/// instructions in the RSA crate's readme.
|
||||||
/// https://github.com/RustCrypto/RSA/blob/master/README.md
|
/// <https://github.com/RustCrypto/RSA/blob/master/README.md>
|
||||||
pub fn generate_actor_keypair() -> Result<Keypair, Error> {
|
pub fn generate_actor_keypair() -> Result<Keypair, Error> {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let rsa = RsaPrivateKey::new(&mut rng, 2048)?;
|
let rsa = RsaPrivateKey::new(&mut rng, 2048)?;
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,19 @@
|
||||||
|
use super::{Actor, Object};
|
||||||
use crate::{config::Data, error::Error};
|
use crate::{config::Data, error::Error};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use either::Either;
|
use either::Either;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::fmt::Debug;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use super::{Actor, Object};
|
#[doc(hidden)]
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
pub enum UntaggedEither<L, R> {
|
||||||
|
Left(L),
|
||||||
|
Right(R),
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<T, R, E, D> Object for Either<T, R>
|
impl<T, R, E, D> Object for Either<T, R>
|
||||||
|
|
@ -14,10 +23,10 @@ where
|
||||||
<T as Object>::Kind: Send + Sync,
|
<T as Object>::Kind: Send + Sync,
|
||||||
<R as Object>::Kind: Send + Sync,
|
<R as Object>::Kind: Send + Sync,
|
||||||
D: Sync + Send + Clone,
|
D: Sync + Send + Clone,
|
||||||
E: From<Error>,
|
E: From<Error> + Debug,
|
||||||
{
|
{
|
||||||
type DataType = D;
|
type DataType = D;
|
||||||
type Kind = Either<T::Kind, R::Kind>;
|
type Kind = UntaggedEither<T::Kind, R::Kind>;
|
||||||
type Error = E;
|
type Error = E;
|
||||||
|
|
||||||
fn last_refreshed_at(&self) -> Option<DateTime<Utc>> {
|
fn last_refreshed_at(&self) -> Option<DateTime<Utc>> {
|
||||||
|
|
@ -39,7 +48,7 @@ where
|
||||||
if let Some(r) = r {
|
if let Some(r) = r {
|
||||||
return Ok(Some(Either::Right(r)));
|
return Ok(Some(Either::Right(r)));
|
||||||
}
|
}
|
||||||
Err(Error::NotFound.into())
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete(self, data: &Data<Self::DataType>) -> Result<(), Self::Error> {
|
async fn delete(self, data: &Data<Self::DataType>) -> Result<(), Self::Error> {
|
||||||
|
|
@ -51,8 +60,8 @@ where
|
||||||
|
|
||||||
async fn into_json(self, data: &Data<Self::DataType>) -> Result<Self::Kind, Self::Error> {
|
async fn into_json(self, data: &Data<Self::DataType>) -> Result<Self::Kind, Self::Error> {
|
||||||
Ok(match self {
|
Ok(match self {
|
||||||
Either::Left(l) => Either::Left(l.into_json(data).await?),
|
Either::Left(l) => UntaggedEither::Left(l.into_json(data).await?),
|
||||||
Either::Right(r) => Either::Right(r.into_json(data).await?),
|
Either::Right(r) => UntaggedEither::Right(r.into_json(data).await?),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,16 +71,16 @@ where
|
||||||
data: &Data<Self::DataType>,
|
data: &Data<Self::DataType>,
|
||||||
) -> Result<(), Self::Error> {
|
) -> Result<(), Self::Error> {
|
||||||
match json {
|
match json {
|
||||||
Either::Left(l) => T::verify(l, expected_domain, data).await?,
|
UntaggedEither::Left(l) => T::verify(l, expected_domain, data).await?,
|
||||||
Either::Right(r) => R::verify(r, expected_domain, data).await?,
|
UntaggedEither::Right(r) => R::verify(r, expected_domain, data).await?,
|
||||||
};
|
};
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn from_json(json: Self::Kind, data: &Data<Self::DataType>) -> Result<Self, Self::Error> {
|
async fn from_json(json: Self::Kind, data: &Data<Self::DataType>) -> Result<Self, Self::Error> {
|
||||||
Ok(match json {
|
Ok(match json {
|
||||||
Either::Left(l) => Either::Left(T::from_json(l, data).await?),
|
UntaggedEither::Left(l) => Either::Left(T::from_json(l, data).await?),
|
||||||
Either::Right(r) => Either::Right(R::from_json(r, data).await?),
|
UntaggedEither::Right(r) => Either::Right(R::from_json(r, data).await?),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -84,7 +93,7 @@ where
|
||||||
<T as Object>::Kind: Send + Sync,
|
<T as Object>::Kind: Send + Sync,
|
||||||
<R as Object>::Kind: Send + Sync,
|
<R as Object>::Kind: Send + Sync,
|
||||||
D: Sync + Send + Clone,
|
D: Sync + Send + Clone,
|
||||||
E: From<Error>,
|
E: From<Error> + Debug,
|
||||||
{
|
{
|
||||||
fn id(&self) -> Url {
|
fn id(&self) -> Url {
|
||||||
match self {
|
match self {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue