Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): make from_content_parts accept Vec #94

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ pub struct XorName(pub [u8; XOR_NAME_LEN]);
impl XorName {
/// Generate a XorName for the given content.
pub fn from_content(content: &[u8]) -> Self {
Self::from_content_parts(&[content])
Self::from_content_parts(vec![content.to_vec()])
}

/// Generate a XorName for the given content (for content-addressable-storage)
pub fn from_content_parts(content_parts: &[&[u8]]) -> Self {
pub fn from_content_parts(content_parts: Vec<Vec<u8>>) -> Self {
let mut sha3 = Sha3::v256();
for part in content_parts {
sha3.update(part);
sha3.update(&part);
}
let mut hash = [0u8; XOR_NAME_LEN];
sha3.finalize(&mut hash);
Expand Down Expand Up @@ -662,8 +662,8 @@ mod tests {

#[test]
fn xor_name_from_content() {
let alpha_1 = XorName::from_content_parts(&[b"abcdefg", b"hijk"]);
let alpha_2 = XorName::from_content_parts(&[b"abcdefg", b"hijk"]);
let alpha_1 = XorName::from_content_parts(vec![b"abcdefg".to_vec(), b"hijk".to_vec()]);
let alpha_2 = XorName::from_content_parts(vec![b"abcdefg".to_vec(), b"hijk".to_vec()]);
let alpha_3 = XorName::from_content(b"abcdefg");

assert_eq!(alpha_1, alpha_2);
Expand All @@ -672,7 +672,7 @@ mod tests {

#[test]
fn xor_name_from_content_is_agnostic_to_where_content_parts_splits() {
let alpha_1 = XorName::from_content_parts(&[b"abcdefg", b"hijk"]);
let alpha_1 = XorName::from_content_parts(vec![b"abcdefg".to_vec(), b"hijk".to_vec()]);
let alpha_2 = XorName::from_content(b"abcdefghijk");
assert_eq!(alpha_1, alpha_2);
}
Expand Down