From dacf1e622926c395a69595189ab9abc1f7ec7a01 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Sun, 8 Aug 2021 13:13:28 +0200 Subject: [PATCH] Limit type/method visibility in apub code --- crates/apub/src/extensions/context.rs | 2 +- crates/apub/src/extensions/signatures.rs | 2 +- crates/apub/src/fetcher/community.rs | 2 +- crates/apub/src/fetcher/mod.rs | 2 +- crates/apub/src/fetcher/objects.rs | 6 +++--- crates/apub/src/fetcher/person.rs | 2 +- crates/apub/src/lib.rs | 19 ++++++++----------- crates/apub/src/objects/mod.rs | 4 ++-- 8 files changed, 18 insertions(+), 21 deletions(-) diff --git a/crates/apub/src/extensions/context.rs b/crates/apub/src/extensions/context.rs index 1d6f83bd7..bc58052f0 100644 --- a/crates/apub/src/extensions/context.rs +++ b/crates/apub/src/extensions/context.rs @@ -2,7 +2,7 @@ use activitystreams::{base::AnyBase, context, primitives::OneOrMany}; use serde_json::json; use url::Url; -pub fn lemmy_context() -> OneOrMany { +pub(crate) fn lemmy_context() -> OneOrMany { let context_ext = AnyBase::from_arbitrary_json(json!( { "sc": "http://schema.org#", diff --git a/crates/apub/src/extensions/signatures.rs b/crates/apub/src/extensions/signatures.rs index 8fded5152..675740365 100644 --- a/crates/apub/src/extensions/signatures.rs +++ b/crates/apub/src/extensions/signatures.rs @@ -62,7 +62,7 @@ pub(crate) async fn sign_and_send( } /// Verifies the HTTP signature on an incoming inbox request. -pub fn verify_signature(request: &HttpRequest, public_key: &str) -> Result<(), LemmyError> { +pub(crate) fn verify_signature(request: &HttpRequest, public_key: &str) -> Result<(), LemmyError> { let verified = CONFIG2 .begin_verify( request.method(), diff --git a/crates/apub/src/fetcher/community.rs b/crates/apub/src/fetcher/community.rs index ff94129be..83aa7b51e 100644 --- a/crates/apub/src/fetcher/community.rs +++ b/crates/apub/src/fetcher/community.rs @@ -25,7 +25,7 @@ use url::Url; /// /// If it exists locally and `!should_refetch_actor()`, it is returned directly from the database. /// Otherwise it is fetched from the remote instance, stored and returned. -pub async fn get_or_fetch_and_upsert_community( +pub(crate) async fn get_or_fetch_and_upsert_community( apub_id: &Url, context: &LemmyContext, recursion_counter: &mut i32, diff --git a/crates/apub/src/fetcher/mod.rs b/crates/apub/src/fetcher/mod.rs index 477cecc87..9d9e2b8e3 100644 --- a/crates/apub/src/fetcher/mod.rs +++ b/crates/apub/src/fetcher/mod.rs @@ -42,7 +42,7 @@ where /// /// If it exists locally and `!should_refetch_actor()`, it is returned directly from the database. /// Otherwise it is fetched from the remote instance, stored and returned. -pub async fn get_or_fetch_and_upsert_actor( +pub(crate) async fn get_or_fetch_and_upsert_actor( apub_id: &Url, context: &LemmyContext, recursion_counter: &mut i32, diff --git a/crates/apub/src/fetcher/objects.rs b/crates/apub/src/fetcher/objects.rs index 835bf63a3..e538982db 100644 --- a/crates/apub/src/fetcher/objects.rs +++ b/crates/apub/src/fetcher/objects.rs @@ -17,7 +17,7 @@ use url::Url; /// pulled from its apub ID, inserted and returned. /// /// The parent community is also pulled if necessary. Comments are not pulled. -pub async fn get_or_fetch_and_insert_post( +pub(crate) async fn get_or_fetch_and_insert_post( post_ap_id: &Url, context: &LemmyContext, recursion_counter: &mut i32, @@ -46,7 +46,7 @@ pub async fn get_or_fetch_and_insert_post( /// pulled from its apub ID, inserted and returned. /// /// The parent community, post and comment are also pulled if necessary. -pub async fn get_or_fetch_and_insert_comment( +pub(crate) async fn get_or_fetch_and_insert_comment( comment_ap_id: &Url, context: &LemmyContext, recursion_counter: &mut i32, @@ -80,7 +80,7 @@ pub async fn get_or_fetch_and_insert_comment( } } -pub async fn get_or_fetch_and_insert_post_or_comment( +pub(crate) async fn get_or_fetch_and_insert_post_or_comment( ap_id: &Url, context: &LemmyContext, recursion_counter: &mut i32, diff --git a/crates/apub/src/fetcher/person.rs b/crates/apub/src/fetcher/person.rs index 3acedb086..ed3ca057f 100644 --- a/crates/apub/src/fetcher/person.rs +++ b/crates/apub/src/fetcher/person.rs @@ -16,7 +16,7 @@ use url::Url; /// /// If it exists locally and `!should_refetch_actor()`, it is returned directly from the database. /// Otherwise it is fetched from the remote instance, stored and returned. -pub async fn get_or_fetch_and_upsert_person( +pub(crate) async fn get_or_fetch_and_upsert_person( apub_id: &Url, context: &LemmyContext, recursion_counter: &mut i32, diff --git a/crates/apub/src/lib.rs b/crates/apub/src/lib.rs index 950f11dc4..5bbf8bb55 100644 --- a/crates/apub/src/lib.rs +++ b/crates/apub/src/lib.rs @@ -34,7 +34,7 @@ use serde::Serialize; use std::net::IpAddr; use url::{ParseError, Url}; -pub static APUB_JSON_CONTENT_TYPE: &str = "application/activity+json"; +static APUB_JSON_CONTENT_TYPE: &str = "application/activity+json"; /// Checks if the ID is allowed for sending or receiving. /// @@ -123,7 +123,7 @@ pub trait ApubObjectType { /// Common methods provided by ActivityPub actors (community and person). Not all methods are /// implemented by all actors. -pub trait ActorType { +trait ActorType { fn is_local(&self) -> bool; fn actor_id(&self) -> Url; fn name(&self) -> String; @@ -209,7 +209,7 @@ pub enum EndpointType { } /// Generates an apub endpoint for a given domain, IE xyz.tld -pub(crate) fn generate_apub_endpoint_for_domain( +fn generate_apub_endpoint_for_domain( endpoint_type: EndpointType, name: &str, domain: &str, @@ -260,7 +260,7 @@ pub fn generate_shared_inbox_url(actor_id: &DbUrl) -> Result Ok(Url::parse(&url)?.into()) } -pub fn generate_moderators_url(community_id: &DbUrl) -> Result { +fn generate_moderators_url(community_id: &DbUrl) -> Result { Ok(Url::parse(&format!("{}/moderators", community_id))?.into()) } @@ -286,7 +286,7 @@ pub fn build_actor_id_from_shortname( /// Store a sent or received activity in the database, for logging purposes. These records are not /// persistent. -pub(crate) async fn insert_activity( +async fn insert_activity( ap_id: &Url, activity: T, local: bool, @@ -348,7 +348,7 @@ pub(crate) async fn find_post_or_comment_by_id( } #[derive(Debug)] -pub enum Object { +enum Object { Comment(Box), Post(Box), Community(Box), @@ -356,10 +356,7 @@ pub enum Object { PrivateMessage(Box), } -pub(crate) async fn find_object_by_id( - context: &LemmyContext, - apub_id: Url, -) -> Result { +async fn find_object_by_id(context: &LemmyContext, apub_id: Url) -> Result { let ap_id = apub_id.clone(); if let Ok(pc) = find_post_or_comment_by_id(context, ap_id.to_owned()).await { return Ok(match pc { @@ -397,7 +394,7 @@ pub(crate) async fn find_object_by_id( Err(NotFound.into()) } -pub(crate) async fn check_community_or_site_ban( +async fn check_community_or_site_ban( person: &Person, community_id: CommunityId, pool: &DbPool, diff --git a/crates/apub/src/objects/mod.rs b/crates/apub/src/objects/mod.rs index 2114a1d89..33a93915a 100644 --- a/crates/apub/src/objects/mod.rs +++ b/crates/apub/src/objects/mod.rs @@ -19,14 +19,14 @@ pub(crate) mod private_message; /// Trait for converting an object or actor into the respective ActivityPub type. #[async_trait::async_trait(?Send)] -pub trait ToApub { +pub(crate) trait ToApub { type ApubType; async fn to_apub(&self, pool: &DbPool) -> Result; fn to_tombstone(&self) -> Result; } #[async_trait::async_trait(?Send)] -pub trait FromApub { +pub(crate) trait FromApub { type ApubType; /// Converts an object from ActivityPub type to Lemmy internal type. ///