ssi_data_integrity/any/
signature_options.rs1use serde::Deserialize;
2use ssi_core::JsonPointerBuf;
3use ssi_di_sd_primitives::HmacShaAnyKey;
4use ssi_verification_methods::multikey::MultikeyPair;
5
6#[derive(Debug, Default, Deserialize)]
7#[serde(rename_all = "camelCase")]
8#[non_exhaustive]
9pub struct AnySignatureOptions {
10 pub mandatory_pointers: Vec<JsonPointerBuf>,
11
12 #[serde(rename = "hmacKeyString")]
13 pub hmac_key: Option<HmacShaAnyKey>,
14
15 pub key_pair: Option<MultikeyPair>,
16
17 #[cfg(all(feature = "w3c", feature = "bbs"))]
18 #[serde(default)]
19 pub feature_option: ssi_data_integrity_suites::bbs_2023::FeatureOption,
20
21 #[cfg(all(feature = "w3c", feature = "bbs"))]
22 pub commitment_with_proof: Option<Vec<u8>>,
23}
24
25impl From<AnySignatureOptions> for () {
26 fn from(_value: AnySignatureOptions) -> Self {}
27}
28
29impl From<()> for AnySignatureOptions {
30 fn from(_value: ()) -> Self {
31 AnySignatureOptions::default()
32 }
33}
34
35#[cfg(all(feature = "w3c", feature = "bbs"))]
36impl TryFrom<AnySignatureOptions> for ssi_data_integrity_suites::bbs_2023::Bbs2023SignatureOptions {
37 type Error = ssi_data_integrity_core::suite::ConfigurationError;
38
39 fn try_from(o: AnySignatureOptions) -> Result<Self, Self::Error> {
40 Ok(Self {
41 mandatory_pointers: o.mandatory_pointers,
42 feature_option: o.feature_option,
43 commitment_with_proof: o.commitment_with_proof,
44 hmac_key: o
45 .hmac_key
46 .map(HmacShaAnyKey::into_sha256)
47 .transpose()
48 .map_err(|_| {
49 ssi_data_integrity_core::suite::ConfigurationError::invalid_option("hmacKey")
50 })?,
51 })
52 }
53}
54
55#[cfg(all(feature = "w3c", feature = "bbs"))]
56impl From<ssi_data_integrity_suites::bbs_2023::Bbs2023SignatureOptions> for AnySignatureOptions {
57 fn from(value: ssi_data_integrity_suites::bbs_2023::Bbs2023SignatureOptions) -> Self {
58 Self {
59 mandatory_pointers: value.mandatory_pointers,
60 feature_option: value.feature_option,
61 commitment_with_proof: value.commitment_with_proof,
62 hmac_key: value.hmac_key.map(HmacShaAnyKey::Sha256),
63 ..Default::default()
64 }
65 }
66}
67
68#[cfg(all(feature = "w3c", feature = "secp256r1"))]
69impl From<AnySignatureOptions> for ssi_data_integrity_suites::ecdsa_sd_2023::SignatureOptions {
70 fn from(o: AnySignatureOptions) -> Self {
71 Self {
72 mandatory_pointers: o.mandatory_pointers,
73 hmac_key: o.hmac_key,
74 key_pair: o.key_pair,
75 }
76 }
77}
78
79#[cfg(all(feature = "w3c", feature = "secp256r1"))]
80impl From<ssi_data_integrity_suites::ecdsa_sd_2023::SignatureOptions> for AnySignatureOptions {
81 fn from(value: ssi_data_integrity_suites::ecdsa_sd_2023::SignatureOptions) -> Self {
82 Self {
83 mandatory_pointers: value.mandatory_pointers,
84 hmac_key: value.hmac_key,
85 key_pair: value.key_pair,
86 ..Default::default()
87 }
88 }
89}