Crates.io | aws-tree-hash |
lib.rs | aws-tree-hash |
version | 0.1.1 |
source | src |
created_at | 2022-12-26 14:35:56.908419 |
updated_at | 2022-12-26 14:35:56.908419 |
description | Calculate the Amazon SHA256 tree hash as described on Checksum Calculation page of the AWS S3 Glacier developer guide. |
homepage | |
repository | https://github.com/hannes-hochreiner/aws-tree-hash |
max_upload_size | |
id | 745803 |
size | 27,530 |
A library for calculating AWS tree hashes
use hex::FromHex;
fn main() {
assert_eq!(
aws_tree_hash::calculate_tree_hash(&[0; 7680000]),
Vec::from_hex("7a43777ddc7a0326d36b15bc482e6c7736e1c2e9d80a647e8c301646f6a4785c").unwrap()
);
}
use hex::FromHex;
fn main() {
let data = &[0u8; 7680000];
let tree_hash_1 = aws_tree_hash::calculate_tree_hash(&data[..2097152]);
let tree_hash_2 = aws_tree_hash::calculate_tree_hash(&data[2097152..4194304]);
let tree_hash_3 = aws_tree_hash::calculate_tree_hash(&data[4194304..6291456]);
let tree_hash_4 = aws_tree_hash::calculate_tree_hash(&data[6291456..]);
let res = aws_tree_hash::combine_hashes(vec![tree_hash_1, tree_hash_2, tree_hash_3, tree_hash_4]);
assert_eq!(
res,
Vec::from_hex("7a43777ddc7a0326d36b15bc482e6c7736e1c2e9d80a647e8c301646f6a4785c")
.unwrap()
);
}
The tree hash for a 7.7 MB file containing only null characters can be obtained by running just src_other/start
.
The calculation is performed using the example algorithm provided by Amazon.
This work is licensed under the MIT or Apache 2.0 license.
SPDX-License-Identifier: MIT OR Apache-2.0