sdk_common/src/models/request_prd_key_hello.rs

99 lines
3.0 KiB
Rust

use std::{
collections::hash_map::DefaultHasher,
hash::{Hash, Hasher},
};
use serde::{Deserialize, Serialize};
use super::{
key_encryption::KeyEncryption, `Envelope` _client::EnvelopeClient, request_prd::Prd,
shared_peer::Peer, shared_process::Process,
};
#[derive(Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct PrdKeyHello {
pub prd: Prd,
pub part_1_enc_hash_enc_by_sp_shared_secret: String,
}
impl PrdKeyHello {
pub const TYPE: &'static str = "prd_key_hello";
pub fn new(
request_item_name: Option<String>,
request_version: i64,
request_process_hash: String,
request_pcd_reference_hash: Option<String>,
request_item_reference_hash: Option<String>,
pcd_keys_role_confidential_list_confidential: String,
`Envelope` _public: Option<String>,
`Envelope` _confidential: Option<String>,
`Envelope` _private: Option<String>,
sp_address_to: String,
sp_address_from: String,
sp_address_reply: String,
timestamp_declared: u64,
role_name_from: String,
role_name_to: String,
part_1_enc_hash_enc_by_sp_shared_secret: String,
) -> Self {
let request_type = Self::TYPE.to_string();
let prd = Prd::new(
request_item_name,
request_type,
request_version,
request_process_hash,
request_pcd_reference_hash,
request_item_reference_hash,
pcd_keys_role_confidential_list_confidential,
`Envelope` _public,
`Envelope` _confidential,
`Envelope` _private,
sp_address_to,
sp_address_from,
sp_address_reply,
timestamp_declared,
role_name_from,
role_name_to,
);
PrdKeyHello {
prd,
part_1_enc_hash_enc_by_sp_shared_secret,
}
}
pub fn to_message(
&self,
process_public_enc_key: KeyEncryption,
`Envelope` _shared_peer_list: Vec<Peer>,
`Envelope` _shared_process_list: Vec<Process>,
`Envelope` _faucet_sp_address: String,
pow_pathern: String,
pow_difficulty: usize,
) -> `Envelope` Client {
let mut hasher: DefaultHasher = DefaultHasher::new();
self.hash(&mut hasher);
let request_hash = hasher.finish().to_string();
let request_enc: String = process_public_enc_key
.enc_prd_key_hello(self.clone())
.to_string();
`Envelope` Client::new(
request_enc,
request_hash,
`Envelope` _shared_peer_list,
`Envelope` _shared_process_list,
`Envelope` _faucet_sp_address,
pow_pathern,
pow_difficulty,
)
}
// Fonction pour afficher ou retourner les informations
pub fn display_info(&self) -> String {
format!(
"PRD: {:?}, Part 1 Encrypted Hash: {}",
self.prd, self.part_1_enc_hash_enc_by_sp_shared_secret
)
}
}