sdk_common/src/models/metadata_role_confidential.rs

153 lines
6.6 KiB
Rust

use serde::{Deserialize, Serialize};
use super::{
key_encryption::KeyEncryption, metadata::MetaData,
pcd_item_enc_attribute_role_confidential::PcdItemEncAttributeRoleConfidential,
};
#[derive(Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MetadataRoleConfidential {
pub meta_data: MetaData,
}
impl MetadataRoleConfidential {
pub fn new(meta_data: MetaData) -> Self {
MetadataRoleConfidential { meta_data }
}
pub fn display_info(&self) {
println!("MetadataRoleConfidential:");
// Assuming MetaData has a display_info method
self.meta_data.display_info(); // Display information for `meta_data`
}
pub fn enc_list(&self) -> Vec<PcdItemEncAttributeRoleConfidential> {
let mut enc_attribute_list: Vec<PcdItemEncAttributeRoleConfidential> = Vec::new();
// tag_list
let mut enc_attribute_tag_list_key =
KeyEncryption::new(Some("tag_list".to_owned()), None, None);
if let Ok(_new) = enc_attribute_tag_list_key.key_new_random() {
let enc_attribute_tag_list = PcdItemEncAttributeRoleConfidential::new(
"tag_list".to_owned(),
enc_attribute_tag_list_key.enc_vec_string(self.meta_data.tag_list.clone()),
enc_attribute_tag_list_key,
);
enc_attribute_list.push(enc_attribute_tag_list);
}
// zone_list
let mut enc_attribute_zone_list_key =
KeyEncryption::new(Some("zone_list".to_owned()), None, None);
if let Ok(_new) = enc_attribute_zone_list_key.key_new_random() {
let enc_attribute_zone_list = PcdItemEncAttributeRoleConfidential::new(
"zone_list".to_owned(),
enc_attribute_zone_list_key.enc_vec_string(self.meta_data.zone_list.clone()),
enc_attribute_zone_list_key,
);
enc_attribute_list.push(enc_attribute_zone_list);
}
// label_list
let mut enc_attribute_label_list_key =
KeyEncryption::new(Some("label_list".to_owned()), None, None);
if let Ok(_new) = enc_attribute_label_list_key.key_new_random() {
let enc_attribute_label_list = PcdItemEncAttributeRoleConfidential::new(
"label_list".to_owned(),
enc_attribute_label_list_key.enc_vec_string(self.meta_data.label_list.clone()),
enc_attribute_label_list_key,
);
enc_attribute_list.push(enc_attribute_label_list);
}
// ref_list
let mut enc_attribute_ref_list_key =
KeyEncryption::new(Some("ref_list".to_owned()), None, None);
if let Ok(_new) = enc_attribute_ref_list_key.key_new_random() {
let enc_attribute_ref_list = PcdItemEncAttributeRoleConfidential::new(
"ref_list".to_owned(),
enc_attribute_ref_list_key.enc_vec_string(self.meta_data.ref_list.clone()),
enc_attribute_ref_list_key,
);
enc_attribute_list.push(enc_attribute_ref_list);
}
// data_list
let mut enc_attribute_data_list_key =
KeyEncryption::new(Some("data_list".to_owned()), None, None);
if let Ok(_new) = enc_attribute_data_list_key.key_new_random() {
let enc_attribute_data_list = PcdItemEncAttributeRoleConfidential::new(
"data_list".to_owned(),
enc_attribute_data_list_key.enc_vec_string(self.meta_data.data_list.clone()),
enc_attribute_data_list_key,
);
enc_attribute_list.push(enc_attribute_data_list);
}
// amount
let mut enc_attribute_amount_key =
KeyEncryption::new(Some("amount".to_owned()), None, None);
if let Ok(_new) = enc_attribute_amount_key.key_new_random() {
let enc_attribute_amount = PcdItemEncAttributeRoleConfidential::new(
"amount".to_owned(),
enc_attribute_amount_key.enc_amount(self.meta_data.amount.clone()),
enc_attribute_amount_key,
);
enc_attribute_list.push(enc_attribute_amount);
}
// number
let mut enc_attribute_number_key =
KeyEncryption::new(Some("number".to_owned()), None, None);
if let Ok(_new) = enc_attribute_number_key.key_new_random() {
let enc_attribute_number = PcdItemEncAttributeRoleConfidential::new(
"number".to_owned(),
enc_attribute_number_key.enc_number(self.meta_data.number.clone()),
enc_attribute_number_key,
);
enc_attribute_list.push(enc_attribute_number);
}
// render_template_list
let mut enc_attribute_render_template_list_key =
KeyEncryption::new(Some("render_template_list".to_owned()), None, None);
if let Ok(_new) = enc_attribute_render_template_list_key.key_new_random() {
let enc_attribute_render_template_list = PcdItemEncAttributeRoleConfidential::new(
"render_template_list".to_owned(),
enc_attribute_render_template_list_key
.enc_vec_string(self.meta_data.render_template_list.clone()),
enc_attribute_render_template_list_key,
);
enc_attribute_list.push(enc_attribute_render_template_list);
}
// legal_text_list
let mut enc_attribute_legal_text_list_key =
KeyEncryption::new(Some("legal_text_list".to_owned()), None, None);
if let Ok(_new) = enc_attribute_legal_text_list_key.key_new_random() {
let enc_attribute_legal_text_list = PcdItemEncAttributeRoleConfidential::new(
"legal_text_list".to_owned(),
enc_attribute_legal_text_list_key
.enc_vec_string(self.meta_data.legal_text_list.clone()),
enc_attribute_legal_text_list_key,
);
enc_attribute_list.push(enc_attribute_legal_text_list);
}
// key_list
let mut enc_attribute_key_list_key =
KeyEncryption::new(Some("key_list".to_owned()), None, None);
if let Ok(_new) = enc_attribute_key_list_key.key_new_random() {
let enc_attribute_key_list = PcdItemEncAttributeRoleConfidential::new(
"key_list".to_owned(),
enc_attribute_key_list_key.enc_vec_key_encryption(self.meta_data.key_list.clone()),
enc_attribute_key_list_key,
);
enc_attribute_list.push(enc_attribute_key_list);
}
return enc_attribute_list;
}
// Additional
}