Skip to content

Commit

Permalink
mime-type adjustments hyperledger#820
Browse files Browse the repository at this point in the history
  • Loading branch information
SumantxD committed May 7, 2023
1 parent 81e1487 commit 2d02d80
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 17 deletions.
21 changes: 15 additions & 6 deletions messages/src/msg_fields/protocols/cred_issuance/mod.rs
Expand Up @@ -142,22 +142,31 @@ impl Serialize for CredentialPreviewMsgType {
}
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum AttrValue {
Plain {
value: String,
},
Encoded {
value: String,
#[serde(rename = "mime-type")]
mime_type: MaybeKnown<MimeType>,
},
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub struct CredentialAttr {
pub name: String,
pub value: String,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "mime-type")]
pub mime_type: Option<MimeType>,
pub value: AttrValue,
}

impl CredentialAttr {
pub fn new(name: String, value: String) -> Self {
pub fn new(name: String, value: AttrValue) -> Self {
Self {
name,
value,
mime_type: None,
}
}
}
Expand Down
43 changes: 32 additions & 11 deletions messages/src/msg_fields/protocols/present_proof/propose.rs
@@ -1,6 +1,7 @@
use std::str::FromStr;

use serde::{Deserialize, Serialize};
use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer};
use derive_more::From;

use crate::{
decorators::{thread::Thread, timing::Timing},
Expand Down Expand Up @@ -98,27 +99,37 @@ impl Serialize for PresentationPreviewMsgType {
}
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum AttrValue {
Plain {
#[serde(skip_serializing_if = "Option::is_none")]
value: Option<String>,
},
Encoded {
value: String,
#[serde(rename = "mime-type")]
mime_type: MaybeKnown<MimeType>,
},
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
pub struct PresentationAttr {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub cred_def_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "mime-type")]
pub mime_type: Option<MimeType>,
#[serde(skip_serializing_if = "Option::is_none")]
pub value: Option<String>,
pub value: AttrValue,
#[serde(skip_serializing_if = "Option::is_none")]
pub referent: Option<String>,
}


impl PresentationAttr {
pub fn new(name: String) -> Self {
pub fn new(name: String, value: AttrValue) -> Self {
Self {
name,
cred_def_id: None,
mime_type: None,
value: None,
value,
referent: None,
}
}
Expand Down Expand Up @@ -182,7 +193,12 @@ mod tests {

#[test]
fn test_minimal_propose_proof() {
let attribute = PresentationAttr::new("test_attribute_name".to_owned());
let attribute = PresentationAttr::new(
"test_attribute_name".to_owned(),
AttrValue::Plain {
value: Some("test_value".to_owned()),
},
);
let predicate = Predicate::new(
"test_predicate_name".to_owned(),
PredicateOperator::GreaterOrEqual,
Expand All @@ -202,7 +218,12 @@ mod tests {

#[test]
fn test_extended_propose_proof() {
let attribute = PresentationAttr::new("test_attribute_name".to_owned());
let attribute = PresentationAttr::new(
"test_attribute_name".to_owned(),
AttrValue::Plain {
value: Some("test_value".to_owned()),
},
);
let predicate = Predicate::new(
"test_predicate_name".to_owned(),
PredicateOperator::GreaterOrEqual,
Expand Down

0 comments on commit 2d02d80

Please sign in to comment.