Skip to content

Commit d2b9f36

Browse files
committed
Merge branch 'tim/update_deps' into 'master'
chore: Update deps, switch to using new blake2 API See merge request TankerHQ/sdk-rust!94
2 parents 4c6323d + b0c3054 commit d2b9f36

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

.gitlab-ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ stages:
7171

7272
.profiles/windows:
7373
before_script:
74+
- poetry run python -m pip install --upgrade pip
75+
- poetry install
7476
# Powershell doesn't split env variable when expanding it.
7577
# So, we are using the native syntax to create an array, which will be correctly expanded.
7678
- $TANKER_PROFILES = "--profile", "vs2019-release-shared"

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ double-checked-cell-async = "2.0.2"
2222
rand = "0.7.3"
2323
base64 = "0.13"
2424
variant_count = "1.0"
25-
blake2 = "0.9"
25+
blake2 = "0.10.2"
2626
ed25519-dalek = "1.0"
2727
x25519-dalek = "1.1"
2828

tests/identity/admin/block.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use blake2::digest::{Update, VariableOutput};
2-
use blake2::VarBlake2b;
2+
use blake2::Blake2bVar;
33
use ed25519_dalek::Keypair;
44

55
pub fn serialized_root_block(sign_keypair: &Keypair) -> Vec<u8> {
@@ -51,8 +51,8 @@ fn serialized_block(
5151
}
5252

5353
fn block_hash(nature: u64, author: &[u8; 32], payload: &[u8]) -> Vec<u8> {
54-
let mut hasher = VarBlake2b::new(crate::identity::BLOCK_HASH_SIZE).unwrap();
55-
hasher.update(serialized_varint(nature).into_iter().collect::<Vec<_>>());
54+
let mut hasher = Blake2bVar::new(crate::identity::BLOCK_HASH_SIZE).unwrap();
55+
hasher.update(&serialized_varint(nature).into_iter().collect::<Vec<_>>());
5656
hasher.update(author);
5757
hasher.update(payload);
5858
hasher.finalize_boxed().to_vec()

tests/identity/mod.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ pub use admin::Admin;
88
mod test_app;
99
pub use test_app::TestApp;
1010

11-
use blake2::digest::{Update, VariableOutput};
12-
use blake2::VarBlake2b;
11+
use blake2::digest::{consts, VariableOutput};
12+
use blake2::{Blake2b, Blake2bVar};
1313
use ed25519_dalek::{Keypair, Signer};
1414
use rand::{rngs::OsRng, Rng};
1515
use serde_json::{json, Value};
@@ -24,25 +24,32 @@ const USER_SECRET_SIZE: usize = 32;
2424
const SIGNATURE_SIZE: usize = 64;
2525

2626
pub fn hash_user_id(app_id: &[u8], user_id: &str) -> Vec<u8> {
27-
let mut hasher = VarBlake2b::new(BLOCK_HASH_SIZE).unwrap();
27+
use blake2::digest::Update;
28+
29+
let mut hasher = Blake2bVar::new(BLOCK_HASH_SIZE).unwrap();
2830
hasher.update(user_id.as_bytes());
2931
hasher.update(app_id);
3032
hasher.finalize_boxed().to_vec()
3133
}
3234

3335
pub fn generate_user_secret(hashed_user_id: &[u8]) -> Vec<u8> {
36+
use blake2::Digest;
37+
3438
let random_bytes: [u8; USER_SECRET_SIZE - 1] = rand::thread_rng().gen();
35-
let mut hasher = VarBlake2b::new(1).unwrap();
39+
let mut hasher = Blake2b::<consts::U1>::new();
3640
hasher.update(&random_bytes);
3741
hasher.update(hashed_user_id);
3842

3943
let mut user_secret = random_bytes.to_vec();
40-
hasher.finalize_variable(|h| user_secret.push(h[0]));
44+
let res = hasher.finalize();
45+
user_secret.push(res[0]);
4146
user_secret
4247
}
4348

4449
pub fn generate_app_id(app_secret: &[u8]) -> Vec<u8> {
45-
let mut hasher = VarBlake2b::new(BLOCK_HASH_SIZE).unwrap();
50+
use blake2::digest::Update;
51+
52+
let mut hasher = Blake2bVar::new(BLOCK_HASH_SIZE).unwrap();
4653
hasher.update(&[APP_CREATION_NATURE]);
4754
hasher.update(&[0u8; AUTHOR_SIZE]);
4855
hasher.update(&app_secret[app_secret.len() - APP_PUBLIC_KEY_SIZE..]);

0 commit comments

Comments
 (0)