-use activitystreams::unparsed::UnparsedMutExt;
-use activitystreams_ext::UnparsedExtension;
use actix_web::HttpRequest;
use anyhow::anyhow;
use http::{header::HeaderName, HeaderMap, HeaderValue};
}
}
-/// Extension for actor public key, which is needed on person and community for HTTP signatures.
-///
-/// Taken from: https://docs.rs/activitystreams/0.5.0-alpha.17/activitystreams/ext/index.html
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct PublicKeyExtension {
- pub public_key: PublicKey,
-}
-
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PublicKey {
pub owner: Url,
pub public_key_pem: String,
}
-
-impl PublicKey {
- pub fn to_ext(&self) -> PublicKeyExtension {
- PublicKeyExtension {
- public_key: self.to_owned(),
- }
- }
-}
-
-impl<U> UnparsedExtension<U> for PublicKeyExtension
-where
- U: UnparsedMutExt,
-{
- type Error = serde_json::Error;
-
- fn try_from_unparsed(unparsed_mut: &mut U) -> Result<Self, Self::Error> {
- Ok(PublicKeyExtension {
- public_key: unparsed_mut.remove("publicKey")?,
- })
- }
-
- fn try_into_unparsed(self, unparsed_mut: &mut U) -> Result<(), Self::Error> {
- unparsed_mut.insert("publicKey", self.public_key)?;
- Ok(())
- }
-}