Added a keys check on load. Added a warning on errors.

This commit is contained in:
Revertron
2021-03-23 19:29:51 +01:00
parent 98b00eb8e2
commit 1225bf6fbc
2 changed files with 18 additions and 5 deletions
+14 -2
View File
@@ -64,11 +64,23 @@ impl Keystore {
match fs::read(&path) {
Ok(key) => {
if key.len() == 32 {
return Some(Keystore::from_random_bytes(key.as_slice()));
let mut keystore = Keystore::from_random_bytes(key.as_slice());
keystore.path = path.to_str().unwrap().to_owned();
let bytes = Bytes::from_bytes(&keystore.keypair.public.to_bytes());
return if check_public_key_strength(&bytes, KEYSTORE_DIFFICULTY) {
Some(keystore)
} else {
None
};
}
let mut keystore = Self::from_bytes(key.as_slice());
keystore.path = path.to_str().unwrap().to_owned();
Some(keystore)
let bytes = Bytes::from_bytes(&keystore.keypair.public.to_bytes());
return if check_public_key_strength(&bytes, KEYSTORE_DIFFICULTY) {
Some(keystore)
} else {
None
};
}
Err(_) => {
None