Skip to content

Commit

Permalink
Satisfy clippy (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
giarc3 authored Nov 12, 2021
1 parent 12e77df commit 7363592
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 51 deletions.
11 changes: 5 additions & 6 deletions src/crypto/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,10 @@ pub fn encrypt_to_with_key<T, CR: rand::CryptoRng + rand::RngCore>(
}
impl From<(WithKey<UserOrGroup>, RecryptErr)> for DocAccessEditErr {
fn from((user_or_group, err): (WithKey<UserOrGroup>, RecryptErr)) -> Self {
match user_or_group {
WithKey { id, .. } => DocAccessEditErr::new(
id,
format!("Access grant failed with error {}", err.to_string()),
),
}
let WithKey { id, .. } = user_or_group;
DocAccessEditErr::new(
id,
format!("Access grant failed with error {}", err.to_string()),
)
}
}
8 changes: 4 additions & 4 deletions src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ pub trait DocumentOps {
async fn document_grant_access(
&self,
document_id: &DocumentId,
grant_list: &Vec<UserOrGroup>,
grant_list: &[UserOrGroup],
) -> Result<DocumentAccessResult>;

/// Revokes decryption access to a document for the provided users and/or groups.
Expand Down Expand Up @@ -362,7 +362,7 @@ pub trait DocumentOps {
async fn document_revoke_access(
&self,
document_id: &DocumentId,
revoke_list: &Vec<UserOrGroup>,
revoke_list: &[UserOrGroup],
) -> Result<DocumentAccessResult>;
}

Expand Down Expand Up @@ -486,7 +486,7 @@ impl DocumentOps for crate::IronOxide {
async fn document_grant_access(
&self,
id: &DocumentId,
grant_list: &Vec<UserOrGroup>,
grant_list: &[UserOrGroup],
) -> Result<DocumentAccessResult> {
let (users, groups) = partition_user_or_group(grant_list);

Expand All @@ -509,7 +509,7 @@ impl DocumentOps for crate::IronOxide {
async fn document_revoke_access(
&self,
id: &DocumentId,
revoke_list: &Vec<UserOrGroup>,
revoke_list: &[UserOrGroup],
) -> Result<DocumentAccessResult> {
add_optional_timeout(
document_api::document_revoke_access(self.device.auth(), id, revoke_list),
Expand Down
2 changes: 1 addition & 1 deletion src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ pub(crate) fn take_lock<T>(m: &Mutex<T>) -> MutexGuard<T> {
m.lock().unwrap_or_else(|e| {
let error = format!("Error when acquiring lock: {}", e);
error!("{}", error);
panic!(error);
panic!("{}", error);
})
}

Expand Down
34 changes: 18 additions & 16 deletions src/internal/document_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,8 @@ pub async fn encrypt_document<
document_id: Option<DocumentId>,
document_name: Option<DocumentName>,
grant_to_author: bool,
user_grants: &Vec<UserId>,
group_grants: &Vec<GroupId>,
user_grants: &[UserId],
group_grants: &[GroupId],
policy_grant: Option<&PolicyGrant>,
policy_cache: &PolicyCache,
) -> Result<DocumentEncryptResult, IronOxideErr> {
Expand All @@ -610,7 +610,7 @@ pub async fn encrypt_document<
group_grants,
policy_grant,
if grant_to_author {
Some(&user_master_pub_key)
Some(user_master_pub_key)
} else {
None
},
Expand Down Expand Up @@ -654,8 +654,8 @@ type UserMasterPublicKey = PublicKey;
async fn resolve_keys_for_grants(
auth: &RequestAuth,
config: &IronOxideConfig,
user_grants: &Vec<UserId>,
group_grants: &Vec<GroupId>,
user_grants: &[UserId],
group_grants: &[GroupId],
policy_grant: Option<&PolicyGrant>,
maybe_user_master_pub_key: Option<&UserMasterPublicKey>,
policy_cache: &PolicyCache,
Expand Down Expand Up @@ -750,8 +750,8 @@ pub async fn encrypt_document_unmanaged<R1, R2>(
plaintext: &[u8],
document_id: Option<DocumentId>,
grant_to_author: bool,
user_grants: &Vec<UserId>,
group_grants: &Vec<GroupId>,
user_grants: &[UserId],
group_grants: &[GroupId],
policy_grant: Option<&PolicyGrant>,
) -> Result<DocumentEncryptUnmanagedResult, IronOxideErr>
where
Expand All @@ -774,7 +774,7 @@ where
group_grants,
policy_grant,
if grant_to_author {
Some(&user_master_pub_key)
Some(user_master_pub_key)
} else {
None
},
Expand Down Expand Up @@ -979,10 +979,12 @@ impl EncryptedDoc {
.collect();
let proto_edek_vec = proto_edek_vec_results?;

let mut proto_edeks = EncryptedDeksP::default();
proto_edeks.edeks = RepeatedField::from_vec(proto_edek_vec);
proto_edeks.documentId = self.header.document_id.id().into();
proto_edeks.segmentId = self.header.segment_id as i32; // okay since the ironcore-ws defines this to be an i32
let proto_edeks = EncryptedDeksP {
edeks: RepeatedField::from_vec(proto_edek_vec),
documentId: self.header.document_id.id().into(),
segmentId: self.header.segment_id as i32, // okay since the ironcore-ws defines this to be an i32
..Default::default()
};

let edek_bytes = proto_edeks.write_to_bytes()?;
Ok(edek_bytes)
Expand Down Expand Up @@ -1104,7 +1106,7 @@ pub async fn decrypt_document_unmanaged<CR: rand::CryptoRng + rand::RngCore>(
parse_document_parts(encrypted_doc)?,
))
},
requests::edek_transform::edek_transform(&auth, encrypted_deks,)
requests::edek_transform::edek_transform(auth, encrypted_deks,)
)?;

edeks_and_header_match_or_err(&proto_edeks, &doc_meta)?;
Expand Down Expand Up @@ -1164,8 +1166,8 @@ pub async fn document_grant_access<CR: rand::CryptoRng + rand::RngCore>(
id: &DocumentId,
user_master_pub_key: &PublicKey,
priv_device_key: &PrivateKey,
user_grants: &Vec<UserId>,
group_grants: &Vec<GroupId>,
user_grants: &[UserId],
group_grants: &[GroupId],
) -> Result<DocumentAccessResult, IronOxideErr> {
let (doc_meta, users, groups) = try_join!(
document_get_metadata(auth, id),
Expand Down Expand Up @@ -1211,7 +1213,7 @@ pub async fn document_grant_access<CR: rand::CryptoRng + rand::RngCore>(
pub async fn document_revoke_access(
auth: &RequestAuth,
id: &DocumentId,
revoke_list: &Vec<UserOrGroup>,
revoke_list: &[UserOrGroup],
) -> Result<DocumentAccessResult, IronOxideErr> {
use requests::document_access::{self, resp};

Expand Down
3 changes: 2 additions & 1 deletion src/internal/document_api/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,8 @@ mod tests {
let result = serde_json::to_string(&item).unwrap();
assert!(
result.contains("\"fromGroup\""),
format!("{} should contain fromGroup", result)
"{} should contain fromGroup",
result
);
let de_result = serde_json::from_str(&result).unwrap();
assert_eq!(item, de_result)
Expand Down
21 changes: 10 additions & 11 deletions src/internal/group_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl GroupId {
}
}
impl recrypt::api::Hashable for GroupId {
fn to_bytes(self: &Self) -> Vec<u8> {
fn to_bytes(&self) -> Vec<u8> {
self.0.as_bytes().to_vec()
}
}
Expand Down Expand Up @@ -364,7 +364,7 @@ impl GroupAccessEditResult {
// List all of the groups that the requesting user is either a member or admin of
pub async fn list(
auth: &RequestAuth,
ids: Option<&Vec<GroupId>>,
ids: Option<&[GroupId]>,
) -> Result<GroupListResult, IronOxideErr> {
let GroupListResponse { result } = match ids {
Some(group_ids) => requests::group_list::group_limited_list_request(auth, group_ids).await,
Expand All @@ -382,14 +382,14 @@ pub async fn list(
/// Calling this with an empty `groups` list will not result in a call to the server.
pub(crate) async fn get_group_keys(
auth: &RequestAuth,
groups: &Vec<GroupId>,
groups: &[GroupId],
) -> Result<(Vec<GroupId>, Vec<WithKey<GroupId>>), IronOxideErr> {
// if there aren't any groups in the list, just return with empty results
if groups.is_empty() {
return Ok((vec![], vec![]));
}

let cloned_groups: Vec<GroupId> = groups.clone();
let cloned_groups: Vec<GroupId> = groups.to_vec();
let GroupListResult { result } = list(auth, Some(groups)).await?;
let ids_with_keys =
result
Expand Down Expand Up @@ -494,7 +494,7 @@ pub async fn group_create<CR: rand::CryptoRng + rand::RngCore>(
owner: Option<UserId>,
admins: Vec1<UserId>,
members: Vec<UserId>,
users_to_lookup: &Vec<UserId>,
users_to_lookup: &[UserId],
needs_rotation: bool,
) -> Result<GroupCreateResult, IronOxideErr> {
let user_ids_and_keys = user_api::user_key_list(auth, users_to_lookup).await?;
Expand Down Expand Up @@ -628,8 +628,7 @@ fn generate_aug_and_admins<CR: rand::CryptoRng + rand::RngCore>(
);
errors
.into_iter()
.map(|(_, e)| Err(e.into()))
.collect::<Result<(), IronOxideErr>>()?;
.try_for_each(|(_, e)| Err::<(), IronOxideErr>(e.into()))?;
Ok((aug_factor.into(), updated_group_admins))
}

Expand Down Expand Up @@ -707,7 +706,7 @@ pub async fn group_add_members<CR: rand::CryptoRng + rand::RngCore>(
auth: &RequestAuth,
device_private_key: &PrivateKey,
group_id: &GroupId,
users: &Vec<UserId>,
users: &[UserId],
) -> Result<GroupAccessEditResult, IronOxideErr> {
let (group_get, (mut acc_fails, successes)) =
try_join!(get_metadata(auth, group_id), get_user_keys(auth, users))?;
Expand Down Expand Up @@ -769,7 +768,7 @@ pub async fn group_add_admins<CR: rand::CryptoRng + rand::RngCore>(
auth: &RequestAuth,
device_private_key: &PrivateKey,
group_id: &GroupId,
users: &Vec<UserId>,
users: &[UserId],
) -> Result<GroupAccessEditResult, IronOxideErr> {
let (group_get, (mut acc_fails, successes)) =
try_join!(get_metadata(auth, group_id), get_user_keys(auth, users))?;
Expand Down Expand Up @@ -821,7 +820,7 @@ pub async fn group_add_admins<CR: rand::CryptoRng + rand::RngCore>(
///This is a thin wrapper that's just mapping the errors into the type we need for add member and add admin
async fn get_user_keys(
auth: &RequestAuth,
users: &Vec<UserId>,
users: &[UserId],
) -> Result<(Vec<GroupAccessEditErr>, Vec<WithKey<UserId>>), IronOxideErr> {
let (failed_ids, succeeded_ids) = user_api::get_user_keys(auth, users).await?;
let failed_ids_result = failed_ids
Expand Down Expand Up @@ -868,7 +867,7 @@ pub async fn update_group_name(
pub async fn group_remove_entity(
auth: &RequestAuth,
id: &GroupId,
users: &Vec<UserId>,
users: &[UserId],
entity_type: GroupEntity,
) -> Result<GroupAccessEditResult, IronOxideErr> {
let GroupUserEditResponse {
Expand Down
10 changes: 6 additions & 4 deletions src/internal/group_api/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ pub mod group_list {
//List a specific set of groups given a list of group IDs
pub async fn group_limited_list_request(
auth: &RequestAuth,
groups: &Vec<GroupId>,
groups: &[GroupId],
) -> Result<GroupListResponse, IronOxideErr> {
let group_ids: Vec<&str> = groups.iter().map(GroupId::id).collect();
auth.request
Expand Down Expand Up @@ -462,7 +462,7 @@ pub mod group_remove_entity {
pub async fn remove_entity_request(
auth: &RequestAuth,
group_id: &GroupId,
user_ids: &Vec<UserId>,
user_ids: &[UserId],
entity_type: GroupEntity,
) -> Result<GroupUserEditResponse, IronOxideErr> {
let removed_users = user_ids
Expand Down Expand Up @@ -522,11 +522,13 @@ mod tests {
let result = serde_json::to_string(&item).unwrap();
assert!(
result.contains("\"admin\""),
format!("{} should contain admin", result)
"{} should contain admin",
result
);
assert!(
result.contains("\"member\""),
format!("{} should contain member", result)
"{} should contain member",
result
);
let de_result = serde_json::from_str(&result).unwrap();
assert_eq!(item, de_result)
Expand Down
1 change: 1 addition & 0 deletions src/internal/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ pub fn url_encode(token: &str) -> PercentEncodedString {
PercentEncodedString(percent_encoding::utf8_percent_encode(token, ICL_ENCODE_SET).to_string())
}

#[allow(clippy::large_enum_variant)]
///Enum representing all the ways that authorization can be done for the IronCoreRequest.
pub enum Authorization<'a> {
JwtAuth(&'a Jwt),
Expand Down
12 changes: 6 additions & 6 deletions src/internal/user_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ pub async fn user_verify(
jwt: &Jwt,
request: IronCoreRequest,
) -> Result<Option<UserResult>, IronOxideErr> {
requests::user_verify::user_verify(&jwt, &request)
requests::user_verify::user_verify(jwt, &request)
.await?
.map(|resp| resp.try_into())
.transpose()
Expand All @@ -398,7 +398,7 @@ pub async fn user_create<CR: rand::CryptoRng + rand::RngCore>(
})?;

requests::user_create::user_create(
&jwt,
jwt,
recrypt_pub.into(),
encrypted_priv_key.into(),
needs_rotation,
Expand Down Expand Up @@ -640,7 +640,7 @@ pub async fn device_delete(
/// Get a list of users public keys given a list of user account IDs
pub async fn user_key_list(
auth: &RequestAuth,
user_ids: &Vec<UserId>,
user_ids: &[UserId],
) -> Result<HashMap<UserId, PublicKey>, IronOxideErr> {
requests::user_key_list::user_key_list_request(auth, user_ids)
.await
Expand All @@ -666,7 +666,7 @@ pub async fn user_key_list(
/// Calling this with an empty `users` list will not result in a call to the server.
pub(crate) async fn get_user_keys(
auth: &RequestAuth,
users: &Vec<UserId>,
users: &[UserId],
) -> Result<(Vec<UserId>, Vec<WithKey<UserId>>), IronOxideErr> {
// if there aren't any users in the list, just return with empty results
if users.is_empty() {
Expand All @@ -675,7 +675,7 @@ pub(crate) async fn get_user_keys(
user_api::user_key_list(auth, users)
.await
.map(|ids_with_keys| {
users.clone().into_iter().partition_map(|user_id| {
users.to_vec().into_iter().partition_map(|user_id| {
let maybe_public_key = ids_with_keys.get(&user_id).cloned();
match maybe_public_key {
Some(pk) => Either::Right(WithKey::new(user_id, pk)),
Expand Down Expand Up @@ -732,7 +732,7 @@ fn gen_device_add_signature<CR: rand::CryptoRng + rand::RngCore>(
transform_key: &'a TransformKey,
jwt: &'a Jwt,
user_public_key: &'a PublicKey,
};
}

impl<'a> recrypt::api::Hashable for SignedMessage<'a> {
fn to_bytes(&self) -> Vec<u8> {
Expand Down
2 changes: 1 addition & 1 deletion src/internal/user_api/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ pub mod user_key_list {

pub async fn user_key_list_request(
auth: &RequestAuth,
users: &Vec<UserId>,
users: &[UserId],
) -> Result<UserKeyListResponse, IronOxideErr> {
let user_ids: Vec<&str> = users.iter().map(UserId::id).collect();
if !user_ids.is_empty() {
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@
//! # }
//! ```
#![allow(clippy::too_many_arguments)]
#![allow(clippy::type_complexity)]
// required by quick_error or IronOxideErr
#![recursion_limit = "128"]
// required as of rust 1.46.0
Expand Down Expand Up @@ -358,7 +360,7 @@ pub async fn initialize(
/// Finds the groups that the caller is an admin of that need rotation and
/// forms an InitAndRotationCheck from the user/groups needing rotation.
fn check_groups_and_collect_rotation<T>(
groups: &Vec<internal::group_api::GroupMetaResult>,
groups: &[internal::group_api::GroupMetaResult],
user_needs_rotation: bool,
account_id: UserId,
ironoxide: T,
Expand Down

0 comments on commit 7363592

Please sign in to comment.