This commit is contained in:
Ajinkya Kulkarni 2024-12-05 12:26:03 +01:00
parent 29c642d64c
commit 7fbbf0fcbb

View file

@ -46,12 +46,10 @@ async fn get_fmspc_list() -> Vec<Fmspc> {
}
async fn upsert_tcbinfo() -> Result<(), &'static str> {
let mut store: HashMap<Fmspc, TcbInfo> = if Path::new("./standard").exists() {
let data = fs::read_to_string("./standard").expect("Unable to read file");
serde_json::from_str(&data).unwrap()
}
else {
} else {
fs::File::create("./standard").expect("couldn't create file");
HashMap::new()
};
@ -73,11 +71,11 @@ async fn upsert_tcbinfo() -> Result<(), &'static str> {
for fmspc in fmspc_list {
let tcbinfo = get_tcbinfo(fmspc.clone(), "standard".to_string()).await;
assert!(verify_signature(tcbinfo.clone(), key));
let store_entry = if store.contains_key(&fmspc)
{
let store_entry = if store.contains_key(&fmspc) {
&store[&fmspc]
}
else {""};
} else {
""
};
if *store_entry != tcbinfo {
println!("updating local TCBInfo for FMSPC: {fmspc}");
store.insert(fmspc.clone(), tcbinfo.clone());
@ -100,8 +98,8 @@ async fn upsert_tcbinfo() -> Result<(), &'static str> {
.tx_execute(
&contract_address,
&chain_id,
400000,
&sender,
1000000,
sender,
json!(execute_msg),
"11000untrn",
)
@ -114,19 +112,14 @@ async fn upsert_tcbinfo() -> Result<(), &'static str> {
}
let serialized = serde_json::to_string(&store).unwrap();
fs::write("./standard", serialized).expect("Unable to write file");
Ok(())
// }
// }
}
fn verify_signature(tcbinfo: String, key: VerifyingKey) -> bool {
let signed_tcbinfo =
SignedTcbInfo::try_from(tcbinfo.as_ref()).expect("tcbinfo string parsing failed");
if let Err(_) = signed_tcbinfo
.verify(Some(&key), None)
{
return false
if signed_tcbinfo.verify(Some(&key), None).is_err() {
return false;
}
true
}