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.
This commit is contained in:
parent
6dca99631f
commit
91106f5685
|
@ -299,7 +299,7 @@ impl SecretKey {
|
||||||
impl ::serde::Serialize for SecretKey {
|
impl ::serde::Serialize for SecretKey {
|
||||||
fn serialize<S: ::serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
|
fn serialize<S: ::serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
|
||||||
if s.is_human_readable() {
|
if s.is_human_readable() {
|
||||||
let mut buf = [0u8; 64];
|
let mut buf = [0u8; constants::SECRET_KEY_SIZE * 2];
|
||||||
s.serialize_str(::to_hex(&self.0, &mut buf).expect("fixed-size hex serialization"))
|
s.serialize_str(::to_hex(&self.0, &mut buf).expect("fixed-size hex serialization"))
|
||||||
} else {
|
} else {
|
||||||
s.serialize_bytes(&self[..])
|
s.serialize_bytes(&self[..])
|
||||||
|
@ -925,7 +925,7 @@ impl str::FromStr for KeyPair {
|
||||||
impl ::serde::Serialize for KeyPair {
|
impl ::serde::Serialize for KeyPair {
|
||||||
fn serialize<S: ::serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
|
fn serialize<S: ::serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
|
||||||
if s.is_human_readable() {
|
if s.is_human_readable() {
|
||||||
let mut buf = [0u8; 64];
|
let mut buf = [0u8; constants::SECRET_KEY_SIZE * 2];
|
||||||
s.serialize_str(::to_hex(&self.serialize_secret(), &mut buf)
|
s.serialize_str(::to_hex(&self.serialize_secret(), &mut buf)
|
||||||
.expect("fixed-size hex serialization"))
|
.expect("fixed-size hex serialization"))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -91,7 +91,7 @@ pub struct DisplaySecret {
|
||||||
impl fmt::Debug for DisplaySecret {
|
impl fmt::Debug for DisplaySecret {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let mut slice = [0u8; 64];
|
let mut slice = [0u8; SECRET_KEY_SIZE * 2];
|
||||||
let hex = to_hex(&self.secret, &mut slice).expect("fixed-size hex serializer failed");
|
let hex = to_hex(&self.secret, &mut slice).expect("fixed-size hex serializer failed");
|
||||||
f.debug_tuple("DisplaySecret")
|
f.debug_tuple("DisplaySecret")
|
||||||
.field(&hex)
|
.field(&hex)
|
||||||
|
|
Loading…
Reference in New Issue