Skip to content

Commit 9687bdd

Browse files
committed
node-data: change save_consensus_keys to take a password in bytes
1 parent 51226ed commit 9687bdd

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

node-data/src/bls.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ fn read_from_file(
166166
)
167167
})?;
168168

169-
let aes_key = hash_sha256(pwd);
169+
let aes_key = hash_sha256(pwd.as_bytes());
170170

171171
let bytes = decrypt(&ciphertext[..], &aes_key)
172172
.map_err(|e| anyhow::anyhow!("Invalid consensus keys password {e}"))?;
@@ -188,7 +188,7 @@ pub fn save_consensus_keys(
188188
filename: &str,
189189
pk: &BlsPublicKey,
190190
sk: &BlsSecretKey,
191-
pwd: &str,
191+
pwd: &[u8],
192192
) -> Result<(PathBuf, PathBuf), ConsensusKeysError> {
193193
let path = path.join(filename);
194194
let bytes = pk.to_bytes();
@@ -211,9 +211,9 @@ pub fn save_consensus_keys(
211211
Ok((path.with_extension("keys"), path.with_extension("cpk")))
212212
}
213213

214-
fn hash_sha256(pwd: &str) -> Vec<u8> {
214+
fn hash_sha256(pwd: &[u8]) -> Vec<u8> {
215215
let mut hasher = Sha256::new();
216-
hasher.update(pwd.as_bytes());
216+
hasher.update(pwd);
217217
hasher.finalize().to_vec()
218218
}
219219

@@ -280,7 +280,7 @@ mod tests {
280280
let pk = BlsPublicKey::from(&sk);
281281
let pwd = "password";
282282

283-
save_consensus_keys(dir.path(), "consensus", &pk, &sk, pwd)?;
283+
save_consensus_keys(dir.path(), "consensus", &pk, &sk, pwd.as_bytes())?;
284284
let keys_path = dir.path().join("consensus.keys");
285285
let (loaded_sk, loaded_pk) = load_keys(
286286
keys_path

0 commit comments

Comments
 (0)