From e2c3e62d1c54c8a38b4bb47faa353ae023aa5c44 Mon Sep 17 00:00:00 2001 From: Philipp Gackstatter Date: Fri, 30 Jun 2023 08:25:27 +0200 Subject: [PATCH] Remove identity-diff remains --- identity_core/src/common/one_or_set.rs | 33 - identity_core/src/common/ordered_set.rs | 33 - identity_core/src/common/timestamp.rs | 57 -- identity_core/src/common/url.rs | 30 - identity_core/src/error.rs | 5 - identity_core/src/lib.rs | 5 - identity_did/src/did.rs | 29 - identity_did/src/did_url.rs | 29 - identity_document/src/diff/diff_document.rs | 819 ------------------ identity_document/src/diff/diff_service.rs | 406 --------- identity_document/src/diff/mod.rs | 11 - identity_document/src/document/mod.rs | 2 - identity_document/src/lib.rs | 4 - .../src/verifiable/properties.rs | 36 - identity_iota/src/lib.rs | 5 - identity_jose/src/jwk/diff/key.rs | 155 ---- identity_jose/src/jwk/diff/key_operations.rs | 38 - identity_jose/src/jwk/diff/key_params/ec.rs | 100 --- identity_jose/src/jwk/diff/key_params/mod.rs | 92 -- identity_jose/src/jwk/diff/key_params/oct.rs | 60 -- identity_jose/src/jwk/diff/key_params/okp.rs | 92 -- identity_jose/src/jwk/diff/key_params/rsa.rs | 109 --- identity_jose/src/jwk/diff/key_type.rs | 38 - identity_jose/src/jwk/diff/key_use.rs | 38 - identity_jose/src/jwk/diff/mod.rs | 16 - identity_jose/src/jwk/mod.rs | 3 - .../verification_method/diff/diff_method.rs | 399 --------- .../verification_method/diff/method_data.rs | 75 -- .../verification_method/diff/method_ref.rs | 60 -- .../verification_method/diff/method_type.rs | 27 - .../src/verification_method/diff/mod.rs | 11 - .../src/verification_method/mod.rs | 3 - 32 files changed, 2820 deletions(-) delete mode 100644 identity_document/src/diff/diff_document.rs delete mode 100644 identity_document/src/diff/diff_service.rs delete mode 100644 identity_document/src/diff/mod.rs delete mode 100644 identity_jose/src/jwk/diff/key.rs delete mode 100644 identity_jose/src/jwk/diff/key_operations.rs delete mode 100644 identity_jose/src/jwk/diff/key_params/ec.rs delete mode 100644 identity_jose/src/jwk/diff/key_params/mod.rs delete mode 100644 identity_jose/src/jwk/diff/key_params/oct.rs delete mode 100644 identity_jose/src/jwk/diff/key_params/okp.rs delete mode 100644 identity_jose/src/jwk/diff/key_params/rsa.rs delete mode 100644 identity_jose/src/jwk/diff/key_type.rs delete mode 100644 identity_jose/src/jwk/diff/key_use.rs delete mode 100644 identity_jose/src/jwk/diff/mod.rs delete mode 100644 identity_verification/src/verification_method/diff/diff_method.rs delete mode 100644 identity_verification/src/verification_method/diff/method_data.rs delete mode 100644 identity_verification/src/verification_method/diff/method_ref.rs delete mode 100644 identity_verification/src/verification_method/diff/method_type.rs delete mode 100644 identity_verification/src/verification_method/diff/mod.rs diff --git a/identity_core/src/common/one_or_set.rs b/identity_core/src/common/one_or_set.rs index 341c92cbc1..6333e642de 100644 --- a/identity_core/src/common/one_or_set.rs +++ b/identity_core/src/common/one_or_set.rs @@ -316,39 +316,6 @@ where } } -#[cfg(feature = "diff")] -mod diff { - use super::*; - use identity_diff::Diff; - use identity_diff::DiffVec; - impl Diff for OneOrSet - where - T: Diff + KeyComparable + Serialize + for<'de> Deserialize<'de>, - { - type Type = DiffVec; - - fn diff(&self, other: &Self) -> identity_diff::Result { - self.clone().into_vec().diff(&other.clone().into_vec()) - } - - fn merge(&self, diff: Self::Type) -> identity_diff::Result { - self - .clone() - .into_vec() - .merge(diff) - .and_then(|this| Self::try_from(this).map_err(identity_diff::Error::merge)) - } - - fn from_diff(diff: Self::Type) -> identity_diff::Result { - Vec::from_diff(diff).and_then(|this| Self::try_from(this).map_err(identity_diff::Error::convert)) - } - - fn into_diff(self) -> identity_diff::Result { - self.into_vec().into_diff() - } - } -} - #[cfg(test)] mod tests { use crate::convert::FromJson; diff --git a/identity_core/src/common/ordered_set.rs b/identity_core/src/common/ordered_set.rs index b5c2597a4c..b3650490ef 100644 --- a/identity_core/src/common/ordered_set.rs +++ b/identity_core/src/common/ordered_set.rs @@ -285,39 +285,6 @@ where } } -#[cfg(feature = "diff")] -mod diff { - use super::*; - use identity_diff::Diff; - use identity_diff::DiffVec; - impl Diff for OrderedSet - where - T: Diff + KeyComparable + Serialize + for<'de> Deserialize<'de>, - { - type Type = DiffVec; - - fn diff(&self, other: &Self) -> identity_diff::Result { - self.clone().into_vec().diff(&other.clone().into_vec()) - } - - fn merge(&self, diff: Self::Type) -> identity_diff::Result { - self - .clone() - .into_vec() - .merge(diff) - .and_then(|this| Self::try_from(this).map_err(identity_diff::Error::merge)) - } - - fn from_diff(diff: Self::Type) -> identity_diff::Result { - Vec::from_diff(diff).and_then(|this| Self::try_from(this).map_err(identity_diff::Error::convert)) - } - - fn into_diff(self) -> identity_diff::Result { - self.into_vec().into_diff() - } - } -} - #[cfg(test)] mod tests { use std::collections::HashSet; diff --git a/identity_core/src/common/timestamp.rs b/identity_core/src/common/timestamp.rs index 84dc6be6ab..3dd287b46b 100644 --- a/identity_core/src/common/timestamp.rs +++ b/identity_core/src/common/timestamp.rs @@ -175,38 +175,6 @@ fn truncate_fractional_seconds(offset_date_time: OffsetDateTime) -> OffsetDateTi offset_date_time - time::Duration::nanoseconds(offset_date_time.nanosecond() as i64) } -#[cfg(feature = "diff")] -mod diff { - use super::*; - use identity_diff::Diff; - use identity_diff::DiffString; - - use crate::diff; - - impl Diff for Timestamp { - type Type = DiffString; - - fn diff(&self, other: &Self) -> diff::Result { - self.to_string().diff(&other.to_string()) - } - - fn merge(&self, diff: Self::Type) -> diff::Result { - self - .to_string() - .merge(diff) - .and_then(|this| Self::parse(&this).map_err(diff::Error::merge)) - } - - fn from_diff(diff: Self::Type) -> diff::Result { - String::from_diff(diff).and_then(|this| Self::parse(&this).map_err(diff::Error::convert)) - } - - fn into_diff(self) -> diff::Result { - self.to_string().into_diff() - } - } -} - /// A span of time. /// /// This type is typically used to increment or decrement a [`Timestamp`]. @@ -395,29 +363,4 @@ mod tests { assert_eq!(time1, time2); } - - #[cfg(feature = "diff")] - #[test] - fn test_timestamp_diff() { - use identity_diff::Diff; - use identity_diff::DiffString; - let time1: Timestamp = Timestamp::parse("2021-01-01T12:00:01Z").unwrap(); - let time2: Timestamp = Timestamp::parse("2022-01-02T12:00:02Z").unwrap(); - - // Diff - let non_diff: DiffString = time1.diff(&time1).unwrap(); - assert!(non_diff.0.is_none()); - let diff12: DiffString = time1.diff(&time2).unwrap(); - assert_eq!(String::from_diff(diff12.clone()).unwrap(), time2.to_string()); - let diff21: DiffString = time2.diff(&time1).unwrap(); - assert_eq!(String::from_diff(diff21.clone()).unwrap(), time1.to_string()); - - // Merge - assert_eq!(time1.merge(non_diff.clone()).unwrap(), time1); - assert_eq!(time2.merge(non_diff).unwrap(), time2); - assert_eq!(time1.merge(diff12.clone()).unwrap(), time2); - assert_eq!(time1.merge(diff21.clone()).unwrap(), time1); - assert_eq!(time2.merge(diff12).unwrap(), time2); - assert_eq!(time2.merge(diff21).unwrap(), time1); - } } diff --git a/identity_core/src/common/url.rs b/identity_core/src/common/url.rs index 65eafdcc8a..914d3bf2fc 100644 --- a/identity_core/src/common/url.rs +++ b/identity_core/src/common/url.rs @@ -88,36 +88,6 @@ where } } -#[cfg(feature = "diff")] -mod diff { - use super::*; - use crate::diff; - use crate::diff::Diff; - use crate::diff::DiffString; - impl Diff for Url { - type Type = DiffString; - - fn diff(&self, other: &Self) -> diff::Result { - self.to_string().diff(&other.to_string()) - } - - fn merge(&self, diff: Self::Type) -> diff::Result { - self - .to_string() - .merge(diff) - .and_then(|this| Self::parse(this).map_err(diff::Error::merge)) - } - - fn from_diff(diff: Self::Type) -> diff::Result { - String::from_diff(diff).and_then(|this| Self::parse(this).map_err(diff::Error::convert)) - } - - fn into_diff(self) -> diff::Result { - self.to_string().into_diff() - } - } -} - impl KeyComparable for Url { type Key = Url; diff --git a/identity_core/src/error.rs b/identity_core/src/error.rs index 51f9621e73..87faabd59b 100644 --- a/identity_core/src/error.rs +++ b/identity_core/src/error.rs @@ -27,11 +27,6 @@ pub enum Error { /// Caused by a failure to decode multibase-encoded data. #[error("failed to decode multibase data")] DecodeMultibase(#[from] multibase::Error), - #[cfg(feature = "diff")] - /// Caused by attempting to perform an invalid `Diff` operation. - #[deprecated(since = "0.5.0", note = "diff chain features are slated for removal")] - #[error("invalid document diff")] - InvalidDiff(#[from] identity_diff::Error), /// Caused by attempting to parse an invalid `Url`. #[error("invalid url")] InvalidUrl(#[from] url::ParseError), diff --git a/identity_core/src/lib.rs b/identity_core/src/lib.rs index 23d379e4e6..901eedb2dd 100644 --- a/identity_core/src/lib.rs +++ b/identity_core/src/lib.rs @@ -20,11 +20,6 @@ #[doc(inline)] pub use serde_json::json; -#[cfg(feature = "diff")] -#[deprecated(since = "0.5.0", note = "diff chain features are slated for removal")] -#[doc(inline)] -pub use identity_diff as diff; - pub mod common; pub mod convert; pub mod crypto; diff --git a/identity_did/src/did.rs b/identity_did/src/did.rs index 1104fedb6b..eb07f61a08 100644 --- a/identity_did/src/did.rs +++ b/identity_did/src/did.rs @@ -237,35 +237,6 @@ impl From for String { } } -#[cfg(feature = "diff")] -mod diff { - use super::*; - use identity_core::diff::Diff; - use identity_core::diff::DiffString; - impl Diff for CoreDID { - type Type = DiffString; - - fn diff(&self, other: &Self) -> identity_core::diff::Result { - self.to_string().diff(&other.to_string()) - } - - fn merge(&self, diff: Self::Type) -> identity_core::diff::Result { - self - .to_string() - .merge(diff) - .and_then(|this| Self::parse(this).map_err(identity_core::diff::Error::merge)) - } - - fn from_diff(diff: Self::Type) -> identity_core::diff::Result { - String::from_diff(diff).and_then(|this| Self::parse(this).map_err(identity_core::diff::Error::convert)) - } - - fn into_diff(self) -> identity_core::diff::Result { - self.to_string().into_diff() - } - } -} - impl PartialEq for CoreDID { fn eq(&self, other: &str) -> bool { self.as_str() == other diff --git a/identity_did/src/did_url.rs b/identity_did/src/did_url.rs index f80fd003d6..7d24b543c3 100644 --- a/identity_did/src/did_url.rs +++ b/identity_did/src/did_url.rs @@ -515,35 +515,6 @@ impl Display for DIDUrl { } } -#[cfg(feature = "diff")] -mod diff { - use super::*; - use identity_core::diff::Diff; - use identity_core::diff::DiffString; - impl Diff for DIDUrl { - type Type = DiffString; - - fn diff(&self, other: &Self) -> identity_core::diff::Result { - self.to_string().diff(&other.to_string()) - } - - fn merge(&self, diff: Self::Type) -> identity_core::diff::Result { - self - .to_string() - .merge(diff) - .and_then(|this| Self::parse(this).map_err(identity_core::diff::Error::merge)) - } - - fn from_diff(diff: Self::Type) -> identity_core::diff::Result { - String::from_diff(diff).and_then(|this| Self::parse(this).map_err(identity_core::diff::Error::convert)) - } - - fn into_diff(self) -> identity_core::diff::Result { - self.to_string().into_diff() - } - } -} - impl KeyComparable for DIDUrl { type Key = Self; diff --git a/identity_document/src/diff/diff_document.rs b/identity_document/src/diff/diff_document.rs deleted file mode 100644 index 1cdb519fe8..0000000000 --- a/identity_document/src/diff/diff_document.rs +++ /dev/null @@ -1,819 +0,0 @@ -// Copyright 2020-2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -use serde::Deserialize; -use serde::Serialize; - -use identity_core::common::Object; -use identity_core::common::OneOrSet; -use identity_core::common::OrderedSet; -use identity_core::common::Url; -use identity_core::diff::Diff; -use identity_core::diff::DiffVec; -use identity_core::diff::Error; -use identity_core::diff::Result; - -use crate::document::CoreDocument; -use crate::document::CoreDocumentData; -use crate::service::Service; -use identity_did::CoreDID; -use identity_verification::MethodRef; -use identity_verification::VerificationMethod; - -#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] -#[serde(bound(deserialize = ""))] -pub struct DiffDocument { - #[serde(skip_serializing_if = "Option::is_none")] - id: Option<::Type>, - #[serde(skip_serializing_if = "Option::is_none")] - controller: Option>>, - #[serde(skip_serializing_if = "Option::is_none")] - also_known_as: Option>, - #[serde(skip_serializing_if = "Option::is_none")] - verification_method: Option>, - #[serde(skip_serializing_if = "Option::is_none")] - authentication: Option>, - #[serde(skip_serializing_if = "Option::is_none")] - assertion_method: Option>, - #[serde(skip_serializing_if = "Option::is_none")] - key_agreement: Option>, - #[serde(skip_serializing_if = "Option::is_none")] - capability_delegation: Option>, - #[serde(skip_serializing_if = "Option::is_none")] - capability_invocation: Option>, - #[serde(skip_serializing_if = "Option::is_none")] - service: Option>, - #[serde(skip_serializing_if = "Option::is_none")] - properties: Option<::Type>, -} - -impl Diff for CoreDocument { - type Type = DiffDocument; - - fn diff(&self, other: &Self) -> Result { - Ok(DiffDocument { - id: if self.id() == other.id() { - None - } else { - Some(self.id().diff(other.id())?) - }, - controller: if self.controller() == other.controller() { - None - } else { - match (self.controller(), other.controller()) { - (Some(a), Some(b)) => Some(Some(a.diff(b)?)), - (None, Some(b)) => Some(Some(b.clone().into_diff()?)), - _ => Some(None), - } - }, - also_known_as: if self.also_known_as() == other.also_known_as() { - None - } else { - Some(self.also_known_as().to_vec().diff(&other.also_known_as().to_vec())?) - }, - verification_method: if self.verification_method() == other.verification_method() { - None - } else { - Some(self.verification_method().diff(other.verification_method())?) - }, - authentication: if self.authentication() == other.authentication() { - None - } else { - Some(self.authentication().diff(other.authentication())?) - }, - assertion_method: if self.assertion_method() == other.assertion_method() { - None - } else { - Some(self.assertion_method().diff(other.assertion_method())?) - }, - key_agreement: if self.key_agreement() == other.key_agreement() { - None - } else { - Some(self.key_agreement().diff(other.key_agreement())?) - }, - capability_delegation: if self.capability_delegation() == other.capability_delegation() { - None - } else { - Some(self.capability_delegation().diff(other.capability_delegation())?) - }, - capability_invocation: if self.capability_invocation() == other.capability_invocation() { - None - } else { - Some(self.capability_invocation().diff(other.capability_invocation())?) - }, - service: if self.service() == other.service() { - None - } else { - Some(self.service().diff(other.service())?) - }, - properties: if self.properties() == other.properties() { - None - } else { - Some(self.properties().diff(other.properties())?) - }, - }) - } - - fn merge(&self, diff: Self::Type) -> Result { - let id: CoreDID = diff - .id - .map(|value| self.id().merge(value)) - .transpose()? - .unwrap_or_else(|| self.id().clone()); - - let controller: Option> = diff - .controller - .map(|value| match value { - Some(diff_value) => self - .controller() - .map(|controller| controller.merge(diff_value)) - .transpose(), - None => Ok(None), - }) - .transpose()? - .unwrap_or_else(|| self.controller().cloned()); - - let also_known_as: OrderedSet = diff - .also_known_as - .map(|value| self.also_known_as().merge(value)) - .transpose()? - .unwrap_or_else(|| self.also_known_as().clone()); - - let verification_method: OrderedSet = diff - .verification_method - .map(|value| self.verification_method().merge(value)) - .transpose()? - .unwrap_or_else(|| self.verification_method().clone()); - - let authentication: OrderedSet = diff - .authentication - .map(|value| self.authentication().merge(value)) - .transpose()? - .unwrap_or_else(|| self.authentication().clone()); - - let assertion_method: OrderedSet = diff - .assertion_method - .map(|value| self.assertion_method().merge(value)) - .transpose()? - .unwrap_or_else(|| self.assertion_method().clone()); - - let key_agreement: OrderedSet = diff - .key_agreement - .map(|value| self.key_agreement().merge(value)) - .transpose()? - .unwrap_or_else(|| self.key_agreement().clone()); - - let capability_delegation: OrderedSet = diff - .capability_delegation - .map(|value| self.capability_delegation().merge(value)) - .transpose()? - .unwrap_or_else(|| self.capability_delegation().clone()); - - let capability_invocation: OrderedSet = diff - .capability_invocation - .map(|value| self.capability_invocation().merge(value)) - .transpose()? - .unwrap_or_else(|| self.capability_invocation().clone()); - - let service: OrderedSet = diff - .service - .map(|value| self.service().merge(value)) - .transpose()? - .unwrap_or_else(|| self.service().clone()); - - let properties: Object = diff - .properties - .map(|value| self.properties().merge(value)) - .transpose()? - .unwrap_or_else(|| self.properties().clone()); - - Ok(CoreDocument { - data: CoreDocumentData { - id, - controller, - also_known_as, - verification_method, - authentication, - assertion_method, - key_agreement, - capability_delegation, - capability_invocation, - service, - properties, - }, - }) - } - - fn from_diff(diff: Self::Type) -> Result { - let id: CoreDID = diff - .id - .map(CoreDID::from_diff) - .transpose()? - .ok_or_else(|| Error::convert("Missing field `document.id`"))?; - - let controller: Option> = diff - .controller - .map(|diff| match diff { - Some(diff) => Some(OneOrSet::from_diff(diff)).transpose(), - None => Ok(None), - }) - .transpose()? - .ok_or_else(|| Error::convert("Missing field `document.controller`"))?; - - let also_known_as: OrderedSet = diff - .also_known_as - .map(Diff::from_diff) - .transpose()? - .ok_or_else(|| Error::convert("Missing field `document.also_known_as`"))?; - - let verification_method: OrderedSet = diff - .verification_method - .map(Diff::from_diff) - .transpose()? - .ok_or_else(|| Error::convert("Missing field `document.verification_method`"))?; - - let authentication: OrderedSet = diff - .authentication - .map(Diff::from_diff) - .transpose()? - .ok_or_else(|| Error::convert("Missing field `document.authentication`"))?; - - let assertion_method: OrderedSet = diff - .assertion_method - .map(Diff::from_diff) - .transpose()? - .ok_or_else(|| Error::convert("Missing field `document.assertion_method`"))?; - - let key_agreement: OrderedSet = diff - .key_agreement - .map(Diff::from_diff) - .transpose()? - .ok_or_else(|| Error::convert("Missing field `document.key_agreement`"))?; - - let capability_delegation: OrderedSet = diff - .capability_delegation - .map(Diff::from_diff) - .transpose()? - .ok_or_else(|| Error::convert("Missing field `document.capability_delegation`"))?; - - let capability_invocation: OrderedSet = diff - .capability_invocation - .map(Diff::from_diff) - .transpose()? - .ok_or_else(|| Error::convert("Missing field `document.capability_invocation`"))?; - - let service: OrderedSet = diff - .service - .map(Diff::from_diff) - .transpose()? - .ok_or_else(|| Error::convert("Missing field `document.service`"))?; - - let properties: Object = diff.properties.map(Object::from_diff).transpose()?.unwrap_or_default(); - - Ok(CoreDocument { - data: CoreDocumentData { - id, - controller, - also_known_as, - verification_method, - authentication, - assertion_method, - key_agreement, - capability_delegation, - capability_invocation, - service, - properties, - }, - }) - } - - fn into_diff(self) -> Result { - let inner = self.data; - - Ok(DiffDocument { - id: Some(inner.id.into_diff()?), - controller: Some(inner.controller.map(|value| value.into_diff()).transpose()?), - also_known_as: Some(inner.also_known_as.into_diff()?), - verification_method: Some(inner.verification_method.into_diff()?), - authentication: Some(inner.authentication.into_diff()?), - assertion_method: Some(inner.assertion_method.into_diff()?), - key_agreement: Some(inner.key_agreement.into_diff()?), - capability_delegation: Some(inner.capability_delegation.into_diff()?), - capability_invocation: Some(inner.capability_invocation.into_diff()?), - service: Some(inner.service.into_diff()?), - properties: if inner.properties == Default::default() { - None - } else { - Some(inner.properties.into_diff()?) - }, - }) - } -} - -#[cfg(test)] -mod test { - use std::collections::BTreeMap; - - use identity_core::common::Value; - use identity_core::convert::FromJson; - use identity_core::convert::ToJson; - use identity_core::diff::DiffString; - - use crate::service::ServiceBuilder; - use crate::service::ServiceEndpoint; - use identity_did::DIDUrl; - use identity_did::DID; - use identity_verification::MethodBuilder; - use identity_verification::MethodData; - use identity_verification::MethodType; - - use super::*; - - fn controller() -> CoreDID { - "did:example:1234".parse().unwrap() - } - - fn method(controller: &CoreDID, fragment: &str) -> VerificationMethod { - MethodBuilder::default() - .id(controller.to_url().join(fragment).unwrap()) - .controller(controller.clone()) - .type_(MethodType::ED25519_VERIFICATION_KEY_2018) - .data(MethodData::new_multibase(fragment.as_bytes())) - .build() - .unwrap() - } - - fn service(did_url: DIDUrl) -> Service { - ServiceBuilder::default() - .id(did_url) - .service_endpoint(ServiceEndpoint::One(Url::parse("did:service:1234").unwrap())) - .type_("test_service") - .build() - .unwrap() - } - - fn document() -> CoreDocument { - let controller = controller(); - let mut properties: BTreeMap = BTreeMap::default(); - properties.insert("key1".to_string(), "value1".into()); - - CoreDocument::builder(properties) - .id(controller.clone()) - .controller(controller.clone()) - .verification_method(method(&controller, "#key-1")) - .verification_method(method(&controller, "#key-2")) - .verification_method(method(&controller, "#key-3")) - .authentication(method(&controller, "#auth-key")) - .authentication(controller.to_url().join("#key-3").unwrap()) - .key_agreement(controller.to_url().join("#key-4").unwrap()) - .assertion_method(method(&controller, "#key-5")) - .capability_delegation(method(&controller, "#key-6")) - .capability_invocation(method(&controller, "#key-7")) - .service(service(controller.to_url().join("#service").unwrap())) - .build() - .unwrap() - } - - #[test] - fn test_id() { - let doc = document(); - let mut new = doc.clone(); - let new_did = "did:diff:1234"; - *new.id_mut_unchecked() = new_did.parse().unwrap(); - assert_ne!(doc, new); - - let diff = doc.diff(&new).unwrap(); - assert_eq!(diff.id, Some(DiffString(Some(new_did.to_string())))); - let merge = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_controller_one() { - let doc: CoreDocument = document(); - let mut new: CoreDocument = doc.clone(); - let new_controller: CoreDID = "did:diff:1234".parse().unwrap(); - *new.controller_mut() = Some(OneOrSet::new_one(new_controller)); - assert_ne!(doc, new); - - let diff: DiffDocument = doc.diff(&new).unwrap(); - let merge: CoreDocument = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_controller_set() { - let doc: CoreDocument = document(); - let mut new: CoreDocument = doc.clone(); - let new_controllers: Vec = vec![ - "did:diff:1234".parse().unwrap(), - "did:diff:5678".parse().unwrap(), - "did:diff:9012".parse().unwrap(), - ]; - *new.controller_mut() = Some(new_controllers.try_into().unwrap()); - assert_ne!(doc, new); - - let diff: DiffDocument = doc.diff(&new).unwrap(); - let merge: CoreDocument = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_controller_unset() { - let doc: CoreDocument = document(); - let mut new: CoreDocument = doc.clone(); - *new.controller_mut() = None; - assert_ne!(doc, new); - - let diff: DiffDocument = doc.diff(&new).unwrap(); - let merge: CoreDocument = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_also_known_as() { - let doc = document(); - let mut new = doc.clone(); - new.also_known_as_mut().append("diff:diff:1234".parse().unwrap()); - assert_ne!(doc, new); - - let diff = doc.diff(&new).unwrap(); - let merge = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_add_verification_method() { - let doc = document(); - let mut new = doc.clone(); - - // add new method - assert!(new.data.verification_method.append(method(&doc.data.id, "#key-diff"))); - assert_ne!(doc, new); - let diff = doc.diff(&new).unwrap(); - let merge = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_replace_verification_method() { - let doc = document(); - let mut new = doc.clone(); - - // update method - let first = new.verification_method().first().unwrap().clone(); - new - .data - .verification_method - .replace(&first, method(&"did:diff:1234".parse().unwrap(), "#key-diff")); - assert_ne!(doc, new); - let diff = doc.diff(&new).unwrap(); - let merge = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_remove_verification_method() { - let doc = document(); - let mut new = doc.clone(); - - // remove method - let first = new.verification_method().first().unwrap().clone(); - new.data.verification_method.remove(&first); - assert_ne!(doc, new); - let diff = doc.diff(&new).unwrap(); - let merge = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_add_authentication() { - let doc = document(); - let mut new = doc.clone(); - - // add new method - let method_ref: MethodRef = method(&doc.data.id, "#key-diff").into(); - assert!(new.data.authentication.append(method_ref)); - assert_ne!(doc, new); - let diff = doc.diff(&new).unwrap(); - let merge = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_replace_authentication() { - let doc = document(); - let mut new = doc.clone(); - - // update method - let method_ref: MethodRef = method(&doc.data.id, "#key-diff").into(); - let first = new.authentication().first().unwrap().clone(); - new.data.authentication.replace(&first, method_ref); - assert_ne!(doc, new); - let diff = doc.diff(&new).unwrap(); - let merge = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_remove_authentication() { - let doc = document(); - let mut new = doc.clone(); - - // remove method - let first = new.authentication().first().unwrap().clone(); - new.data.authentication.remove(&first); - assert_ne!(doc, new); - let diff = doc.diff(&new).unwrap(); - let merge = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_add_assertion_method() { - let doc = document(); - let mut new = doc.clone(); - - // add new method - let method_ref: MethodRef = method(&doc.data.id, "#key-diff").into(); - assert!(new.data.assertion_method.append(method_ref)); - assert_ne!(doc, new); - let diff = doc.diff(&new).unwrap(); - let merge = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_replace_assertion_method() { - let doc = document(); - let mut new = doc.clone(); - - // update method - let method_ref: MethodRef = method(&doc.data.id, "#key-diff").into(); - let first = new.assertion_method().first().unwrap().clone(); - new.data.assertion_method.replace(&first, method_ref); - assert_ne!(doc, new); - let diff = doc.diff(&new).unwrap(); - let merge = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_remove_assertion_method() { - let doc = document(); - let mut new = doc.clone(); - - // remove method - let first = new.assertion_method().first().unwrap().clone(); - new.data.assertion_method.remove(&first); - assert_ne!(doc, new); - let diff = doc.diff(&new).unwrap(); - let merge = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_add_key_agreement() { - let doc = document(); - let mut new = doc.clone(); - - // add new method - let method_ref: MethodRef = method(&doc.data.id, "#key-diff").into(); - assert!(new.data.key_agreement.append(method_ref)); - assert_ne!(doc, new); - let diff = doc.diff(&new).unwrap(); - let merge = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_replace_key_agreement() { - let doc = document(); - let mut new = doc.clone(); - - // update method - let method_ref: MethodRef = method(&doc.data.id, "#key-diff").into(); - let first = new.key_agreement().first().unwrap().clone(); - new.data.key_agreement.replace(&first, method_ref); - assert_ne!(doc, new); - let diff = doc.diff(&new).unwrap(); - let merge = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_remove_key_agreement() { - let doc = document(); - let mut new = doc.clone(); - - // remove method - let first = new.key_agreement().first().unwrap().clone(); - new.data.key_agreement.remove(&first); - assert_ne!(doc, new); - let diff = doc.diff(&new).unwrap(); - let merge = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_add_capability_delegation() { - let doc = document(); - let mut new = doc.clone(); - - // add new method - let method_ref: MethodRef = method(&doc.data.id, "#key-diff").into(); - assert!(new.data.capability_delegation.append(method_ref)); - assert_ne!(doc, new); - let diff = doc.diff(&new).unwrap(); - let merge = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_replace_capability_delegation() { - let doc = document(); - let mut new = doc.clone(); - - // update method - let method_ref: MethodRef = method(&doc.data.id, "#key-diff").into(); - let first = new.capability_delegation().first().unwrap().clone(); - new.data.capability_delegation.replace(&first, method_ref); - assert_ne!(doc, new); - let diff = doc.diff(&new).unwrap(); - let merge = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_remove_capability_delegation() { - let doc = document(); - let mut new = doc.clone(); - - // remove method - let first = new.capability_delegation().first().unwrap().clone(); - new.data.capability_delegation.remove(&first); - assert_ne!(doc, new); - let diff = doc.diff(&new).unwrap(); - let merge = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_add_capability_invocation() { - let doc = document(); - let mut new = doc.clone(); - - // add new method - let method_ref: MethodRef = method(&doc.data.id, "#key-diff").into(); - assert!(new.data.capability_invocation.append(method_ref)); - assert_ne!(doc, new); - let diff = doc.diff(&new).unwrap(); - let merge = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_replace_capability_invocation() { - let doc = document(); - let mut new = doc.clone(); - - // update method - let method_ref: MethodRef = method(&doc.data.id, "#key-diff").into(); - let first = new.capability_invocation().first().unwrap().clone(); - new.data.capability_invocation.replace(&first, method_ref); - assert_ne!(doc, new); - let diff = doc.diff(&new).unwrap(); - let merge = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_remove_capability_invocation() { - let doc = document(); - let mut new = doc.clone(); - - // remove method - let first = new.capability_invocation().first().unwrap().clone(); - new.data.capability_invocation.remove(&first); - assert_ne!(doc, new); - let diff = doc.diff(&new).unwrap(); - let merge = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_add_service() { - let doc = document(); - let mut new = doc.clone(); - - // Add new service - let service = service(doc.data.id.to_url().join("#key-diff").unwrap()); - assert!(new.insert_service(service).is_ok()); - assert_ne!(doc, new); - let diff = doc.diff(&new).unwrap(); - let merge = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_replace_service() { - let doc = document(); - let mut new = doc.clone(); - - // add new service - let service = service(doc.data.id.to_url().join("#key-diff").unwrap()); - let first = new.service().first().unwrap().clone(); - assert!(new.remove_service(first.id()).is_some()); - assert!(new.insert_service(service).is_ok()); - assert_ne!(doc, new); - let diff = doc.diff(&new).unwrap(); - let merge = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_remove_service() { - let doc = document(); - let mut new = doc.clone(); - - // remove method - let first = new.service().first().unwrap().clone(); - new.remove_service(first.id()); - assert_ne!(doc, new); - let diff = doc.diff(&new).unwrap(); - let merge = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_replace_properties() { - let doc = document(); - let mut new = doc.clone(); - - // update properties - *new.properties_mut_unchecked() = BTreeMap::default(); - - assert_ne!(doc, new); - let diff = doc.diff(&new).unwrap(); - let merge = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_add_properties() { - let doc = document(); - let mut new = doc.clone(); - - // update properties - assert!(new - .properties_mut_unchecked() - .insert("key2".to_string(), "value2".into()) - .is_none()); - - assert_ne!(doc, new); - let diff = doc.diff(&new).unwrap(); - let merge = doc.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_from_into_diff() { - let doc: CoreDocument = document(); - - let diff: DiffDocument = doc.clone().into_diff().unwrap(); - let new: CoreDocument = CoreDocument::from_diff(diff.clone()).unwrap(); - assert_eq!(doc, new); - - let ser: String = diff.to_json().unwrap(); - let de: DiffDocument = DiffDocument::from_json(&ser).unwrap(); - assert_eq!(de, diff); - let from: CoreDocument = CoreDocument::from_diff(de).unwrap(); - assert_eq!(doc, from); - } - - #[test] - fn test_rotate_key_material_method() { - let doc = document(); - let mut new = doc.clone(); - - let first: DIDUrl = new.capability_invocation().first().unwrap().as_ref().clone(); - new.data.capability_invocation.remove(&first); - - let method_ref: MethodRef = MethodBuilder::default() - .id(first) - .controller(new.data.id.clone()) - .type_(MethodType::ED25519_VERIFICATION_KEY_2018) - .data(MethodData::new_multibase(b"key_material")) - .build() - .unwrap() - .into(); - - assert!(new.data.capability_invocation.append(method_ref)); - - assert_ne!(doc, new); - - // Ensure overwriting the key material of a method with the same fragment produces a diff. - let diff = doc.diff(&new).unwrap(); - assert!(diff.capability_invocation.is_some()); - } -} diff --git a/identity_document/src/diff/diff_service.rs b/identity_document/src/diff/diff_service.rs deleted file mode 100644 index ea78384b72..0000000000 --- a/identity_document/src/diff/diff_service.rs +++ /dev/null @@ -1,406 +0,0 @@ -// Copyright 2020-2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -use serde::Deserialize; -use serde::Serialize; - -use identity_core::common::Object; -use identity_core::common::OneOrSet; -use identity_core::diff::Diff; -use identity_core::diff::Error; -use identity_core::diff::Result; - -use crate::service::Service; -use crate::service::ServiceBuilder; -use crate::service::ServiceEndpoint; -use identity_did::DIDUrl; - -#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] -pub struct DiffService { - #[serde(skip_serializing_if = "Option::is_none")] - id: Option<::Type>, - #[serde(skip_serializing_if = "Option::is_none")] - type_: Option< as Diff>::Type>, - #[serde(skip_serializing_if = "Option::is_none")] - service_endpoint: Option<::Type>, - #[serde(skip_serializing_if = "Option::is_none")] - properties: Option<::Type>, -} - -impl Diff for Service { - type Type = DiffService; - - fn diff(&self, other: &Self) -> Result { - Ok(DiffService { - id: if self.id() == other.id() { - None - } else { - Some(self.id().diff(other.id())?) - }, - type_: if self.type_() == other.type_() { - None - } else { - Some(self.type_().diff(other.type_())?) - }, - service_endpoint: if self.service_endpoint() == other.service_endpoint() { - None - } else { - Some(self.service_endpoint().diff(other.service_endpoint())?) - }, - properties: if self.properties() == other.properties() { - None - } else { - Some(self.properties().diff(other.properties())?) - }, - }) - } - - fn merge(&self, diff: Self::Type) -> Result { - let id: DIDUrl = diff - .id - .map(|value| self.id().merge(value)) - .transpose()? - .unwrap_or_else(|| self.id().clone()); - - let type_: OneOrSet = diff - .type_ - .map(|value| self.type_().merge(value)) - .transpose()? - .unwrap_or_else(|| self.type_().clone()); - - let service_endpoint: ServiceEndpoint = diff - .service_endpoint - .map(|value| self.service_endpoint().merge(value)) - .transpose()? - .unwrap_or_else(|| self.service_endpoint().clone()); - - let properties: Object = diff - .properties - .map(|value| self.properties().merge(value)) - .transpose()? - .unwrap_or_else(|| self.properties().clone()); - - // Use builder to enforce invariants. - ServiceBuilder::new(properties) - .id(id) - .types(type_) - .service_endpoint(service_endpoint) - .build() - .map_err(Error::merge) - } - - fn from_diff(diff: Self::Type) -> Result { - let id: DIDUrl = diff - .id - .map(Diff::from_diff) - .transpose()? - .ok_or_else(|| Error::convert("Missing field `service.id`"))?; - - let type_: OneOrSet = diff - .type_ - .map(Diff::from_diff) - .transpose()? - .ok_or_else(|| Error::convert("Missing field `service.type_`"))?; - - let service_endpoint: ServiceEndpoint = diff - .service_endpoint - .map(Diff::from_diff) - .transpose()? - .ok_or_else(|| Error::convert("Missing field `service.service_endpoint`"))?; - - let properties: Object = diff.properties.map(Diff::from_diff).transpose()?.unwrap_or_default(); - - // Use builder to enforce invariants. - ServiceBuilder::new(properties) - .id(id) - .types(type_) - .service_endpoint(service_endpoint) - .build() - .map_err(Error::convert) - } - - fn into_diff(self) -> Result { - Ok(DiffService { - id: Some(self.id.into_diff()?), - type_: Some(self.type_.into_diff()?), - service_endpoint: Some(self.service_endpoint.into_diff()?), - properties: if self.properties != Object::default() { - Some(self.properties.into_diff()?) - } else { - None - }, - }) - } -} - -impl Diff for ServiceEndpoint { - type Type = ServiceEndpoint; - - fn diff(&self, other: &Self) -> identity_core::diff::Result { - if self != other { - Ok(other.clone()) - } else { - Ok(self.clone()) - } - } - - fn merge(&self, diff: Self::Type) -> identity_core::diff::Result { - if self != &diff { - Ok(diff) - } else { - Ok(self.clone()) - } - } - - fn from_diff(diff: Self::Type) -> identity_core::diff::Result { - Ok(diff) - } - - fn into_diff(self) -> identity_core::diff::Result { - Ok(self) - } -} - -#[cfg(test)] -mod test { - use indexmap::IndexMap; - - use identity_core::common::Object; - use identity_core::common::OrderedSet; - use identity_core::common::Url; - use identity_core::convert::FromJson; - use identity_core::convert::ToJson; - use identity_core::diff::DiffString; - use identity_core::diff::DiffVec; - use identity_did::DIDUrl; - - use super::*; - - fn controller() -> DIDUrl { - "did:example:1234#service".parse().unwrap() - } - - fn service() -> Service { - let controller = controller(); - Service::builder(Object::default()) - .id(controller) - .service_endpoint(Url::parse("did:service:1234").unwrap()) - .type_("test_service") - .build() - .unwrap() - } - - #[test] - fn test_id() { - let service = service(); - let mut new = service.clone(); - new.set_id("did:diff:123#new-service".parse().unwrap()).unwrap(); - - let diff = service.diff(&new).unwrap(); - assert!(diff.properties.is_none()); - assert!(diff.service_endpoint.is_none()); - assert!(diff.type_.is_none()); - assert_eq!(diff.id, Some(DiffString(Some("did:diff:123#new-service".to_string())))); - let merge = service.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_type_one() { - let service = service(); - let mut new = service.clone(); - *new.type_mut() = OneOrSet::new_one("test_service_2".to_owned()); - - let diff = service.diff(&new).unwrap(); - assert!(diff.properties.is_none()); - assert!(diff.service_endpoint.is_none()); - assert!(diff.id.is_none()); - assert!(diff.type_.is_some()); - let merge = service.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_type_set() { - let service = service(); - - // One to set. - let mut service_set = service.clone(); - *service_set.type_mut() = - OneOrSet::try_from(vec!["test_service_set_1".to_owned(), "test_service_set_2".to_owned()]).unwrap(); - - let diff_set = service.diff(&service_set).unwrap(); - assert!(diff_set.properties.is_none()); - assert!(diff_set.service_endpoint.is_none()); - assert!(diff_set.id.is_none()); - assert!(diff_set.type_.is_some()); - let merge = service.merge(diff_set).unwrap(); - assert_eq!(merge, service_set); - - // Set to one. - let mut service_one = service_set.clone(); - *service_one.type_mut() = OneOrSet::new_one("one_service_type".to_owned()); - - let diff_one = service_set.diff(&service_one).unwrap(); - assert!(diff_one.properties.is_none()); - assert!(diff_one.service_endpoint.is_none()); - assert!(diff_one.id.is_none()); - assert!(diff_one.type_.is_some()); - let merge = service_set.merge(diff_one).unwrap(); - assert_eq!(merge, service_one); - } - - #[test] - fn test_service_endpoint_one() { - let service = service(); - let mut new = service.clone(); - let new_url = Url::parse("did:test:1234#service").unwrap(); - *new.service_endpoint_mut() = ServiceEndpoint::One(new_url.clone()); - - let diff = service.diff(&new).unwrap(); - assert!(diff.id.is_none()); - assert!(diff.properties.is_none()); - assert!(diff.type_.is_none()); - assert_eq!(diff.service_endpoint, Some(ServiceEndpoint::One(new_url)),); - let merge = service.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_service_endpoint_set() { - let service = service(); - - let mut new = service.clone(); - let new_url_set = vec![ - Url::parse("https://example.com/").unwrap(), - Url::parse("did:test:1234#service").unwrap(), - ]; - *new.service_endpoint_mut() = ServiceEndpoint::Set(new_url_set.clone().try_into().unwrap()); - - let diff = service.diff(&new).unwrap(); - assert!(diff.id.is_none()); - assert!(diff.properties.is_none()); - assert!(diff.type_.is_none()); - assert_eq!( - diff.service_endpoint, - Some(ServiceEndpoint::Set(new_url_set.try_into().unwrap())), - ); - let merge = service.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_service_endpoint_map() { - let service = service(); - - let mut new = service.clone(); - let mut new_url_map = IndexMap::new(); - new_url_map.insert( - "origins".to_owned(), - vec![ - Url::parse("https://example.com/").unwrap(), - Url::parse("did:test:1234#service").unwrap(), - ] - .try_into() - .unwrap(), - ); - *new.service_endpoint_mut() = ServiceEndpoint::Map(new_url_map.clone()); - - let diff = service.diff(&new).unwrap(); - assert!(diff.id.is_none()); - assert!(diff.properties.is_none()); - assert!(diff.type_.is_none()); - assert_eq!(diff.service_endpoint, Some(ServiceEndpoint::Map(new_url_map)),); - let merge = service.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_replace_properties() { - let mut service = service(); - service.properties.insert("key1".to_string(), "value1".into()); - let mut new = service.clone(); - - // Replace properties. - *new.properties_mut() = Object::default(); - - assert_ne!(service, new); - let diff = service.diff(&new).unwrap(); - let merge = service.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_add_properties() { - let service = service(); - let mut new = service.clone(); - - // Update properties. - assert!(new - .properties_mut() - .insert("key2".to_string(), "value2".into()) - .is_none()); - - assert_ne!(service, new); - let diff = service.diff(&new).unwrap(); - let merge = service.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_from_into_diff() { - let service: Service = service(); - - let diff: DiffService = service.clone().into_diff().unwrap(); - let new: Service = Service::from_diff(diff.clone()).unwrap(); - assert_eq!(new, service); - - let ser: String = diff.to_json().unwrap(); - let de: DiffService = DiffService::from_json(&ser).unwrap(); - assert_eq!(diff, de); - let from: Service = Service::from_diff(de).unwrap(); - assert_eq!(from, service); - } - - #[test] - fn test_serde() { - let service = service(); - - // Empty diff. - { - let diff: DiffService = service.clone().into_diff().unwrap(); - let ser: String = diff.to_json().unwrap(); - let de: DiffService = DiffService::from_json(&ser).unwrap(); - assert_eq!(diff, de); - } - - // Updated fields. - { - let mut updated: Service = service.clone(); - updated.id = DIDUrl::parse("did:test:serde").unwrap(); - updated.type_ = OneOrSet::new_one("TestSerde".to_owned()); - updated.service_endpoint = ServiceEndpoint::One(Url::parse("https://test.serde/").unwrap()); - updated.properties.insert("a".into(), 42.into()); - let diff: DiffService = Diff::diff(&service, &updated).unwrap(); - let ser: String = diff.to_json().unwrap(); - let de: DiffService = DiffService::from_json(&ser).unwrap(); - assert_eq!(diff, de); - } - } - - #[test] - fn test_ordered_set_service_diff_serde() { - let mut service = service(); - service.type_ = OneOrSet::from("".to_string()); - let set0: OrderedSet = OrderedSet::new(); - let set1: OrderedSet = OrderedSet::try_from(vec![service]).unwrap(); - - let diff: DiffVec = Diff::diff(&set0, &set1).unwrap(); - let merge: OrderedSet = set0.merge(diff.clone()).unwrap(); - assert_eq!(merge, set1); - - let ser: String = diff.to_json().unwrap(); - let de: DiffVec = DiffVec::from_json(&ser).unwrap(); - assert_eq!(diff, de); - } -} diff --git a/identity_document/src/diff/mod.rs b/identity_document/src/diff/mod.rs deleted file mode 100644 index 89343abe4a..0000000000 --- a/identity_document/src/diff/mod.rs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2020-2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -pub use self::diff_document::DiffDocument; -pub use self::diff_service::DiffService; -pub use identity_verification::diff::DiffMethod; -pub use identity_verification::diff::DiffMethodData; -pub use identity_verification::diff::DiffMethodRef; - -mod diff_document; -mod diff_service; diff --git a/identity_document/src/document/mod.rs b/identity_document/src/document/mod.rs index ee3ad9e950..f6b34be46f 100644 --- a/identity_document/src/document/mod.rs +++ b/identity_document/src/document/mod.rs @@ -8,7 +8,5 @@ pub use self::builder::DocumentBuilder; pub use self::core_document::CoreDocument; -#[cfg(feature = "diff")] -pub(crate) use core_document::CoreDocumentData; mod builder; mod core_document; diff --git a/identity_document/src/lib.rs b/identity_document/src/lib.rs index 65b572be23..f45acae16f 100644 --- a/identity_document/src/lib.rs +++ b/identity_document/src/lib.rs @@ -20,10 +20,6 @@ #[macro_use] extern crate serde; -#[cfg(feature = "diff")] -#[deprecated(since = "0.5.0", note = "diff chain features are slated for removal")] -pub mod diff; - pub mod document; pub mod error; pub mod service; diff --git a/identity_document/src/verifiable/properties.rs b/identity_document/src/verifiable/properties.rs index e08c9000b2..121fb4f507 100644 --- a/identity_document/src/verifiable/properties.rs +++ b/identity_document/src/verifiable/properties.rs @@ -41,42 +41,6 @@ impl VerifiableProperties { } } -#[cfg(feature = "diff")] -mod diff { - use super::*; - use identity_core::diff::Diff; - /// NOTE: excludes the `proof` Signature from the diff to save space on the Tangle and because - /// a merged signature will be invalid in general. - impl Diff for VerifiableProperties - where - T: Diff, - { - type Type = ::Type; - - fn diff(&self, other: &Self) -> identity_core::diff::Result { - self.properties.diff(&other.properties) - } - - fn merge(&self, diff: Self::Type) -> identity_core::diff::Result { - let mut this: VerifiableProperties = self.clone(); - this.properties = this.properties.merge(diff)?; - Ok(this) - } - - fn from_diff(diff: Self::Type) -> identity_core::diff::Result { - let properties: T = T::from_diff(diff)?; - Ok(VerifiableProperties { - properties, - proof: None, // proof intentionally excluded - }) - } - - fn into_diff(self) -> identity_core::diff::Result { - self.properties.into_diff() - } - } -} - impl Deref for VerifiableProperties { type Target = T; diff --git a/identity_iota/src/lib.rs b/identity_iota/src/lib.rs index 521dc4d6a6..33154968fc 100644 --- a/identity_iota/src/lib.rs +++ b/identity_iota/src/lib.rs @@ -26,11 +26,6 @@ pub mod core { pub use identity_core::error::*; pub use identity_core::utils::*; - #[cfg(feature = "diff")] - #[deprecated(since = "0.5.0", note = "diff chain features are slated for removal")] - #[doc(inline)] - pub use identity_core::diff; - #[doc(inline)] pub use identity_core::json; } diff --git a/identity_jose/src/jwk/diff/key.rs b/identity_jose/src/jwk/diff/key.rs deleted file mode 100644 index fc03e831de..0000000000 --- a/identity_jose/src/jwk/diff/key.rs +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright 2020-2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -use crate::jwk::Jwk; -use crate::jwk::JwkOperation; -use crate::jwk::JwkType; -use crate::jwk::JwkUse; -use identity_core::common::Url; -use identity_core::diff::Diff; -use identity_core::diff::DiffOption; -use identity_core::diff::Result as DiffResult; -use serde::Deserialize; -use serde::Serialize; - -use super::DiffJwkParams; - -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] -pub struct DiffJwk { - kty: ::Type, - use_: DiffOption, - key_ops: DiffOption>, - alg: DiffOption, - kid: DiffOption, - x5u: DiffOption, - x5c: DiffOption>, - x5t: DiffOption, - x5t_s256: DiffOption, - params: DiffJwkParams, -} - -impl Diff for Jwk { - type Type = DiffJwk; - /// Finds the difference of `self` and `other`. This is guaranteed to error if either - /// `self` or `other` contain params with private key components. - fn diff(&self, other: &Self) -> DiffResult { - let kty = self.kty.diff(&other.kty)?; - let use_ = self.use_.diff(&other.use_)?; - let key_ops = self.key_ops.diff(&other.key_ops)?; - let alg = self.alg.diff(&other.alg)?; - let kid = self.kid.diff(&other.kid)?; - let x5u = self.x5u.diff(&other.x5u)?; - let x5c = self.x5c.diff(&other.x5c)?; - let x5t = self.x5t.diff(&other.x5t)?; - let x5t_s256 = self.x5t_s256.diff(&other.x5t_s256)?; - let params = self.params.diff(&other.params)?; - Ok(DiffJwk { - kty, - use_, - key_ops, - alg, - kid, - x5u, - x5c, - x5t, - x5t_s256, - params, - }) - } - fn merge(&self, diff: Self::Type) -> DiffResult { - let DiffJwk { - kty, - use_, - key_ops, - alg, - kid, - x5u, - x5c, - x5t, - x5t_s256, - params, - } = diff; - let kty = self.kty.merge(kty)?; - let use_ = self.use_.merge(use_)?; - let key_ops = self.key_ops.merge(key_ops)?; - let alg = self.alg.merge(alg)?; - let kid = self.kid.merge(kid)?; - let x5u = self.x5u.merge(x5u)?; - let x5c = self.x5c.merge(x5c)?; - let x5t = self.x5t.merge(x5t)?; - let x5t_s256 = self.x5t_s256.merge(x5t_s256)?; - let params = self.params.merge(params)?; - Ok(Jwk { - kty, - use_, - key_ops, - alg, - kid, - x5u, - x5c, - x5t, - x5t_s256, - params, - }) - } - - fn from_diff(diff: Self::Type) -> identity_core::diff::Result { - let DiffJwk { - kty, - use_, - key_ops, - alg, - kid, - x5u, - x5c, - x5t, - x5t_s256, - params, - } = diff; - let kty = Diff::from_diff(kty)?; - let use_ = Diff::from_diff(use_)?; - let key_ops = Diff::from_diff(key_ops)?; - let alg = Diff::from_diff(alg)?; - let kid = Diff::from_diff(kid)?; - let x5u = Diff::from_diff(x5u)?; - let x5c = Diff::from_diff(x5c)?; - let x5t = Diff::from_diff(x5t)?; - let x5t_s256 = Diff::from_diff(x5t_s256)?; - let params = Diff::from_diff(params)?; - Ok(Jwk { - kty, - use_, - key_ops, - alg, - kid, - x5u, - x5c, - x5t, - x5t_s256, - params, - }) - } - - /// Convert `self` into [`DiffJwk`]. This is guaranteed to error if `self` - /// contains params with private key components. - fn into_diff(mut self) -> identity_core::diff::Result { - self.take_diff() - } -} - -impl Jwk { - fn take_diff(&mut self) -> DiffResult { - Ok(DiffJwk { - kty: self.kty.into_diff()?, - use_: self.use_.into_diff()?, - key_ops: self.key_ops.take().into_diff()?, - alg: self.alg.take().into_diff()?, - kid: self.kid.take().into_diff()?, - x5u: self.x5u.take().into_diff()?, - x5c: self.x5c.take().into_diff()?, - x5t: self.x5t.take().into_diff()?, - x5t_s256: self.x5t_s256.take().into_diff()?, - params: self.params.take_diff()?, - }) - } -} diff --git a/identity_jose/src/jwk/diff/key_operations.rs b/identity_jose/src/jwk/diff/key_operations.rs deleted file mode 100644 index b07b197cd2..0000000000 --- a/identity_jose/src/jwk/diff/key_operations.rs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2020-2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -use identity_core::diff::Diff; -use identity_core::diff::Result; -use serde::Deserialize; -use serde::Serialize; - -use crate::jwk::JwkOperation; - -#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] -pub struct DiffJwkOperation(#[serde(skip_serializing_if = "Option::is_none")] Option); - -impl Diff for JwkOperation { - type Type = DiffJwkOperation; - - fn diff(&self, other: &Self) -> Result { - if self == other { - Ok(DiffJwkOperation(None)) - } else { - Ok(DiffJwkOperation(Some(*other))) - } - } - - fn merge(&self, diff: Self::Type) -> Result { - Ok(diff.0.unwrap_or(*self)) - } - - fn from_diff(diff: Self::Type) -> Result { - diff - .0 - .ok_or_else(|| identity_core::diff::Error::ConversionError("cannot convert from empty diff".to_owned())) - } - - fn into_diff(self) -> Result { - Ok(DiffJwkOperation(Some(self))) - } -} diff --git a/identity_jose/src/jwk/diff/key_params/ec.rs b/identity_jose/src/jwk/diff/key_params/ec.rs deleted file mode 100644 index dfed291a9f..0000000000 --- a/identity_jose/src/jwk/diff/key_params/ec.rs +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright 2020-2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 -use super::Deserialize; -use super::Diff; -use super::DiffResult; -use super::DiffString; -use super::Serialize; -use crate::jwk::JwkParamsEc; - -/// Represents the difference of two [`JwkParamsEcs`](JwkParamsEc) without any private -/// components. -#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)] -pub struct DiffJwkParamsEc { - pub crv: DiffString, // Curve - pub x: DiffString, // X Coordinate - pub y: DiffString, // Y Coordinate -} - -impl Diff for JwkParamsEc { - type Type = DiffJwkParamsEc; - - /// Finds the difference between `self` and `other` and returns the result as - /// a [`DiffJwkParamsEc`]. - /// - /// # Errors - /// Errors if either `self` or `other` contains private components. - fn diff(&self, other: &Self) -> DiffResult { - if !(self.is_public() && other.is_public()) { - return Err(identity_core::diff::Error::DiffError( - "cannot diff jwk ec params with private components".to_owned(), - )); - } - Ok(DiffJwkParamsEc { - crv: self.crv.diff(&other.crv)?, - x: self.x.diff(&other.x)?, - y: self.y.diff(&other.y)?, - }) - } - - fn merge(&self, diff: Self::Type) -> DiffResult { - let crv = self.crv.merge(diff.crv)?; - let x = self.x.merge(diff.x)?; - let y = self.y.merge(diff.y)?; - Ok(JwkParamsEc { crv, x, y, d: None }) - } - - fn from_diff(diff: Self::Type) -> DiffResult { - let DiffJwkParamsEc { crv, x, y } = diff; - Ok(Self { - crv: Diff::from_diff(crv)?, - x: Diff::from_diff(x)?, - y: Diff::from_diff(y)?, - d: None, - }) - } - - /// Converts the [`JwkParamsEc`] into [`DiffJwkParamsEc`]. - /// - /// # Errors - /// Errors if the params contain a private component. - fn into_diff(mut self) -> DiffResult { - self.take_diff() - } -} - -impl JwkParamsEc { - /// Obtain a [`DiffJwkParamsEc`] from a [`&mut JwkParamsEc`](JwkParamsEc) leaving - /// empty strings as public parameters in `self`. - /// - /// # Errors - /// Errors immediately if the params contain a private component. - /// - /// # Motivation - /// [`JwkParamsEc`] cannot directly be destructured because of [zeroize(drop)] - /// hence this provides workaround to enable a cheap implementation of `into_diff`. - pub(super) fn take_diff(&mut self) -> DiffResult { - if !self.is_public() { - return Err(identity_core::diff::Error::ConversionError( - "cannot convert jwk ec params with private components to diff".to_owned(), - )); - } - - let (crv, x, y): (String, String, String) = { - // Cannot directly destructure because of #[zeroize(drop)] - let JwkParamsEc { - ref mut crv, - ref mut x, - ref mut y, - .. - } = self; - (std::mem::take(crv), std::mem::take(x), std::mem::take(y)) - }; - - Ok(DiffJwkParamsEc { - crv: crv.into_diff()?, - x: x.into_diff()?, - y: y.into_diff()?, - }) - } -} diff --git a/identity_jose/src/jwk/diff/key_params/mod.rs b/identity_jose/src/jwk/diff/key_params/mod.rs deleted file mode 100644 index fb78d600d6..0000000000 --- a/identity_jose/src/jwk/diff/key_params/mod.rs +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2020-2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -use identity_core::diff::Diff; -use identity_core::diff::DiffString; -use identity_core::diff::Result as DiffResult; -use serde::Deserialize; -use serde::Serialize; -mod ec; -mod oct; -mod okp; -mod rsa; -pub use ec::*; -pub use oct::*; -pub use okp::*; -pub use rsa::*; - -use crate::jwk::JwkParams; - -/// The difference of two [`JwkParams`]. -#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] -pub enum DiffJwkParams { - Ec(DiffJwkParamsEc), - Rsa(DiffJwkParamsRsa), - Oct(DiffJwkParamsOct), - Okp(DiffJwkParamsOkp), -} - -impl Diff for JwkParams { - type Type = DiffJwkParams; - - /// Finds the difference between `self` and `other` and returns the result represented as a [`DiffJwkParams`]. - /// - /// # Errors - /// Errors if `self` or `others` contain private components. - fn diff(&self, other: &Self) -> DiffResult { - match (self, other) { - (Self::Okp(a), Self::Okp(b)) => Ok(DiffJwkParams::Okp(a.diff(b)?)), - (Self::Ec(a), Self::Ec(b)) => Ok(DiffJwkParams::Ec(a.diff(b)?)), - (Self::Oct(a), Self::Oct(b)) => Ok(DiffJwkParams::Oct(a.diff(b)?)), - (Self::Rsa(a), Self::Rsa(b)) => Ok(DiffJwkParams::Rsa(a.diff(b)?)), - (_, _) => other.clone().into_diff(), - } - } - - fn merge(&self, diff: Self::Type) -> DiffResult { - match (self, diff) { - (Self::Okp(a), DiffJwkParams::Okp(b)) => a.merge(b).map(Self::Okp), - (Self::Ec(a), DiffJwkParams::Ec(b)) => a.merge(b).map(Self::Ec), - (Self::Oct(a), DiffJwkParams::Oct(b)) => a.merge(b).map(Self::Oct), - (Self::Rsa(a), DiffJwkParams::Rsa(b)) => a.merge(b).map(Self::Rsa), - (_, diff) => Self::from_diff(diff), - } - } - - fn from_diff(diff: Self::Type) -> DiffResult { - match diff { - DiffJwkParams::Okp(diff_params) => Diff::from_diff(diff_params).map(Self::Okp), - DiffJwkParams::Ec(diff_params) => Diff::from_diff(diff_params).map(Self::Ec), - DiffJwkParams::Oct(diff_params) => Diff::from_diff(diff_params).map(Self::Oct), - DiffJwkParams::Rsa(diff_params) => Diff::from_diff(diff_params).map(Self::Rsa), - } - } - - /// Converts the [`JwkParams`] into [`DiffJwkParams`]. - /// - /// # Errors - /// Errors if the [`JwkParams`] contain private components. - fn into_diff(mut self) -> DiffResult { - self.take_diff() - } -} - -impl JwkParams { - /// Obtain [`DiffJwkParams`] from [`&mut JwkParams`](JwkParams) leaving - /// empty strings as public parameters in `self`. - /// - /// # Errors - /// Errors immediately if the params contain a private component. - /// - /// # Motivation - /// [`JwkParams`] cannot directly be destructured because of [zeroize(drop)] - /// hence this provides workaround to enable a cheap implementation of `into_diff`. - pub(super) fn take_diff(&mut self) -> DiffResult { - match self { - Self::Okp(params) => params.take_diff().map(DiffJwkParams::Okp), - Self::Ec(params) => params.take_diff().map(DiffJwkParams::Ec), - Self::Oct(params) => params.take_diff().map(DiffJwkParams::Oct), - Self::Rsa(params) => params.take_diff().map(DiffJwkParams::Rsa), - } - } -} diff --git a/identity_jose/src/jwk/diff/key_params/oct.rs b/identity_jose/src/jwk/diff/key_params/oct.rs deleted file mode 100644 index a1d18c5d39..0000000000 --- a/identity_jose/src/jwk/diff/key_params/oct.rs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2020-2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 -use super::Deserialize; -use super::Diff; -use super::DiffResult; -use super::DiffString; -use super::Serialize; - -use crate::jwk::JwkParamsOct; - -/// Represents the difference of two [`JwkParamsOct`]. -#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)] -pub struct DiffJwkParamsOct { - pub k: DiffString, // Key value -} - -impl Diff for JwkParamsOct { - type Type = DiffJwkParamsOct; - - /// Finds the difference between `self` and `other` and returns the result as - /// a [`DiffJwkParamsOct`]. - fn diff(&self, other: &Self) -> identity_core::diff::Result { - Ok(DiffJwkParamsOct { - k: self.k.diff(&other.k)?, - }) - } - - fn merge(&self, diff: Self::Type) -> identity_core::diff::Result { - let k: String = self.k.merge(diff.k)?; - Ok(Self { k }) - } - - fn from_diff(diff: Self::Type) -> identity_core::diff::Result { - let k: String = Diff::from_diff(diff.k)?; - Ok(Self { k }) - } - - /// Converts the [`JwkParamsOct`] into [`DiffJwkParamsOct`]. - fn into_diff(mut self) -> DiffResult { - self.take_diff() - } -} - -impl JwkParamsOct { - /// Converts a [`&mut JwkParamsOct`](JwkParamsOct) to [`DiffJwkParamsOct`] leaving - /// empty strings as public parameters in `self`. - /// - /// - /// # Motivation - /// [`JwkParamsOct`] cannot directly be destructured because of [zeroize(drop)] - /// hence this provides workaround to enable a cheap implementation of `into_diff`. - pub(super) fn take_diff(&mut self) -> DiffResult { - let k: String = { - let JwkParamsOct { ref mut k } = self; - std::mem::take(k) - }; - - Ok(DiffJwkParamsOct { k: k.into_diff()? }) - } -} diff --git a/identity_jose/src/jwk/diff/key_params/okp.rs b/identity_jose/src/jwk/diff/key_params/okp.rs deleted file mode 100644 index 3162ccf404..0000000000 --- a/identity_jose/src/jwk/diff/key_params/okp.rs +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2020-2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 -use super::Deserialize; -use super::Diff; -use super::DiffResult; -use super::DiffString; -use super::Serialize; - -use crate::jwk::JwkParamsOkp; -/// Represents the difference of two [`JwkParamsOkps`](JwkParamsOkp) without any private -/// components. -#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)] -pub struct DiffJwkParamsOkp { - pub crv: DiffString, // Key SubType - pub x: DiffString, // Public Key -} - -impl Diff for JwkParamsOkp { - type Type = DiffJwkParamsOkp; - - /// Finds the difference between `self` and `other` and returns the result as - /// a [`DiffJwkParamsOkp`]. - /// - /// # Errors - /// Errors if either `self` or `other` contains private components. - fn diff(&self, other: &Self) -> DiffResult { - if !(self.is_public() && other.is_public()) { - return Err(identity_core::diff::Error::DiffError( - "cannot diff jwk okp params with private components".to_owned(), - )); - } - Ok(DiffJwkParamsOkp { - crv: self.crv.diff(&other.crv)?, - x: self.x.diff(&other.x)?, - }) - } - - fn merge(&self, diff: Self::Type) -> DiffResult { - let crv = self.crv.merge(diff.crv)?; - let x = self.x.merge(diff.x)?; - Ok(JwkParamsOkp { crv, x, d: None }) - } - - fn from_diff(diff: Self::Type) -> DiffResult { - let DiffJwkParamsOkp { crv, x } = diff; - Ok(Self { - crv: Diff::from_diff(crv)?, - x: Diff::from_diff(x)?, - d: None, - }) - } - - /// Converts the [`JwkParamsOkp`] into [`DiffJwkParamsOkp`]. - /// - /// # Errors - /// Errors if the params contain a private component. - fn into_diff(mut self) -> DiffResult { - self.take_diff() - } -} - -impl JwkParamsOkp { - /// Obtain a [`DiffJwkParamsOkp`] from a [`&mut JwkParamsOkp`](JwkParamsOkp) leaving - /// empty strings as public parameters in `self`. - /// - /// # Errors - /// Errors immediately if the params contain a private component. - /// - /// # Motivation - /// [`JwkParamsOkp`] cannot directly be destructured because of [zeroize(drop)] - /// hence this provides workaround to enable a cheap implementation of `into_diff`. - pub(super) fn take_diff(&mut self) -> DiffResult { - if !self.is_public() { - return Err(identity_core::diff::Error::ConversionError( - "cannot convert jwk okp params with private components to diff".to_owned(), - )); - } - - let (crv, x): (String, String) = { - // Cannot directly destructure because of #[zeroize(drop)] - let JwkParamsOkp { - ref mut crv, ref mut x, .. - } = self; - (std::mem::take(crv), std::mem::take(x)) - }; - - Ok(DiffJwkParamsOkp { - crv: crv.into_diff()?, - x: x.into_diff()?, - }) - } -} diff --git a/identity_jose/src/jwk/diff/key_params/rsa.rs b/identity_jose/src/jwk/diff/key_params/rsa.rs deleted file mode 100644 index 01376374b3..0000000000 --- a/identity_jose/src/jwk/diff/key_params/rsa.rs +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright 2020-2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 -use super::Deserialize; -use super::Diff; -use super::DiffResult; -use super::DiffString; -use super::Serialize; - -use crate::jwk::JwkParamsRsa; - -/// Represents the difference of two [`JwkParamsRsa`](JwkParamsRsa) without any private -/// components. -#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)] -pub struct DiffJwkParamsRsa { - pub n: DiffString, // Modulus - pub e: DiffString, // Exponent -} - -impl Diff for JwkParamsRsa { - type Type = DiffJwkParamsRsa; - - /// Finds the difference between `self` and `other` and returns the result as - /// a [`DiffJwkParamsRsa`]. - /// - /// # Errors - /// Errors if either `self` or `other` contains private components. - fn diff(&self, other: &Self) -> DiffResult { - if !(self.is_public() && other.is_public()) { - return Err(identity_core::diff::Error::DiffError( - "cannot diff jwk rsa params with private components".to_owned(), - )); - } - Ok(DiffJwkParamsRsa { - n: self.n.diff(&other.n)?, - e: self.e.diff(&other.e)?, - }) - } - - fn merge(&self, diff: Self::Type) -> DiffResult { - let n = self.n.merge(diff.n)?; - let e = self.e.merge(diff.e)?; - Ok(JwkParamsRsa { - n, - e, - d: None, - p: None, - q: None, - dp: None, - dq: None, - qi: None, - oth: None, - }) - } - - fn from_diff(diff: Self::Type) -> DiffResult { - let DiffJwkParamsRsa { n, e } = diff; - Ok(JwkParamsRsa { - n: Diff::from_diff(n)?, - e: Diff::from_diff(e)?, - d: None, - p: None, - q: None, - dp: None, - dq: None, - qi: None, - oth: None, - }) - } - - /// Converts the [`JwkParamsRsa`] into [`DiffJwkParamsRsa`]. - /// - /// # Errors - /// Errors if the params contain a private component. - fn into_diff(mut self) -> DiffResult { - self.take_diff() - } -} - -impl JwkParamsRsa { - /// Obtain a [`DiffJwkParamsRsa`] from a [`&mut JwkParamsRsa`](JwkParamsRsa) leaving - /// empty strings as public parameters in `self`. - /// - /// # Errors - /// Errors immediately if the params contain a private component. - /// - /// # Motivation - /// [`JwkParamsRsa`] cannot directly be destructured because of [zeroize(drop)] - /// hence this provides workaround to enable a cheap implementation of `into_diff`. - pub(super) fn take_diff(&mut self) -> DiffResult { - if !self.is_public() { - return Err(identity_core::diff::Error::ConversionError( - "cannot convert jwk rsa params with private components to diff".to_owned(), - )); - } - - let (n, e): (String, String) = { - // Cannot directly destructure because of #[zeroize(drop)] - let JwkParamsRsa { - ref mut n, ref mut e, .. - } = self; - (std::mem::take(n), std::mem::take(e)) - }; - - Ok(DiffJwkParamsRsa { - n: n.into_diff()?, - e: e.into_diff()?, - }) - } -} diff --git a/identity_jose/src/jwk/diff/key_type.rs b/identity_jose/src/jwk/diff/key_type.rs deleted file mode 100644 index e77e5cacb7..0000000000 --- a/identity_jose/src/jwk/diff/key_type.rs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2020-2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -use identity_core::diff::Diff; -use identity_core::diff::Result; -use serde::Deserialize; -use serde::Serialize; - -use crate::jwk::JwkType; - -#[derive(Clone, Copy, Debug, PartialEq, Deserialize, Serialize)] -pub struct DiffJwkType(#[serde(skip_serializing_if = "Option::is_none")] Option); - -impl Diff for JwkType { - type Type = DiffJwkType; - - fn diff(&self, other: &Self) -> Result { - if self == other { - Ok(DiffJwkType(None)) - } else { - Ok(DiffJwkType(Some(*other))) - } - } - - fn merge(&self, diff: Self::Type) -> Result { - Ok(diff.0.unwrap_or(*self)) - } - - fn from_diff(diff: Self::Type) -> Result { - diff - .0 - .ok_or_else(|| identity_core::diff::Error::ConversionError("cannot convert from empty diff".to_owned())) - } - - fn into_diff(self) -> Result { - Ok(DiffJwkType(Some(self))) - } -} diff --git a/identity_jose/src/jwk/diff/key_use.rs b/identity_jose/src/jwk/diff/key_use.rs deleted file mode 100644 index 18228f7b73..0000000000 --- a/identity_jose/src/jwk/diff/key_use.rs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2020-2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -use identity_core::diff::Diff; -use identity_core::diff::Result; -use serde::Deserialize; -use serde::Serialize; - -use crate::jwk::JwkUse; - -#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, Copy)] -pub struct DiffJwkUse(#[serde(skip_serializing_if = "Option::is_none")] Option); - -impl Diff for JwkUse { - type Type = DiffJwkUse; - - fn diff(&self, other: &Self) -> Result { - if self == other { - Ok(DiffJwkUse(None)) - } else { - Ok(DiffJwkUse(Some(*other))) - } - } - - fn merge(&self, diff: Self::Type) -> Result { - Ok(diff.0.unwrap_or(*self)) - } - - fn from_diff(diff: Self::Type) -> Result { - diff - .0 - .ok_or_else(|| identity_core::diff::Error::ConversionError("cannot convert from empty diff".to_owned())) - } - - fn into_diff(self) -> Result { - Ok(DiffJwkUse(Some(self))) - } -} diff --git a/identity_jose/src/jwk/diff/mod.rs b/identity_jose/src/jwk/diff/mod.rs deleted file mode 100644 index b2c938a6f4..0000000000 --- a/identity_jose/src/jwk/diff/mod.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2020-2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 -//! Provides a [`Diff`](::identity_core::diff::Diff) implementation for [`Jwk`](crate::jwk::Jwk). -//! -//! # Warning: This module has not been tested. -#![allow(deprecated)] -mod key; -mod key_operations; -mod key_params; -mod key_type; -mod key_use; -pub use key::*; -pub use key_operations::*; -pub use key_params::*; -pub use key_type::*; -pub use key_use::*; diff --git a/identity_jose/src/jwk/mod.rs b/identity_jose/src/jwk/mod.rs index 096c4576b3..695d52b558 100644 --- a/identity_jose/src/jwk/mod.rs +++ b/identity_jose/src/jwk/mod.rs @@ -3,9 +3,6 @@ //! JSON Web Keys ([JWK](https://tools.ietf.org/html/rfc7517)) mod curve; -#[cfg(feature = "diff")] -#[deprecated(since = "0.5.0", note = "diff chain features are slated for removal")] -pub mod diff; mod key; mod key_operation; mod key_params; diff --git a/identity_verification/src/verification_method/diff/diff_method.rs b/identity_verification/src/verification_method/diff/diff_method.rs deleted file mode 100644 index 736a1cb30f..0000000000 --- a/identity_verification/src/verification_method/diff/diff_method.rs +++ /dev/null @@ -1,399 +0,0 @@ -// Copyright 2020-2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -use serde::Deserialize; -use serde::Serialize; - -use identity_core::common::Object; -use identity_core::diff::Diff; -use identity_core::diff::Error; -use identity_core::diff::Result; - -use super::method_data::DiffMethodData; -use crate::verification_method::MethodBuilder; -use crate::verification_method::MethodData; -use crate::verification_method::MethodType; -use crate::verification_method::VerificationMethod; -use identity_did::CoreDID; -use identity_did::DIDUrl; - -#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] -pub struct DiffMethod { - #[serde(skip_serializing_if = "Option::is_none")] - id: Option<::Type>, - #[serde(skip_serializing_if = "Option::is_none")] - controller: Option<::Type>, - #[serde(rename = "type", skip_serializing_if = "Option::is_none")] - type_: Option, - #[serde(skip_serializing_if = "Option::is_none")] - data: Option, - #[serde(skip_serializing_if = "Option::is_none")] - properties: Option<::Type>, -} - -impl Diff for VerificationMethod { - type Type = DiffMethod; - - fn diff(&self, other: &Self) -> Result { - Ok(DiffMethod { - id: if self.id() == other.id() { - None - } else { - Some(self.id().diff(other.id())?) - }, - controller: if self.controller() == other.controller() { - None - } else { - Some(self.controller().diff(other.controller())?) - }, - type_: if self.type_() == other.type_() { - None - } else { - Some(self.type_().diff(other.type_())?) - }, - data: if self.data() == other.data() { - None - } else { - Some(self.data().diff(other.data())?) - }, - properties: if self.properties() == other.properties() { - None - } else { - Some(self.properties().diff(other.properties())?) - }, - }) - } - - fn merge(&self, diff: Self::Type) -> Result { - let id: DIDUrl = diff - .id - .map(|value| self.id().merge(value)) - .transpose()? - .unwrap_or_else(|| self.id().clone()); - - let controller: CoreDID = diff - .controller - .map(|value| self.controller().merge(value)) - .transpose()? - .unwrap_or_else(|| self.controller().clone()); - - let data: MethodData = diff - .data - .map(|value| self.data().merge(value)) - .transpose()? - .unwrap_or_else(|| self.data().clone()); - - let type_: MethodType = diff - .type_ - .map(|value| self.type_().merge(value)) - .transpose()? - .unwrap_or_else(|| self.type_().clone()); - - let properties: Object = diff - .properties - .map(|value| self.properties().merge(value)) - .transpose()? - .unwrap_or_else(|| self.properties().clone()); - - // Use builder to enforce invariants. - MethodBuilder::new(properties) - .id(id) - .controller(controller) - .type_(type_) - .data(data) - .build() - .map_err(Error::merge) - } - - fn from_diff(diff: Self::Type) -> Result { - let id: DIDUrl = diff - .id - .map(Diff::from_diff) - .transpose()? - .ok_or_else(|| Error::convert("Missing field `method.id`"))?; - - let controller: CoreDID = diff - .controller - .map(Diff::from_diff) - .transpose()? - .ok_or_else(|| Error::convert("Missing field `method.controller`"))?; - - let type_: MethodType = diff - .type_ - .map(Diff::from_diff) - .transpose()? - .ok_or_else(|| Error::convert("Missing field `method.type`"))?; - - let data: MethodData = diff - .data - .map(Diff::from_diff) - .transpose()? - .ok_or_else(|| Error::convert("Missing field `method.data`"))?; - - let properties: Object = diff.properties.map(Diff::from_diff).transpose()?.unwrap_or_default(); - - // Use builder to enforce invariants. - MethodBuilder::new(properties) - .id(id) - .controller(controller) - .type_(type_) - .data(data) - .build() - .map_err(Error::convert) - } - - fn into_diff(self) -> Result { - Ok(DiffMethod { - id: Some(self.id.into_diff()?), - controller: Some(self.controller.into_diff()?), - type_: Some(self.type_.into_diff()?), - data: Some(self.data.into_diff()?), - properties: if self.properties == Default::default() { - None - } else { - Some(self.properties.into_diff()?) - }, - }) - } -} - -#[cfg(test)] -mod test { - use identity_core::common::Object; - use identity_core::common::Value; - use identity_core::convert::FromJson; - use identity_core::convert::ToJson; - use identity_core::diff::DiffString; - - use super::*; - - fn test_method() -> VerificationMethod { - VerificationMethod::builder(Default::default()) - .id("did:example:123#key".parse().unwrap()) - .controller("did:example:123".parse().unwrap()) - .type_(MethodType::ED25519_VERIFICATION_KEY_2018) - .data(MethodData::PublicKeyMultibase("".into())) - .build() - .unwrap() - } - - #[test] - fn test_diff() { - let method = test_method(); - let new = method.clone(); - let diff = method.diff(&new).unwrap(); - assert!(diff.id.is_none()); - assert!(diff.controller.is_none()); - assert!(diff.data.is_none()); - assert!(diff.type_.is_none()); - assert!(diff.properties.is_none()); - } - - #[test] - fn test_properties() { - let method = test_method(); - let mut new = method.clone(); - - // add property - let mut properties = Object::new(); - properties.insert("key1".to_string(), Value::String("value1".to_string())); - *new.properties_mut() = properties; - - let diff = method.diff(&new).unwrap(); - assert!(diff.id.is_none()); - assert!(diff.controller.is_none()); - assert!(diff.data.is_none()); - assert!(diff.type_.is_none()); - - let merge = method.merge(diff).unwrap(); - assert_eq!(merge, new); - - // add another property - let mut properties = Object::new(); - properties.insert("key2".to_string(), Value::String("value1".to_string())); - *new.properties_mut() = properties; - - let diff = method.diff(&new).unwrap(); - assert!(diff.id.is_none()); - assert!(diff.controller.is_none()); - assert!(diff.data.is_none()); - assert!(diff.type_.is_none()); - - let merge = method.merge(diff).unwrap(); - assert_eq!(merge, new); - - // change property - let mut properties = Object::new(); - properties.insert("key2".to_string(), Value::String("value2".to_string())); - *new.properties_mut() = properties; - - let diff = method.diff(&new).unwrap(); - assert!(diff.id.is_none()); - assert!(diff.controller.is_none()); - assert!(diff.data.is_none()); - assert!(diff.type_.is_none()); - - let merge = method.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_id() { - let method = test_method(); - let mut new = method.clone(); - new.set_id("did:diff:123#key".parse().unwrap()).unwrap(); - - let diff = method.diff(&new).unwrap(); - assert!(diff.controller.is_none()); - assert!(diff.data.is_none()); - assert!(diff.type_.is_none()); - assert!(diff.properties.is_none()); - assert_eq!(diff.id, Some(DiffString(Some("did:diff:123#key".to_string())))); - - let merge = method.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_controller() { - let method = test_method(); - let mut new = method.clone(); - *new.controller_mut() = "did:diff:123".parse().unwrap(); - - let diff = method.diff(&new).unwrap(); - assert!(diff.id.is_none()); - assert!(diff.data.is_none()); - assert!(diff.type_.is_none()); - assert!(diff.properties.is_none()); - assert_eq!(diff.controller, Some(DiffString(Some("did:diff:123".to_string())))); - - let merge = method.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_type() { - let method = test_method(); - let mut new = method.clone(); - *new.type_mut() = MethodType::X25519_KEY_AGREEMENT_KEY_2019; - - let diff = method.diff(&new).unwrap(); - assert!(diff.id.is_none()); - assert!(diff.controller.is_none()); - assert!(diff.data.is_none()); - assert!(diff.properties.is_none()); - assert_eq!(diff.type_, Some(MethodType::X25519_KEY_AGREEMENT_KEY_2019)); - - let merge = method.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_data_base58() { - let method = test_method(); - let mut new = method.clone(); - *new.data_mut() = MethodData::PublicKeyBase58("diff".into()); - - let diff = method.diff(&new).unwrap(); - assert!(diff.id.is_none()); - assert!(diff.controller.is_none()); - assert!(diff.type_.is_none()); - assert!(diff.properties.is_none()); - assert_eq!( - diff.data, - Some(DiffMethodData::PublicKeyBase58(Some(DiffString(Some( - "diff".to_string() - ))))) - ); - - let merge = method.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_data_multibase() { - let method = test_method(); - let mut new = method.clone(); - *new.data_mut() = MethodData::PublicKeyMultibase("diff".into()); - - let diff = method.diff(&new).unwrap(); - assert!(diff.id.is_none()); - assert!(diff.controller.is_none()); - assert!(diff.type_.is_none()); - assert!(diff.properties.is_none()); - assert_eq!( - diff.data, - Some(DiffMethodData::PublicKeyMultibase(Some(DiffString(Some( - "diff".to_string() - ))))) - ); - - let merge = method.merge(diff).unwrap(); - assert_eq!(merge, new); - } - - #[test] - fn test_from_diff() { - let method = test_method(); - let mut new = method.clone(); - - let diff = method.diff(&new).unwrap(); - let diff_method = VerificationMethod::from_diff(diff); - assert!(diff_method.is_err()); - - // add property - let mut properties = Object::new(); - properties.insert("key1".to_string(), Value::String("value1".to_string())); - *new.properties_mut() = properties; - - let diff = method.diff(&new).unwrap(); - let diff_method = VerificationMethod::from_diff(diff); - assert!(diff_method.is_err()); - - // add id - new.set_id("did:diff:123#key".parse().unwrap()).unwrap(); - let diff = method.diff(&new).unwrap(); - let diff_method = VerificationMethod::from_diff(diff); - assert!(diff_method.is_err()); - - // add controller - *new.controller_mut() = "did:diff:123".parse().unwrap(); - let diff = method.diff(&new).unwrap(); - let diff_method = VerificationMethod::from_diff(diff); - assert!(diff_method.is_err()); - - // add type_ - *new.type_mut() = MethodType::X25519_KEY_AGREEMENT_KEY_2019; - let diff = method.diff(&new).unwrap(); - let diff_method = VerificationMethod::from_diff(diff); - assert!(diff_method.is_err()); - - // add data - *new.data_mut() = MethodData::PublicKeyMultibase("diff".into()); - let diff = method.diff(&new).unwrap(); - let diff_method = VerificationMethod::from_diff(diff.clone()); - assert!(diff_method.is_ok()); - let diff_method = diff_method.unwrap(); - assert_eq!(diff_method, new); - - let merge = method.merge(diff.clone()).unwrap(); - assert_eq!(merge, new); - - assert_eq!(new.into_diff().unwrap(), diff); - } - - #[test] - fn test_from_into_diff() { - let method: VerificationMethod = test_method(); - - let diff: DiffMethod = method.clone().into_diff().unwrap(); - let new: VerificationMethod = VerificationMethod::from_diff(diff.clone()).unwrap(); - assert_eq!(method, new); - - let ser: String = diff.to_json().unwrap(); - let de: DiffMethod = DiffMethod::from_json(&ser).unwrap(); - assert_eq!(de, diff); - let from: VerificationMethod = VerificationMethod::from_diff(de).unwrap(); - assert_eq!(method, from); - } -} diff --git a/identity_verification/src/verification_method/diff/method_data.rs b/identity_verification/src/verification_method/diff/method_data.rs deleted file mode 100644 index 2900f8add1..0000000000 --- a/identity_verification/src/verification_method/diff/method_data.rs +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2020-2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -use identity_core::diff::Diff; -use identity_core::diff::DiffString; -use identity_core::diff::Result; - -use crate::jwk::diff::DiffJwk; -use crate::verification_method::MethodData; - -// TODO: Test the `PublicKeyJwk` variant. -#[allow(clippy::large_enum_variant)] -#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] -pub enum DiffMethodData { - PublicKeyMultibase(#[serde(skip_serializing_if = "Option::is_none")] Option), - PublicKeyBase58(#[serde(skip_serializing_if = "Option::is_none")] Option), - PublicKeyJwk(#[serde(skip_serializing_if = "Option::is_none")] Option), -} - -impl Diff for MethodData { - type Type = DiffMethodData; - - fn diff(&self, other: &Self) -> Result { - match (self, other) { - (Self::PublicKeyJwk(a), Self::PublicKeyJwk(b)) if a == b => Ok(DiffMethodData::PublicKeyJwk(None)), - (Self::PublicKeyJwk(a), Self::PublicKeyJwk(b)) => a.diff(b).map(Some).map(DiffMethodData::PublicKeyJwk), - (Self::PublicKeyMultibase(a), Self::PublicKeyMultibase(b)) if a == b => { - Ok(DiffMethodData::PublicKeyMultibase(None)) - } - (Self::PublicKeyMultibase(a), Self::PublicKeyMultibase(b)) => { - a.diff(b).map(Some).map(DiffMethodData::PublicKeyMultibase) - } - (Self::PublicKeyBase58(a), Self::PublicKeyBase58(b)) if a == b => Ok(DiffMethodData::PublicKeyBase58(None)), - (Self::PublicKeyBase58(a), Self::PublicKeyBase58(b)) => a.diff(b).map(Some).map(DiffMethodData::PublicKeyBase58), - (_, _) => other.clone().into_diff(), - } - } - - fn merge(&self, diff: Self::Type) -> Result { - match (self, diff) { - (Self::PublicKeyJwk(a), DiffMethodData::PublicKeyJwk(Some(b))) => a.merge(b).map(Self::PublicKeyJwk), - (Self::PublicKeyJwk(a), DiffMethodData::PublicKeyJwk(None)) => Ok(Self::PublicKeyJwk(a.clone())), - (Self::PublicKeyMultibase(a), DiffMethodData::PublicKeyMultibase(Some(b))) => { - a.merge(b).map(Self::PublicKeyMultibase) - } - (Self::PublicKeyMultibase(a), DiffMethodData::PublicKeyMultibase(None)) => { - Ok(Self::PublicKeyMultibase(a.clone())) - } - (Self::PublicKeyBase58(a), DiffMethodData::PublicKeyBase58(Some(b))) => a.merge(b).map(Self::PublicKeyBase58), - (Self::PublicKeyBase58(a), DiffMethodData::PublicKeyBase58(None)) => Ok(Self::PublicKeyBase58(a.clone())), - (_, diff) => Self::from_diff(diff), - } - } - - fn from_diff(diff: Self::Type) -> Result { - match diff { - DiffMethodData::PublicKeyMultibase(Some(value)) => Diff::from_diff(value).map(Self::PublicKeyMultibase), - DiffMethodData::PublicKeyMultibase(None) => Ok(Self::PublicKeyMultibase(Default::default())), - DiffMethodData::PublicKeyBase58(Some(value)) => Diff::from_diff(value).map(Self::PublicKeyBase58), - DiffMethodData::PublicKeyBase58(None) => Ok(Self::PublicKeyBase58(Default::default())), - DiffMethodData::PublicKeyJwk(Some(value)) => Diff::from_diff(value).map(Self::PublicKeyJwk), - DiffMethodData::PublicKeyJwk(None) => Err(identity_core::diff::Error::ConversionError( - "cannot convert empty diff to jwk method data".to_owned(), - )), - } - } - - fn into_diff(self) -> Result { - match self { - Self::PublicKeyJwk(value) => value.into_diff().map(Some).map(DiffMethodData::PublicKeyJwk), - Self::PublicKeyMultibase(value) => value.into_diff().map(Some).map(DiffMethodData::PublicKeyMultibase), - Self::PublicKeyBase58(value) => value.into_diff().map(Some).map(DiffMethodData::PublicKeyBase58), - } - } -} diff --git a/identity_verification/src/verification_method/diff/method_ref.rs b/identity_verification/src/verification_method/diff/method_ref.rs deleted file mode 100644 index 3bca0e81bc..0000000000 --- a/identity_verification/src/verification_method/diff/method_ref.rs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2020-2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -use identity_core::diff::Diff; -use identity_core::diff::Error; -use identity_core::diff::Result; -use serde::Deserialize; -use serde::Serialize; - -use super::diff_method::DiffMethod; -use crate::verification_method::MethodRef; - -use identity_did::DIDUrl; - -#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] -#[serde(untagged)] -pub enum DiffMethodRef { - Embed(#[serde(skip_serializing_if = "Option::is_none")] Option), - Refer(#[serde(skip_serializing_if = "Option::is_none")] Option<::Type>), -} - -impl Diff for MethodRef { - type Type = DiffMethodRef; - - fn diff(&self, other: &Self) -> Result { - match (self, other) { - (Self::Embed(a), Self::Embed(b)) if a == b => Ok(DiffMethodRef::Embed(None)), - (Self::Embed(a), Self::Embed(b)) => a.diff(b).map(Some).map(DiffMethodRef::Embed), - (Self::Refer(a), Self::Refer(b)) if a == b => Ok(DiffMethodRef::Refer(None)), - (Self::Refer(a), Self::Refer(b)) => a.diff(b).map(Some).map(DiffMethodRef::Refer), - (_, _) => other.clone().into_diff(), - } - } - - fn merge(&self, diff: Self::Type) -> Result { - match (self, diff) { - (Self::Embed(a), DiffMethodRef::Embed(Some(b))) => a.merge(b).map(Self::Embed), - (Self::Embed(a), DiffMethodRef::Embed(None)) => Ok(Self::Embed(a.clone())), - (Self::Refer(a), DiffMethodRef::Refer(Some(b))) => a.merge(b).map(Self::Refer), - (Self::Refer(a), DiffMethodRef::Refer(None)) => Ok(Self::Refer(a.clone())), - (_, diff) => Self::from_diff(diff), - } - } - - fn from_diff(diff: Self::Type) -> Result { - match diff { - DiffMethodRef::Embed(Some(value)) => Diff::from_diff(value).map(Self::Embed), - DiffMethodRef::Embed(None) => Err(Error::convert("Invalid MethodRef Diff")), - DiffMethodRef::Refer(Some(value)) => Diff::from_diff(value).map(Self::Refer), - DiffMethodRef::Refer(None) => Err(Error::convert("Invalid MethodRef Diff")), - } - } - - fn into_diff(self) -> Result { - match self { - Self::Embed(value) => value.into_diff().map(Some).map(DiffMethodRef::Embed), - Self::Refer(value) => value.to_string().into_diff().map(Some).map(DiffMethodRef::Refer), - } - } -} diff --git a/identity_verification/src/verification_method/diff/method_type.rs b/identity_verification/src/verification_method/diff/method_type.rs deleted file mode 100644 index 34eb80fe0c..0000000000 --- a/identity_verification/src/verification_method/diff/method_type.rs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2020-2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -use identity_core::diff::Diff; -use identity_core::diff::Result; - -use crate::verification_method::MethodType; - -impl Diff for MethodType { - type Type = MethodType; - - fn diff(&self, other: &Self) -> Result { - Ok(other.clone()) - } - - fn merge(&self, diff: Self::Type) -> Result { - Ok(diff) - } - - fn from_diff(diff: Self::Type) -> Result { - Ok(diff) - } - - fn into_diff(self) -> Result { - Ok(self) - } -} diff --git a/identity_verification/src/verification_method/diff/mod.rs b/identity_verification/src/verification_method/diff/mod.rs deleted file mode 100644 index 37c2751da6..0000000000 --- a/identity_verification/src/verification_method/diff/mod.rs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2020-2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -mod diff_method; -mod method_data; -mod method_ref; -mod method_type; - -pub use self::diff_method::DiffMethod; -pub use self::method_data::DiffMethodData; -pub use self::method_ref::DiffMethodRef; diff --git a/identity_verification/src/verification_method/mod.rs b/identity_verification/src/verification_method/mod.rs index c8eb99d177..68efda6946 100644 --- a/identity_verification/src/verification_method/mod.rs +++ b/identity_verification/src/verification_method/mod.rs @@ -7,9 +7,6 @@ //! `identity_iota_core_legacy` crate. mod builder; -#[cfg(feature = "diff")] -#[deprecated(since = "0.5.0", note = "diff chain features are slated for removal")] -pub mod diff; mod material; mod method; mod method_ref;