diff --git a/Cargo.lock b/Cargo.lock index 023ca92..db8d244 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,9 +2,8 @@ # It is not intended for manual editing. [[package]] name = "activitystreams" -version = "0.5.0-alpha.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78489a7b8d92f8c23f3dc1b69da158c0a4ca02edf0f4007955fafbca667275dd" +version = "0.5.0-alpha.9" +source = "git+https://git.asonix.dog/Aardwolf/activitystreams?branch=asonix/try-extensions#3258d7e0a7032d9959ad5d2ee05206be8e5a91af" dependencies = [ "activitystreams-derive", "chrono", @@ -17,9 +16,8 @@ dependencies = [ [[package]] name = "activitystreams-derive" -version = "0.5.0-alpha.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f95c948a832a0b7b230b28369bafe79477bb8ebe7306dc97bcaff43832d3cc4d" +version = "0.5.0-alpha.4" +source = "git+https://git.asonix.dog/Aardwolf/activitystreams?branch=asonix/try-extensions#3258d7e0a7032d9959ad5d2ee05206be8e5a91af" dependencies = [ "proc-macro2", "quote", @@ -403,9 +401,9 @@ dependencies = [ [[package]] name = "arc-swap" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7b8a9123b8027467bce0099fe556c628a53c8d83df0507084c31e9ba2e39aff" +checksum = "d663a8e9a99154b5fb793032533f6328da35e23aac63d5c152279aa8ba356825" [[package]] name = "async-trait" @@ -1800,18 +1798,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.104" +version = "1.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" +checksum = "e707fbbf255b8fc8c3b99abb91e7257a622caeb20a9818cbadbeeede4e0932ff" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.104" +version = "1.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64" +checksum = "ac5d00fc561ba2724df6758a17de23df5914f20e41cb00f94d5b7ae42fffaff8" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 802ecb6..df1f398 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ actix = "0.10.0-alpha.2" actix-rt = "1.0.0" actix-web = { version = "3.0.0-alpha.1", features = ["rustls"] } actix-webfinger = { version = "0.3.0-alpha.3" } -activitystreams = "0.5.0-alpha.8" +activitystreams = { version = "0.5.0-alpha.9", git = "https://git.asonix.dog/Aardwolf/activitystreams", branch = "asonix/try-extensions" } base64 = "0.12" bb8-postgres = "0.4.0" dotenv = "0.15.0" diff --git a/src/apub.rs b/src/apub.rs index f34eb69..4acdd53 100644 --- a/src/apub.rs +++ b/src/apub.rs @@ -1,7 +1,9 @@ use activitystreams::{ + actor::Actor, + ext::Extension, object::{Object, ObjectBox}, primitives::XsdAnyUri, - PropRefs, + Base, BaseBox, PropRefs, }; use std::collections::HashMap; @@ -13,16 +15,9 @@ pub struct PublicKey { pub public_key_pem: String, } -#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] -#[serde(rename_all = "camelCase")] -pub struct PublicKeyExtension { - public_key: PublicKey, +impl Extension for PublicKey where T: Actor {} - #[serde(flatten)] - extending: T, -} - -#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PropRefs)] +#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize, PropRefs)] #[serde(rename_all = "camelCase")] #[prop_refs(Object)] pub struct AnyExistingObject { @@ -91,15 +86,6 @@ pub struct Endpoints { shared_inbox: Option, } -impl PublicKey { - pub fn extend(self, extending: T) -> PublicKeyExtension { - PublicKeyExtension { - public_key: self, - extending, - } - } -} - impl ValidObjects { pub fn id(&self) -> &XsdAnyUri { match self { diff --git a/src/inbox.rs b/src/inbox.rs index 3df464d..49c964e 100644 --- a/src/inbox.rs +++ b/src/inbox.rs @@ -7,10 +7,11 @@ use crate::{ state::{State, UrlKind}, }; use activitystreams::{ - activity::apub::{Accept, Announce, Follow, Undo}, + activity::{Accept, Announce, Follow, Undo}, context, object::properties::ObjectProperties, primitives::XsdAnyUri, + public, security, }; use actix_web::{web, HttpResponse}; use futures::join; @@ -18,12 +19,6 @@ use http_signature_normalization_actix::middleware::SignatureVerified; use log::error; use std::convert::TryInto; -fn public() -> XsdAnyUri { - "https://www.w3.org/ns/activitystreams#Public" - .parse() - .unwrap() -} - pub async fn inbox( db: web::Data, state: web::Data, @@ -203,7 +198,7 @@ fn generate_undo_follow( undo.undo_props .set_actor_xsd_any_uri(my_id.clone())? - .set_object_object_box({ + .set_object_base_box({ let mut follow = Follow::default(); follow @@ -272,7 +267,7 @@ fn generate_accept_follow( accept .accept_props .set_actor_xsd_any_uri(my_id.clone())? - .set_object_object_box({ + .set_object_base_box({ let mut follow = Follow::default(); follow.object_props.set_id(input_id.clone())?; @@ -303,7 +298,7 @@ where t.as_mut() .set_id(id.try_into()?)? .set_many_to_xsd_any_uris(vec![to.try_into()?])? - .set_context_xsd_any_uri(context())?; + .set_many_context_xsd_any_uris(vec![context(), security()])?; Ok(t) } diff --git a/src/main.rs b/src/main.rs index 6b5e7d7..975d262 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,7 @@ -use activitystreams::{actor::apub::Application, context, endpoint::EndpointProperties}; +use activitystreams::{ + actor::Application, context, endpoint::EndpointProperties, ext::Extensible, + object::properties::ObjectProperties, +}; use actix_web::{middleware::Logger, web, App, HttpResponse, HttpServer, Responder}; use bb8_postgres::tokio_postgres; use http_signature_normalization_actix::prelude::{VerifyDigest, VerifySignature}; @@ -50,13 +53,13 @@ async fn index() -> impl Responder { } async fn actor_route(state: web::Data) -> Result { - let mut application = Application::default(); + let mut application = Application::full(); let mut endpoint = EndpointProperties::default(); endpoint.set_shared_inbox(state.generate_url(UrlKind::Inbox))?; - application - .object_props + let props: &mut ObjectProperties = application.as_mut(); + props .set_id(state.generate_url(UrlKind::Actor))? .set_summary_xsd_string("AodeRelay bot")? .set_name_xsd_string("AodeRelay")? @@ -64,7 +67,7 @@ async fn actor_route(state: web::Data) -> Result .set_context_xsd_any_uri(context())?; application - .ap_actor_props + .extension .set_preferred_username("relay")? .set_followers(state.generate_url(UrlKind::Followers))? .set_following(state.generate_url(UrlKind::Following))? @@ -78,7 +81,7 @@ async fn actor_route(state: web::Data) -> Result public_key_pem: state.settings.public_key.to_pem_pkcs8()?, }; - Ok(ok(public_key.extend(application))) + Ok(ok(application.extend(public_key))) } #[actix_rt::main]