2020-09-07 21:51:02 +00:00
|
|
|
use activitystreams::{
|
2020-05-21 21:24:56 +00:00
|
|
|
activity::ActorAndObject,
|
|
|
|
actor::{Actor, ApActor},
|
2022-01-17 22:54:45 +00:00
|
|
|
iri_string::types::IriString,
|
2022-11-02 18:55:45 +00:00
|
|
|
unparsed::UnparsedMutExt,
|
2020-03-15 02:05:40 +00:00
|
|
|
};
|
2021-09-21 19:32:25 +00:00
|
|
|
use activitystreams_ext::{Ext1, UnparsedExtension};
|
2020-03-15 02:05:40 +00:00
|
|
|
|
2021-09-21 19:32:25 +00:00
|
|
|
#[derive(Clone, serde::Deserialize, serde::Serialize)]
|
2020-03-16 03:36:46 +00:00
|
|
|
#[serde(rename_all = "camelCase")]
|
2020-05-21 21:24:56 +00:00
|
|
|
pub struct PublicKeyInner {
|
2022-01-17 22:54:45 +00:00
|
|
|
pub id: IriString,
|
|
|
|
pub owner: IriString,
|
2020-03-16 03:36:46 +00:00
|
|
|
pub public_key_pem: String,
|
|
|
|
}
|
|
|
|
|
2021-09-21 19:32:25 +00:00
|
|
|
impl std::fmt::Debug for PublicKeyInner {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
f.debug_struct("PublicKeyInner")
|
|
|
|
.field("id", &self.id.to_string())
|
|
|
|
.field("owner", &self.owner.to_string())
|
|
|
|
.field("public_key_pem", &self.public_key_pem)
|
|
|
|
.finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|