Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32597633
D4667.1767425782.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
7 KB
Referenced Files
None
Subscribers
None
D4667.1767425782.diff
View Options
diff --git a/services/commtest/Cargo.lock b/services/commtest/Cargo.lock
--- a/services/commtest/Cargo.lock
+++ b/services/commtest/Cargo.lock
@@ -67,6 +67,15 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
+[[package]]
+name = "block-buffer"
+version = "0.10.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324"
+dependencies = [
+ "generic-array",
+]
+
[[package]]
name = "bytes"
version = "1.1.0"
@@ -93,9 +102,11 @@
"bytesize",
"derive_more",
"futures",
+ "hex",
"lazy_static",
"num_cpus",
"prost",
+ "sha2",
"tokio",
"tonic",
"tonic-build",
@@ -107,6 +118,25 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
+[[package]]
+name = "cpufeatures"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "crypto-common"
+version = "0.1.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
+dependencies = [
+ "generic-array",
+ "typenum",
+]
+
[[package]]
name = "derive_more"
version = "0.99.16"
@@ -120,6 +150,16 @@
"syn",
]
+[[package]]
+name = "digest"
+version = "0.10.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506"
+dependencies = [
+ "block-buffer",
+ "crypto-common",
+]
+
[[package]]
name = "either"
version = "1.6.1"
@@ -184,6 +224,16 @@
"pin-utils",
]
+[[package]]
+name = "generic-array"
+version = "0.14.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803"
+dependencies = [
+ "typenum",
+ "version_check",
+]
+
[[package]]
name = "getrandom"
version = "0.2.3"
@@ -238,6 +288,12 @@
"libc",
]
+[[package]]
+name = "hex"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
+
[[package]]
name = "http"
version = "0.2.5"
@@ -643,6 +699,17 @@
"pest",
]
+[[package]]
+name = "sha2"
+version = "0.10.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676"
+dependencies = [
+ "cfg-if",
+ "cpufeatures",
+ "digest",
+]
+
[[package]]
name = "slab"
version = "0.4.5"
@@ -872,6 +939,12 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642"
+[[package]]
+name = "typenum"
+version = "1.15.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
+
[[package]]
name = "ucd-trie"
version = "0.1.3"
@@ -890,6 +963,12 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
+[[package]]
+name = "version_check"
+version = "0.9.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
+
[[package]]
name = "want"
version = "0.3.0"
diff --git a/services/commtest/Cargo.toml b/services/commtest/Cargo.toml
--- a/services/commtest/Cargo.toml
+++ b/services/commtest/Cargo.toml
@@ -14,6 +14,8 @@
bytesize = "1.1.0"
lazy_static = "1.4.0"
num_cpus = "1.13.1"
+sha2 = "0.10.2"
+hex = "0.4.3"
[build-dependencies]
tonic-build = "0.6"
diff --git a/services/commtest/tests/backup/create_new_backup.rs b/services/commtest/tests/backup/create_new_backup.rs
--- a/services/commtest/tests/backup/create_new_backup.rs
+++ b/services/commtest/tests/backup/create_new_backup.rs
@@ -8,10 +8,11 @@
BackupData, BackupServiceClient,
};
+use hex::ToHex;
+use sha2::{Digest, Sha512};
use tonic::Request;
-use crate::tools::generate_nbytes;
-use crate::tools::Error;
+use crate::tools::{generate_nbytes, Error};
pub async fn run(
client: &mut BackupServiceClient<tonic::transport::Channel>,
@@ -21,6 +22,7 @@
let cloned_user_id = backup_data.user_id.clone();
let cloned_device_id = backup_data.device_id.clone();
let cloned_backup_chunk_sizes = backup_data.backup_item.chunks_sizes.clone();
+ let predefined_byte_value = None;
let outbound = async_stream::stream! {
println!(" - sending user id");
let request = CreateNewBackupRequest {
@@ -38,15 +40,21 @@
};
yield request;
println!(" - sending data hash");
- // todo calculate the real hash, this is a mocked value
+ let mut hasher = Sha512::new();
+ for chunk_size in &cloned_backup_chunk_sizes {
+ hasher.update(generate_nbytes(*chunk_size, predefined_byte_value));
+ }
+ let hash = hasher.finalize();
+ let s = hash.encode_hex::<String>();
+
let request = CreateNewBackupRequest {
- data: Some(NewCompactionHash(vec![68,67,66,65,66])),
+ data: Some(NewCompactionHash(s.as_bytes().to_vec())),
};
yield request;
- for chunk_size in cloned_backup_chunk_sizes {
+ for chunk_size in &cloned_backup_chunk_sizes {
println!(" - sending data chunk {}", chunk_size);
let request = CreateNewBackupRequest {
- data: Some(NewCompactionChunk(generate_nbytes(chunk_size, None))),
+ data: Some(NewCompactionChunk(generate_nbytes(*chunk_size, predefined_byte_value))),
};
yield request;
}
diff --git a/services/commtest/tests/backup/send_log.rs b/services/commtest/tests/backup/send_log.rs
--- a/services/commtest/tests/backup/send_log.rs
+++ b/services/commtest/tests/backup/send_log.rs
@@ -10,8 +10,10 @@
use tonic::Request;
use crate::backup_utils::BackupData;
-use crate::tools::generate_nbytes;
-use crate::tools::Error;
+use crate::tools::{generate_nbytes, Error};
+
+use hex::ToHex;
+use sha2::{Digest, Sha512};
pub async fn run(
client: &mut BackupServiceClient<tonic::transport::Channel>,
@@ -22,6 +24,7 @@
let cloned_user_id = backup_data.user_id.clone();
let cloned_backup_id = backup_data.backup_item.id.clone();
let cloned_log_sizes = backup_data.log_items[log_index].chunks_sizes.clone();
+ let predefined_byte_value = None;
let outbound = async_stream::stream! {
println!(" - sending user id");
let request = SendLogRequest {
@@ -34,15 +37,22 @@
};
yield request;
println!(" - sending log hash");
+ let mut hasher = Sha512::new();
+ for chunk_size in &cloned_log_sizes {
+ hasher.update(generate_nbytes(*chunk_size, predefined_byte_value));
+ }
+ let hash = hasher.finalize();
+ let s = hash.encode_hex::<String>();
+
let request = SendLogRequest {
- data: Some(LogHash(vec![65,66,67,66+(log_index as u8)])),
+ data: Some(LogHash(s.as_bytes().to_vec())),
};
yield request;
println!(" - sending log data");
- for log_size in cloned_log_sizes {
- println!(" - sending log data {}", log_size);
+ for log_size in &cloned_log_sizes {
+ println!(" - sending log data {}", *log_size);
let request = SendLogRequest {
- data: Some(LogData(generate_nbytes(log_size, None))),
+ data: Some(LogData(generate_nbytes(*log_size, predefined_byte_value))),
};
yield request;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jan 3, 7:36 AM (6 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5887002
Default Alt Text
D4667.1767425782.diff (7 KB)
Attached To
Mode
D4667: [services] Tests - Backup - Calculate a real hash for backups/logs
Attached
Detach File
Event Timeline
Log In to Comment