Skip to content

Commit

Permalink
Merge branch 'tim/fix_clippy' into 'master'
Browse files Browse the repository at this point in the history
fix: Clippy warnings in build.rs

See merge request TankerHQ/sdk-rust!149
  • Loading branch information
tux3 committed Nov 7, 2022
2 parents 44f908b + 112eba1 commit 9de688c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 21 deletions.
6 changes: 3 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ fn main() -> Result<(), Box<dyn Error>> {
);

// Paths can contain anything, but env vars are a liiitle more restricted. Sanity checks!
assert!(!bindings_folder.contains(&"="));
assert!(!bindings_folder.contains(&"\0"));
assert!(!bindings_folder.contains(&"\n"));
assert!(!bindings_folder.contains('='));
assert!(!bindings_folder.contains('\0'));
assert!(!bindings_folder.contains('\n'));

// Export an env var so we can include ctanker.rs in the source code
println!("cargo:rustc-env=NATIVE_BINDINGS_FOLDER={}", bindings_folder);
Expand Down
3 changes: 3 additions & 0 deletions src/ctanker.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// C types can vary by target arch, so casts that look unnecessary on x86 are actually needed
#![allow(clippy::unnecessary_cast)]

#[cfg(target_family = "windows")]
macro_rules! tanker_call {
($self:ident, $func_name:ident($($args:tt)*)) => { $self.ctanker_api.$func_name($($args)*) };
Expand Down
4 changes: 2 additions & 2 deletions tests/encryption_session_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async fn share_with_enc_sess() -> Result<(), Error> {
let bob = app.start_anonymous(&bob_id).await?;

let data = b"La Pleiade";
let options = EncryptionOptions::new().share_with_users(&[bob_public_id]);
let options = EncryptionOptions::new().share_with_users([bob_public_id]);
let sess = alice.create_encryption_session(&options).await?;
let encrypted = sess.encrypt(data).await?;
assert_eq!(bob.decrypt(&encrypted).await?, data);
Expand All @@ -41,7 +41,7 @@ async fn encrypt_stream_with_enc_sess() -> Result<(), Error> {
let bob = app.start_anonymous(&bob_id).await?;

let data = b"La Comedie Humaine";
let options = EncryptionOptions::new().share_with_users(&[bob_public_id]);
let options = EncryptionOptions::new().share_with_users([bob_public_id]);
let sess = alice.create_encryption_session(&options).await?;
let encrypted = sess.encrypt_stream(data as &[u8]).await?;

Expand Down
10 changes: 5 additions & 5 deletions tests/group_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async fn encrypt_and_share_with_external_group() -> Result<(), Error> {
let group_id = bob.create_group(&[&bob_pub_id]).await?;

let message: &[u8] = b"Sawdust. A byproduct.";
let options = EncryptionOptions::new().share_with_groups(&[group_id]);
let options = EncryptionOptions::new().share_with_groups([group_id]);
let encrypted = alice.encrypt(message, &options).await?;

assert_eq!(bob.decrypt(&encrypted).await?, message);
Expand All @@ -73,7 +73,7 @@ async fn share_with_external_group() -> Result<(), Error> {
let encrypted = bob.encrypt(msg, &Default::default()).await?;
let resource_id = bob.get_resource_id(&encrypted)?;

let options = SharingOptions::new().share_with_groups(&[group_id]);
let options = SharingOptions::new().share_with_groups([group_id]);
bob.share(&[resource_id], &options).await?;

assert_eq!(alice.decrypt(&encrypted).await?, msg);
Expand All @@ -93,7 +93,7 @@ async fn encrypt_share_with_duplicate_group_id() -> Result<(), Error> {
let group_id = alice.create_group(&[&alice_pub_id]).await?;

let msg: &[u8] = b"Coverage is the mother of safety";
let options = EncryptionOptions::new().share_with_groups(&[group_id.clone(), group_id]);
let options = EncryptionOptions::new().share_with_groups([group_id.clone(), group_id]);
let encrypted = alice.encrypt(msg, &options).await?;
assert_eq!(alice.decrypt(&encrypted).await?, msg);

Expand All @@ -117,7 +117,7 @@ async fn add_member_to_group() -> Result<(), Error> {
let encrypted = alice.encrypt(msg, &Default::default()).await?;
let resource_id = alice.get_resource_id(&encrypted)?;

let options = SharingOptions::new().share_with_groups(&[&group_id]);
let options = SharingOptions::new().share_with_groups([&group_id]);
alice.share(&[resource_id], &options).await?;

alice
Expand All @@ -144,7 +144,7 @@ async fn remove_member_from_group() -> Result<(), Error> {
let group_id = alice.create_group(&[&alice_pub_id, &bob_pub_id]).await?;

let msg = b"<insert famous citation here>";
let options = EncryptionOptions::new().share_with_groups(&[&group_id]);
let options = EncryptionOptions::new().share_with_groups([&group_id]);
let encrypted = alice.encrypt(msg, &options).await?;

assert_eq!(bob.decrypt(&encrypted).await?, msg);
Expand Down
6 changes: 3 additions & 3 deletions tests/identity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn generate_user_secret(hashed_user_id: &[u8]) -> Vec<u8> {

let random_bytes: [u8; USER_SECRET_SIZE - 1] = rand::thread_rng().gen();
let mut hasher = Blake2b::<consts::U1>::new();
hasher.update(&random_bytes);
hasher.update(random_bytes);
hasher.update(hashed_user_id);

let mut user_secret = random_bytes.to_vec();
Expand Down Expand Up @@ -89,7 +89,7 @@ pub fn create_identity(
"target": "user",
"value": base64::encode(&hashed_user_id),
"delegation_signature": base64::encode(signature.as_ref()),
"ephemeral_public_signature_key": base64::encode(&sign_keypair.public),
"ephemeral_public_signature_key": base64::encode(sign_keypair.public),
"ephemeral_private_signature_key": base64::encode(sign_keypair.to_bytes().as_ref()),
"user_secret": base64::encode(user_secret),
});
Expand Down Expand Up @@ -118,7 +118,7 @@ pub fn create_provisional_identity(b64_app_id: &str, email: &str) -> Result<Stri
"value": email,
"public_encryption_key": base64::encode(encrypt_pk.as_bytes()),
"private_encryption_key": base64::encode(encrypt_sk.to_bytes()),
"public_signature_key": base64::encode(&sign_keypair.public),
"public_signature_key": base64::encode(sign_keypair.public),
"private_signature_key": base64::encode(sign_keypair.to_bytes().as_ref()),
});

Expand Down
15 changes: 7 additions & 8 deletions tests/tanker_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ async fn share_then_decrypt() -> Result<(), Error> {
let encrypted = alice.encrypt(plaintext, &Default::default()).await?;
let resource_id = alice.get_resource_id(&encrypted)?;

let options = SharingOptions::new().share_with_users(&[bob_public_id]);
let options = SharingOptions::new().share_with_users([bob_public_id]);
alice.share(&[resource_id], &options).await?;

let decrypted = bob.decrypt(&encrypted).await?;
Expand All @@ -260,7 +260,7 @@ async fn share_duplicate_user_id() -> Result<(), Error> {
let encrypted = alice.encrypt(plaintext, &Default::default()).await?;
let resource_id = alice.get_resource_id(&encrypted)?;

let options = SharingOptions::new().share_with_users(&[bob_public_id.clone(), bob_public_id]);
let options = SharingOptions::new().share_with_users([bob_public_id.clone(), bob_public_id]);
alice.share(&[resource_id], &options).await?;

let decrypted = bob.decrypt(&encrypted).await?;
Expand All @@ -280,7 +280,7 @@ async fn encrypt_and_share_then_decrypt() -> Result<(), Error> {
let bob = app.start_anonymous(&bob_id).await?;

let plaintext = b"Ludwigsburg";
let options = EncryptionOptions::new().share_with_users(&[bob_public_id]);
let options = EncryptionOptions::new().share_with_users([bob_public_id]);
let encrypted = alice.encrypt(plaintext, &options).await?;
let decrypted = bob.decrypt(&encrypted).await?;
alice.stop().await?;
Expand All @@ -300,7 +300,7 @@ async fn encrypt_no_share_with_self() -> Result<(), Error> {

let plaintext = b"Eclipse";
let options = EncryptionOptions::new()
.share_with_users(&[bob_public_id])
.share_with_users([bob_public_id])
.share_with_self(false);
let encrypted = alice.encrypt(plaintext, &options).await?;

Expand All @@ -324,7 +324,7 @@ async fn share_with_provisional_user() -> Result<(), Error> {
let bob_public_id = app.get_public_identity(&bob_provisional);

let alice = app.start_anonymous(&app.create_identity(None)).await?;
let options = EncryptionOptions::new().share_with_users(&[bob_public_id]);
let options = EncryptionOptions::new().share_with_users([bob_public_id]);
let encrypted = alice.encrypt(message, &options).await?;
alice.stop().await?;

Expand Down Expand Up @@ -359,8 +359,7 @@ async fn share_with_duplicate_provisional_user() -> Result<(), Error> {
let bob_public_id = app.get_public_identity(&bob_provisional);

let alice = app.start_anonymous(&app.create_identity(None)).await?;
let options =
EncryptionOptions::new().share_with_users(&[bob_public_id.clone(), bob_public_id]);
let options = EncryptionOptions::new().share_with_users([bob_public_id.clone(), bob_public_id]);
let encrypted = alice.encrypt(message, &options).await?;
alice.stop().await?;

Expand Down Expand Up @@ -431,7 +430,7 @@ async fn attach_provisional_with_single_verif() -> Result<(), Error> {
let bob_public_id = app.get_public_identity(&bob_provisional);

let alice = app.start_anonymous(&app.create_identity(None)).await?;
let options = EncryptionOptions::new().share_with_users(&[bob_public_id]);
let options = EncryptionOptions::new().share_with_users([bob_public_id]);
let encrypted = alice.encrypt(message, &options).await?;
alice.stop().await?;

Expand Down

0 comments on commit 9de688c

Please sign in to comment.