From 6611debd6bb678db415cf6e2f5ab1516cc38da88 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Mon, 16 Jan 2023 22:54:23 +0100 Subject: [PATCH] Remove verify methods (fixes #15) (#21) --- .../federation-actix/activities/accept.rs | 8 ------ .../activities/create_note.rs | 9 ------- .../federation-actix/activities/follow.rs | 8 ------ examples/federation-actix/objects/note.rs | 9 ------- examples/federation-actix/objects/person.rs | 9 ------- examples/federation-axum/activities/accept.rs | 8 ------ .../federation-axum/activities/create_note.rs | 9 ------- examples/federation-axum/activities/follow.rs | 8 ------ examples/federation-axum/objects/note.rs | 9 ------- examples/federation-axum/objects/person.rs | 9 ------- src/core/actix/inbox.rs | 3 --- src/core/axum/inbox.rs | 3 --- src/core/object_id.rs | 10 ------- src/deser/context.rs | 8 ------ src/traits.rs | 27 ------------------- 15 files changed, 137 deletions(-) diff --git a/examples/federation-actix/activities/accept.rs b/examples/federation-actix/activities/accept.rs index 1022685..a08048f 100644 --- a/examples/federation-actix/activities/accept.rs +++ b/examples/federation-actix/activities/accept.rs @@ -38,14 +38,6 @@ impl ActivityHandler for Accept { self.actor.inner() } - async fn verify( - &self, - _data: &Data, - _request_counter: &mut i32, - ) -> Result<(), Self::Error> { - Ok(()) - } - async fn receive( self, _data: &Data, diff --git a/examples/federation-actix/activities/create_note.rs b/examples/federation-actix/activities/create_note.rs index 3d28878..7ec2060 100644 --- a/examples/federation-actix/activities/create_note.rs +++ b/examples/federation-actix/activities/create_note.rs @@ -50,15 +50,6 @@ impl ActivityHandler for CreateNote { self.actor.inner() } - async fn verify( - &self, - data: &Data, - request_counter: &mut i32, - ) -> Result<(), Self::Error> { - MyPost::verify(&self.object, self.id(), data, request_counter).await?; - Ok(()) - } - async fn receive( self, data: &Data, diff --git a/examples/federation-actix/activities/follow.rs b/examples/federation-actix/activities/follow.rs index 0cc58f2..73a7f92 100644 --- a/examples/federation-actix/activities/follow.rs +++ b/examples/federation-actix/activities/follow.rs @@ -47,14 +47,6 @@ impl ActivityHandler for Follow { self.actor.inner() } - async fn verify( - &self, - _data: &Data, - _request_counter: &mut i32, - ) -> Result<(), Self::Error> { - Ok(()) - } - // Ignore clippy false positive: https://github.com/rust-lang/rust-clippy/issues/6446 #[allow(clippy::await_holding_lock)] async fn receive( diff --git a/examples/federation-actix/objects/note.rs b/examples/federation-actix/objects/note.rs index d59b1c4..d6b58d6 100644 --- a/examples/federation-actix/objects/note.rs +++ b/examples/federation-actix/objects/note.rs @@ -64,15 +64,6 @@ impl ApubObject for MyPost { }) } - async fn verify( - _apub: &Self::ApubType, - _expected_domain: &Url, - _data: &Self::DataType, - _request_counter: &mut i32, - ) -> Result<(), Self::Error> { - Ok(()) - } - async fn from_apub( apub: Self::ApubType, data: &Self::DataType, diff --git a/examples/federation-actix/objects/person.rs b/examples/federation-actix/objects/person.rs index 9b7d19c..311d4fa 100644 --- a/examples/federation-actix/objects/person.rs +++ b/examples/federation-actix/objects/person.rs @@ -159,15 +159,6 @@ impl ApubObject for MyUser { }) } - async fn verify( - _apub: &Self::ApubType, - _expected_domain: &Url, - _data: &Self::DataType, - _request_counter: &mut i32, - ) -> Result<(), Self::Error> { - Ok(()) - } - async fn from_apub( apub: Self::ApubType, _data: &Self::DataType, diff --git a/examples/federation-axum/activities/accept.rs b/examples/federation-axum/activities/accept.rs index 1022685..a08048f 100644 --- a/examples/federation-axum/activities/accept.rs +++ b/examples/federation-axum/activities/accept.rs @@ -38,14 +38,6 @@ impl ActivityHandler for Accept { self.actor.inner() } - async fn verify( - &self, - _data: &Data, - _request_counter: &mut i32, - ) -> Result<(), Self::Error> { - Ok(()) - } - async fn receive( self, _data: &Data, diff --git a/examples/federation-axum/activities/create_note.rs b/examples/federation-axum/activities/create_note.rs index 3d28878..7ec2060 100644 --- a/examples/federation-axum/activities/create_note.rs +++ b/examples/federation-axum/activities/create_note.rs @@ -50,15 +50,6 @@ impl ActivityHandler for CreateNote { self.actor.inner() } - async fn verify( - &self, - data: &Data, - request_counter: &mut i32, - ) -> Result<(), Self::Error> { - MyPost::verify(&self.object, self.id(), data, request_counter).await?; - Ok(()) - } - async fn receive( self, data: &Data, diff --git a/examples/federation-axum/activities/follow.rs b/examples/federation-axum/activities/follow.rs index 0cc58f2..73a7f92 100644 --- a/examples/federation-axum/activities/follow.rs +++ b/examples/federation-axum/activities/follow.rs @@ -47,14 +47,6 @@ impl ActivityHandler for Follow { self.actor.inner() } - async fn verify( - &self, - _data: &Data, - _request_counter: &mut i32, - ) -> Result<(), Self::Error> { - Ok(()) - } - // Ignore clippy false positive: https://github.com/rust-lang/rust-clippy/issues/6446 #[allow(clippy::await_holding_lock)] async fn receive( diff --git a/examples/federation-axum/objects/note.rs b/examples/federation-axum/objects/note.rs index d59b1c4..d6b58d6 100644 --- a/examples/federation-axum/objects/note.rs +++ b/examples/federation-axum/objects/note.rs @@ -64,15 +64,6 @@ impl ApubObject for MyPost { }) } - async fn verify( - _apub: &Self::ApubType, - _expected_domain: &Url, - _data: &Self::DataType, - _request_counter: &mut i32, - ) -> Result<(), Self::Error> { - Ok(()) - } - async fn from_apub( apub: Self::ApubType, data: &Self::DataType, diff --git a/examples/federation-axum/objects/person.rs b/examples/federation-axum/objects/person.rs index 9b7d19c..311d4fa 100644 --- a/examples/federation-axum/objects/person.rs +++ b/examples/federation-axum/objects/person.rs @@ -159,15 +159,6 @@ impl ApubObject for MyUser { }) } - async fn verify( - _apub: &Self::ApubType, - _expected_domain: &Url, - _data: &Self::DataType, - _request_counter: &mut i32, - ) -> Result<(), Self::Error> { - Ok(()) - } - async fn from_apub( apub: Self::ApubType, _data: &Self::DataType, diff --git a/src/core/actix/inbox.rs b/src/core/actix/inbox.rs index 6848723..185fbe1 100644 --- a/src/core/actix/inbox.rs +++ b/src/core/actix/inbox.rs @@ -42,9 +42,6 @@ where actor.public_key(), )?; - debug!("Verifying activity {}", activity.id().to_string()); - activity.verify(data, request_counter).await?; - debug!("Receiving activity {}", activity.id().to_string()); activity.receive(data, request_counter).await?; Ok(HttpResponse::Ok().finish()) diff --git a/src/core/axum/inbox.rs b/src/core/axum/inbox.rs index 70b0b6c..da08cf8 100644 --- a/src/core/axum/inbox.rs +++ b/src/core/axum/inbox.rs @@ -38,9 +38,6 @@ where verify_signature(&headers, &method, &uri, actor.public_key())?; - debug!("Verifying activity {}", activity.id().to_string()); - activity.verify(data, request_counter).await?; - debug!("Receiving activity {}", activity.id().to_string()); activity.receive(data, request_counter).await?; Ok(()) diff --git a/src/core/object_id.rs b/src/core/object_id.rs index 7bd9c61..5b74e31 100644 --- a/src/core/object_id.rs +++ b/src/core/object_id.rs @@ -118,7 +118,6 @@ where let res2 = res?; - Kind::verify(&res2, self.inner(), data, request_counter).await?; Kind::from_apub(res2, data, request_counter).await } } @@ -216,15 +215,6 @@ mod tests { todo!() } - async fn verify( - _apub: &Self::ApubType, - _expected_domain: &Url, - _data: &Self::DataType, - _request_counter: &mut i32, - ) -> Result<(), Self::Error> { - todo!() - } - async fn from_apub( _apub: Self::ApubType, _data: &Self::DataType, diff --git a/src/deser/context.rs b/src/deser/context.rs index d5ca763..c9fa38b 100644 --- a/src/deser/context.rs +++ b/src/deser/context.rs @@ -44,14 +44,6 @@ where self.inner.actor() } - async fn verify( - &self, - data: &Data, - request_counter: &mut i32, - ) -> Result<(), Self::Error> { - self.inner.verify(data, request_counter).await - } - async fn receive( self, data: &Data, diff --git a/src/traits.rs b/src/traits.rs index ad7c85b..7a21bba 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -16,15 +16,6 @@ pub trait ActivityHandler { /// `actor` field of activity fn actor(&self) -> &Url; - /// Verify that the activity is valid. If this method returns an error, the activity will be - /// discarded. This is separate from receive(), so that it can be called recursively on nested - /// objects, without storing something in the database by accident. - async fn verify( - &self, - data: &Data, - request_counter: &mut i32, - ) -> Result<(), Self::Error>; - /// Receives the activity and stores its action in database. async fn receive( self, @@ -50,14 +41,6 @@ where self.deref().actor() } - async fn verify( - &self, - data: &Data, - request_counter: &mut i32, - ) -> Result<(), Self::Error> { - self.deref().verify(data, request_counter).await - } - async fn receive( self, data: &Data, @@ -100,16 +83,6 @@ pub trait ApubObject { /// Trait for converting an object or actor into the respective ActivityPub type. async fn into_apub(self, data: &Self::DataType) -> Result; - /// Verify that the object is valid. If this method returns an error, it will be - /// discarded. This is separate from from_apub(), so that it can be called recursively on nested - /// objects, without storing something in the database by accident. - async fn verify( - apub: &Self::ApubType, - expected_domain: &Url, - data: &Self::DataType, - request_counter: &mut i32, - ) -> Result<(), Self::Error>; - /// Converts an object from ActivityPub type to Lemmy internal type. /// /// * `apub` The object to read from