Skip to content

Commit

Permalink
Make Memo a wrapper for Box<[u8; 512]>
Browse files Browse the repository at this point in the history
  • Loading branch information
dconnolly committed Feb 13, 2020
1 parent ea8fa5e commit 99e3b16
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions zebra-chain/src/note_encryption/memo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use std::{cmp, convert::TryFrom, fmt};
/// recipient of the note.
///
/// [ps]: https://zips.z.cash/protocol/protocol.pdf#notept
#[derive(Clone, Copy)]
pub struct Memo([u8; 512]);
#[derive(Clone)]
pub struct Memo(Box<[u8; 512]>);

impl<'a> TryFrom<&'a [u8]> for Memo {
type Error = &'static str;
Expand All @@ -21,11 +21,11 @@ impl<'a> TryFrom<&'a [u8]> for Memo {
match input.len().cmp(&512) {
cmp::Ordering::Less => {
full_bytes[0..input.len()].copy_from_slice(input);
Ok(Memo(full_bytes))
Ok(Memo(Box::new(full_bytes)))
}
cmp::Ordering::Equal => {
full_bytes[..].copy_from_slice(input);
Ok(Memo(full_bytes))
Ok(Memo(Box::new(full_bytes)))
}
cmp::Ordering::Greater => Err("Memos have a max length of 512 bytes."),
}
Expand All @@ -50,15 +50,15 @@ impl fmt::Debug for Memo {

#[test]
fn memo_fmt() {
let memo = Memo(
let memo = Memo(Box::new(
*b"thiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiis \
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiis \
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeryyyyyyyyyyyyyyyyyyyyyyyyyy \
looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong \
meeeeeeeeeeeeeeeeeeemooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo \
but it's just short enough",
);
));

assert_eq!(format!("{:?}", memo),
"Memo(\"thiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiis iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiis aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeryyyyyyyyyyyyyyyyyyyyyyyyyy looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong meeeeeeeeeeeeeeeeeeemooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo but it\\\'s just short enough\")"
Expand All @@ -67,7 +67,7 @@ fn memo_fmt() {
let mut some_bytes = [0u8; 512];
some_bytes[0] = 0xF6;

assert_eq!(format!("{:?}", Memo(some_bytes)),
assert_eq!(format!("{:?}", Memo(Box::new(some_bytes))),
"Memo(\"f600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\")"
);
}
Expand Down

0 comments on commit 99e3b16

Please sign in to comment.