2020-05-21 21:24:56 +00:00
|
|
|
use activitystreams_ext::{Ext1, UnparsedExtension};
|
|
|
|
use activitystreams_new::{
|
|
|
|
activity::ActorAndObject,
|
|
|
|
actor::{Actor, ApActor},
|
|
|
|
unparsed::UnparsedMutExt,
|
2020-06-27 22:29:23 +00:00
|
|
|
url::Url,
|
2020-03-15 02:05:40 +00:00
|
|
|
};
|
|
|
|
|
2020-03-16 03:36:46 +00:00
|
|
|
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
2020-05-21 21:24:56 +00:00
|
|
|
pub struct PublicKeyInner {
|
2020-06-27 22:29:23 +00:00
|
|
|
pub id: Url,
|
|
|
|
pub owner: Url,
|
2020-03-16 03:36:46 +00:00
|
|
|
pub public_key_pem: String,
|
|
|
|
}
|
|
|
|
|
2020-03-19 01:57:39 +00:00
|
|
|
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
2020-05-21 21:24:56 +00:00
|
|
|
pub struct PublicKey {
|
|
|
|
pub public_key: PublicKeyInner,
|
2020-03-15 02:05:40 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 04:58:13 +00:00
|
|
|
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, serde::Deserialize, serde::Serialize)]
|
2020-03-15 02:05:40 +00:00
|
|
|
#[serde(rename_all = "PascalCase")]
|
|
|
|
pub enum ValidTypes {
|
2020-03-21 20:24:05 +00:00
|
|
|
Accept,
|
2020-03-15 02:05:40 +00:00
|
|
|
Announce,
|
|
|
|
Create,
|
|
|
|
Delete,
|
|
|
|
Follow,
|
2020-03-21 20:24:05 +00:00
|
|
|
Reject,
|
2020-03-15 02:05:40 +00:00
|
|
|
Undo,
|
2020-03-15 22:37:53 +00:00
|
|
|
Update,
|
2020-03-15 02:05:40 +00:00
|
|
|
}
|
|
|
|
|
2020-05-21 21:24:56 +00:00
|
|
|
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, serde::Deserialize, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "PascalCase")]
|
|
|
|
pub enum UndoTypes {
|
|
|
|
Follow,
|
|
|
|
Announce,
|
|
|
|
Create,
|
2020-03-19 01:57:39 +00:00
|
|
|
}
|
|
|
|
|
2020-05-21 21:24:56 +00:00
|
|
|
pub type AcceptedUndoObjects = ActorAndObject<UndoTypes>;
|
|
|
|
pub type AcceptedActivities = ActorAndObject<ValidTypes>;
|
|
|
|
pub type AcceptedActors = Ext1<ApActor<Actor<String>>, PublicKey>;
|
2020-03-19 01:57:39 +00:00
|
|
|
|
2020-05-21 21:24:56 +00:00
|
|
|
impl<U> UnparsedExtension<U> for PublicKey
|
|
|
|
where
|
|
|
|
U: UnparsedMutExt,
|
|
|
|
{
|
|
|
|
type Error = serde_json::Error;
|
2020-03-15 22:37:53 +00:00
|
|
|
|
2020-05-21 21:24:56 +00:00
|
|
|
fn try_from_unparsed(unparsed_mut: &mut U) -> Result<Self, Self::Error> {
|
|
|
|
Ok(PublicKey {
|
|
|
|
public_key: unparsed_mut.remove("publicKey")?,
|
|
|
|
})
|
2020-03-18 04:35:20 +00:00
|
|
|
}
|
|
|
|
|
2020-05-21 21:24:56 +00:00
|
|
|
fn try_into_unparsed(self, unparsed_mut: &mut U) -> Result<(), Self::Error> {
|
|
|
|
unparsed_mut.insert("publicKey", self.public_key)?;
|
|
|
|
Ok(())
|
2020-03-15 17:49:27 +00:00
|
|
|
}
|
|
|
|
}
|