Skip to content

Commit 45c0447

Browse files
committed
Remove magic number
In array initialisation we use magic number 64, this is the secret bytes length multiplied by 2. Please note; we still use the magic number 32, left as such because it is used in various ways and its not immediately clear that using a single const would be any more descriptive. Use `SECRET_KEY_SIZE * 2` instead of magic number 64.
1 parent 5204658 commit 45c0447

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/key.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ impl SecretKey {
299299
impl ::serde::Serialize for SecretKey {
300300
fn serialize<S: ::serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
301301
if s.is_human_readable() {
302-
let mut buf = [0u8; 64];
302+
let mut buf = [0u8; constants::SECRET_KEY_SIZE * 2];
303303
s.serialize_str(::to_hex(&self.0, &mut buf).expect("fixed-size hex serialization"))
304304
} else {
305305
s.serialize_bytes(&self[..])
@@ -925,7 +925,7 @@ impl str::FromStr for KeyPair {
925925
impl ::serde::Serialize for KeyPair {
926926
fn serialize<S: ::serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
927927
if s.is_human_readable() {
928-
let mut buf = [0u8; 64];
928+
let mut buf = [0u8; constants::SECRET_KEY_SIZE * 2];
929929
s.serialize_str(::to_hex(&self.serialize_secret(), &mut buf)
930930
.expect("fixed-size hex serialization"))
931931
} else {

src/secret.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub struct DisplaySecret {
9191
impl fmt::Debug for DisplaySecret {
9292
#[inline]
9393
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
94-
let mut slice = [0u8; 64];
94+
let mut slice = [0u8; SECRET_KEY_SIZE * 2];
9595
let hex = to_hex(&self.secret, &mut slice).expect("fixed-size hex serializer failed");
9696
f.debug_tuple("DisplaySecret")
9797
.field(&hex)

0 commit comments

Comments
 (0)