Skip to content

Commit

Permalink
Add missing constructors and setters/getters
Browse files Browse the repository at this point in the history
  • Loading branch information
sbihel committed Oct 20, 2023
1 parent a95fc3c commit 0612b6c
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/core/profiles/isomdl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,39 @@ impl CredentialMetadataProfile for Metadata {
pub struct Offer {
doctype: DocType,
}

impl Offer {
pub fn new(doctype: DocType) -> Self {
Self { doctype }
}
field_getters_setters![
pub self [self] ["ISO mDL credential offer value"] {
set_doctype -> doctype[DocType],
}
];
}
impl CredentialOfferProfile for Offer {}

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct AuthorizationDetails {
doctype: DocType,
claims: Option<HashMap<Namespace, CredentialSubjectClaims>>,
}

impl AuthorizationDetails {
pub fn new(
doctype: DocType,
claims: Option<HashMap<Namespace, CredentialSubjectClaims>>,
) -> Self {
Self { doctype, claims }
}
field_getters_setters![
pub self [self] ["ISO mDL authorization details value"] {
set_doctype -> doctype[DocType],
set_claims -> claims[Option<HashMap<Namespace, CredentialSubjectClaims>>],
}
];
}
impl AuthorizationDetaislProfile for AuthorizationDetails {}

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
Expand Down Expand Up @@ -83,6 +109,17 @@ impl CredentialRequestProfile for Request {
pub struct Response {
credential: String,
}

impl Response {
pub fn new(credential: String) -> Self {
Self { credential }
}
field_getters_setters![
pub self [self] ["ISO mDL response value"] {
set_credential -> credential[String],
}
];
}
impl CredentialResponseProfile for Response {}

#[cfg(test)]
Expand Down
57 changes: 57 additions & 0 deletions src/core/profiles/w3c/ldp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,66 @@ impl CredentialMetadataProfile for Metadata {
pub struct Offer {
credential_definition: CredentialOfferDefinitionLD,
}

impl Offer {
pub fn new(credential_definition: CredentialOfferDefinitionLD) -> Self {
Self {
credential_definition,
}
}

field_getters_setters![
pub self [self] ["LD VC credential offer value"] {
set_credential_definition -> credential_definition[CredentialOfferDefinitionLD],
}
];
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct CredentialOfferDefinitionLD {
#[serde(rename = "@context")]
context: Vec<serde_json::Value>,
#[serde(flatten)]
credential_offer_definite: CredentialOfferDefinition,
}

impl CredentialOfferDefinitionLD {
pub fn new(
context: Vec<serde_json::Value>,
credential_offer_definite: CredentialOfferDefinition,
) -> Self {
Self {
context,
credential_offer_definite,
}
}

field_getters_setters![
pub self [self] ["LD VC credential offer definition value"] {
set_context -> context[Vec<serde_json::Value>],
set_credential_offer_definite -> credential_offer_definite[CredentialOfferDefinition],
}
];
}
impl CredentialOfferProfile for Offer {}

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct AuthorizationDetails {
credential_definition: CredentialDefinitionLD,
}

impl AuthorizationDetails {
pub fn new(credential_definition: CredentialDefinitionLD) -> Self {
Self {
credential_definition,
}
}

field_getters_setters![
pub self [self] ["LD VC authorization details value"] {
set_credential_definition -> credential_definition[CredentialDefinitionLD],
}
];
}
impl AuthorizationDetaislProfile for AuthorizationDetails {}

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
Expand All @@ -102,6 +149,12 @@ impl Request {
credential_definition,
}
}

field_getters_setters![
pub self [self] ["LD VC credential request value"] {
set_credential_definition -> credential_definition[CredentialDefinitionLD],
}
];
}
impl CredentialRequestProfile for Request {
type Response = Response;
Expand All @@ -113,6 +166,10 @@ pub struct Response {
}

impl Response {
pub fn new(credential: Credential) -> Self {
Self { credential }
}

field_getters_setters![
pub self [self] ["LD VC credential response value"] {
set_credential -> credential[Credential],
Expand Down

0 comments on commit 0612b6c

Please sign in to comment.