Skip to content

Commit

Permalink
f master
Browse files Browse the repository at this point in the history
  • Loading branch information
aesedepece committed Dec 31, 2023
1 parent 323c68c commit 1e2f7d3
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions node/src/signature_mngr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,12 +497,16 @@ impl Actor for SignatureManagerAdapter {

async move {
let config = config_mngr::get().await?;
let master_key_from_file = if let Some(master_key_path) = &config.storage.master_key_import_path {
master_key_import_from_file(master_key_path).map(Some)
} else {
Ok(None)
}?;
let master_key_from_storage: Option<ExtendedSK> = storage_mngr::get::<_, ExtendedSecretKey>(&MASTER_KEY).await?.map(Into::into);
let master_key_from_file =
if let Some(master_key_path) = &config.storage.master_key_import_path {
master_key_import_from_file(master_key_path).map(Some)
} else {
Ok(None)
}?;
let master_key_from_storage: Option<ExtendedSK> =
storage_mngr::get::<_, ExtendedSecretKey>(&MASTER_KEY)
.await?
.map(Into::into);

let master_key = match (master_key_from_file, master_key_from_storage) {
// Didn't ask to import master key and no master key in storage:
Expand All @@ -513,23 +517,28 @@ impl Actor for SignatureManagerAdapter {
(None, Some(from_storage)) => Ok(from_storage),
(Some(from_file), None) => {
// Save the key into the storage
persist_master_key(from_file.clone()).await.map(|()| from_file)
},
persist_master_key(from_file.clone())
.await
.map(|()| from_file)
}
// There is a master key in storage and imported:
(Some(from_file), Some(_from_storage)) => {
// Save the key into the storage
persist_master_key(from_file.clone()).await.map(|()| from_file.clone())
persist_master_key(from_file.clone())
.await
.map(|()| from_file.clone())
}
}?;

crypto.send(SetKey(master_key)).await?
}.into_actor(self)
.map_err(|err, _act, _ctx| {
log::error!("Failed to configure master key: {}", err);
System::current().stop_with_code(1);
})
.map(|_res: Result<(), ()>, _act, _ctx| ())
.wait(ctx);
}
.into_actor(self)
.map_err(|err, _act, _ctx| {
log::error!("Failed to configure master key: {}", err);
System::current().stop_with_code(1);
})
.map(|_res: Result<(), ()>, _act, _ctx| ())
.wait(ctx);

let crypto = self.crypto.clone();
async move {
Expand Down

0 comments on commit 1e2f7d3

Please sign in to comment.