Skip to content

Commit b6083e6

Browse files
authored
Merge pull request #2236 from input-output-hk/jpraynaud/fix-trailing-whitespace-genesis-signature
Fix: support trailing whitespace in protocol key files
2 parents 98407cd + efc4d3e commit b6083e6

File tree

7 files changed

+32
-11
lines changed

7 files changed

+32
-11
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-aggregator/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-aggregator"
3-
version = "0.6.14"
3+
version = "0.6.15"
44
description = "A Mithril Aggregator server"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-aggregator/src/snapshotter.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ impl CompressedArchiveSnapshotter {
240240
#[cfg(test)]
241241
/// Allow to use a custom temporary directory to avoid conflicts during the snapshot verification.
242242
pub fn set_sub_temp_dir<P: AsRef<Path>>(&mut self, sub_dir: P) {
243-
self.temp_dir = std::env::temp_dir().join(sub_dir);
243+
self.temp_dir =
244+
mithril_common::test_utils::TempDir::create("snapshotter", "temp_dir").join(sub_dir);
244245
}
245246

246247
fn snapshot<T: TarAppender>(&self, filepath: &Path, appender: T) -> StdResult<OngoingSnapshot> {

mithril-common/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-common"
3-
version = "0.4.105"
3+
version = "0.4.106"
44
description = "Common types, interfaces, and utilities for Mithril nodes."
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-common/src/crypto_helper/codec.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn key_decode_hex<T>(from: HexEncodedKeySlice) -> Result<T, CodecError>
4444
where
4545
T: DeserializeOwned,
4646
{
47-
let from_vec = Vec::from_hex(from).map_err(|e| {
47+
let from_vec = Vec::from_hex(from.trim()).map_err(|e| {
4848
CodecError::new(
4949
"Key decode hex: can not turn hexadecimal value into bytes",
5050
e.into(),
@@ -91,6 +91,18 @@ mod tests {
9191
assert_eq!(test_to_serialize, test_to_serialize_restored);
9292
}
9393

94+
#[test]
95+
fn test_key_decode_hex_with_leading_and_trailing_whitespace() {
96+
let test_to_serialize = TestSerialize {
97+
inner_string: "my inner string".to_string(),
98+
};
99+
let test_to_serialize_hex =
100+
key_encode_hex(&test_to_serialize).expect("unexpected hex encoding error");
101+
let test_to_serialize_restored = key_decode_hex(&format!(" \r{test_to_serialize_hex} \n"))
102+
.expect("unexpected hex decoding error");
103+
assert_eq!(test_to_serialize, test_to_serialize_restored);
104+
}
105+
94106
#[test]
95107
fn test_bech32_encode() {
96108
let hrp = "pool";

mithril-common/src/crypto_helper/tests_setup.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use super::{genesis::*, types::*, OpCert, SerDeShelleyFileFormat};
33
use crate::{
44
entities::{Certificate, ProtocolMessage, ProtocolMessagePartKey, SignerWithStake, Stake},
5-
test_utils::{CertificateChainBuilder, SignerFixture},
5+
test_utils::{CertificateChainBuilder, SignerFixture, TempDir},
66
};
77

88
use rand_chacha::ChaCha20Rng;
@@ -14,9 +14,10 @@ pub fn setup_temp_directory_for_signer(
1414
party_id: &ProtocolPartyId,
1515
auto_create: bool,
1616
) -> Option<PathBuf> {
17-
let temp_dir = std::env::temp_dir()
18-
.join("mithril_crypto_helper_material")
17+
let temp_dir = TempDir::new("tests_setup", "mithril_crypto_helper_material")
18+
.build_path()
1919
.join(party_id);
20+
2021
if auto_create {
2122
fs::create_dir_all(&temp_dir).expect("temp dir creation should not fail");
2223
}

mithril-common/src/crypto_helper/types/protocol_key.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,10 @@ macro_rules! impl_codec_and_type_conversions_for_protocol_key {
218218

219219
#[cfg(test)]
220220
mod test {
221-
use crate::{crypto_helper::ProtocolKey, test_utils::fake_keys};
221+
use crate::{
222+
crypto_helper::ProtocolKey,
223+
test_utils::{fake_keys, TempDir},
224+
};
222225
use mithril_stm::stm::StmVerificationKeyPoP;
223226
use serde::{Deserialize, Serialize};
224227

@@ -275,7 +278,11 @@ mod test {
275278
#[test]
276279
fn can_read_and_write_to_file_a_verification_key() {
277280
let expected_key: ProtocolKey<StmVerificationKeyPoP> = VERIFICATION_KEY.try_into().unwrap();
278-
let key_path = std::env::temp_dir().join("can_read_and_write_to_file_a_verification_key");
281+
let key_path = TempDir::create(
282+
"protocol_key",
283+
"can_read_and_write_to_file_a_verification_key",
284+
)
285+
.join("key.out");
279286

280287
expected_key
281288
.write_json_hex_to_file(&key_path)

0 commit comments

Comments
 (0)