Skip to content

Commit 96c01e8

Browse files
authored
Fix hash HEX printing (#7496)
1 parent 5a92062 commit 96c01e8

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/crypto/sha256_hash.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ namespace ccf::crypto
5050

5151
std::ostream& operator<<(std::ostream& os, const ccf::crypto::Sha256Hash& h)
5252
{
53-
for (unsigned i = 0; i < ccf::crypto::Sha256Hash::SIZE; i++)
54-
{
55-
os << std::hex << static_cast<int>(h.h[i]);
56-
}
57-
53+
os << h.hex_str();
5854
return os;
5955
}
6056

src/crypto/test/crypto.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,4 +1466,20 @@ TEST_CASE("Do not trust non-ca certs")
14661466
// CA:FALSE).
14671467
REQUIRE_FALSE(
14681468
non_ca_cert_verifier->verify_certificate({&non_ca_cert}, {}, true));
1469+
}
1470+
1471+
TEST_CASE("Sha256 hex conversions")
1472+
{
1473+
{
1474+
INFO("Sha256 via operator<<");
1475+
1476+
const std::string hex{
1477+
"f3d25d4670b742f035c1f1d9fffa2eba676ddc491c5288403fa1091e62f26dd6"};
1478+
auto hash = ccf::crypto::Sha256Hash::from_hex_string(hex);
1479+
1480+
std::stringstream ss;
1481+
ss << hash;
1482+
1483+
REQUIRE(ss.str() == hex);
1484+
}
14691485
}

0 commit comments

Comments
 (0)