Skip to content

Commit

Permalink
Wrap rust comments (#512)
Browse files Browse the repository at this point in the history
Add a `rustfmt.toml` config with the following options:

- comment_width: 100
- wrap_comments: true
- group_imports: "StdExternalCrate"
- imports_granularity: "Crate"

This sorts and groups imports. And wraps long comments. Unfortunately
all of these configs are "unstable" and we need nightly cargo-fmt in
order to run them.
  • Loading branch information
Hinton authored Jan 22, 2024
1 parent 785e7c4 commit 0e9b64f
Show file tree
Hide file tree
Showing 38 changed files with 164 additions and 114 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ jobs:
with:
toolchain: stable

- name: Install rust nightly
run: |
rustup toolchain install nightly
rustup component add rustfmt --toolchain nightly-x86_64-unknown-linux-gnu
- name: Cache cargo registry
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3

- name: Cargo fmt
run: cargo fmt --check
run: cargo +nightly fmt --check

- name: Set up Node
uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1
Expand Down
9 changes: 6 additions & 3 deletions crates/bitwarden-api-api/src/apis/access_policies_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,24 @@ pub enum AccessPoliciesIdPutError {
UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`organizations_id_access_policies_people_potential_grantees_get`]
/// struct for typed errors of method
/// [`organizations_id_access_policies_people_potential_grantees_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OrganizationsIdAccessPoliciesPeoplePotentialGranteesGetError {
UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`organizations_id_access_policies_projects_potential_grantees_get`]
/// struct for typed errors of method
/// [`organizations_id_access_policies_projects_potential_grantees_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OrganizationsIdAccessPoliciesProjectsPotentialGranteesGetError {
UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`organizations_id_access_policies_service_accounts_potential_grantees_get`]
/// struct for typed errors of method
/// [`organizations_id_access_policies_service_accounts_potential_grantees_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OrganizationsIdAccessPoliciesServiceAccountsPotentialGranteesGetError {
Expand Down
6 changes: 4 additions & 2 deletions crates/bitwarden-api-api/src/apis/collections_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ pub enum OrganizationsOrgIdCollectionsIdDeletePostError {
UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`organizations_org_id_collections_id_delete_user_org_user_id_post`]
/// struct for typed errors of method
/// [`organizations_org_id_collections_id_delete_user_org_user_id_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OrganizationsOrgIdCollectionsIdDeleteUserOrgUserIdPostError {
Expand Down Expand Up @@ -97,7 +98,8 @@ pub enum OrganizationsOrgIdCollectionsIdPutError {
UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`organizations_org_id_collections_id_user_org_user_id_delete`]
/// struct for typed errors of method
/// [`organizations_org_id_collections_id_user_org_user_id_delete`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OrganizationsOrgIdCollectionsIdUserOrgUserIdDeleteError {
Expand Down
3 changes: 2 additions & 1 deletion crates/bitwarden-api-api/src/apis/groups_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ pub enum OrganizationsOrgIdGroupsIdDeletePostError {
UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`organizations_org_id_groups_id_delete_user_org_user_id_post`]
/// struct for typed errors of method
/// [`organizations_org_id_groups_id_delete_user_org_user_id_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OrganizationsOrgIdGroupsIdDeleteUserOrgUserIdPostError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ pub enum OrganizationsConnectionsEnabledGetError {
UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`organizations_connections_organization_connection_id_delete`]
/// struct for typed errors of method
/// [`organizations_connections_organization_connection_id_delete`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OrganizationsConnectionsOrganizationConnectionIdDeleteError {
UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`organizations_connections_organization_connection_id_delete_post`]
/// struct for typed errors of method
/// [`organizations_connections_organization_connection_id_delete_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OrganizationsConnectionsOrganizationConnectionIdDeletePostError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,24 @@ pub enum OrganizationSponsorshipSponsoredSponsoredOrgIdDeleteError {
UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`organization_sponsorship_sponsored_sponsored_org_id_remove_post`]
/// struct for typed errors of method
/// [`organization_sponsorship_sponsored_sponsored_org_id_remove_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OrganizationSponsorshipSponsoredSponsoredOrgIdRemovePostError {
UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`organization_sponsorship_sponsoring_org_id_families_for_enterprise_post`]
/// struct for typed errors of method
/// [`organization_sponsorship_sponsoring_org_id_families_for_enterprise_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OrganizationSponsorshipSponsoringOrgIdFamiliesForEnterprisePostError {
UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`organization_sponsorship_sponsoring_org_id_families_for_enterprise_resend_post`]
/// struct for typed errors of method
/// [`organization_sponsorship_sponsoring_org_id_families_for_enterprise_resend_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OrganizationSponsorshipSponsoringOrgIdFamiliesForEnterpriseResendPostError {
Expand All @@ -62,7 +65,8 @@ pub enum OrganizationSponsorshipSponsoringOrganizationIdDeleteError {
UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`organization_sponsorship_sponsoring_organization_id_delete_post`]
/// struct for typed errors of method
/// [`organization_sponsorship_sponsoring_organization_id_delete_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OrganizationSponsorshipSponsoringOrganizationIdDeletePostError {
Expand Down
9 changes: 6 additions & 3 deletions crates/bitwarden-api-api/src/apis/organization_users_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,16 @@ pub enum OrganizationsOrgIdUsersInvitePostError {
UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`organizations_org_id_users_organization_user_id_accept_init_post`]
/// struct for typed errors of method
/// [`organizations_org_id_users_organization_user_id_accept_init_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OrganizationsOrgIdUsersOrganizationUserIdAcceptInitPostError {
UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`organizations_org_id_users_organization_user_id_accept_post`]
/// struct for typed errors of method
/// [`organizations_org_id_users_organization_user_id_accept_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OrganizationsOrgIdUsersOrganizationUserIdAcceptPostError {
Expand Down Expand Up @@ -230,7 +232,8 @@ pub enum OrganizationsOrgIdUsersRevokePutError {
UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`organizations_org_id_users_user_id_reset_password_enrollment_put`]
/// struct for typed errors of method
/// [`organizations_org_id_users_user_id_reset_password_enrollment_put`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OrganizationsOrgIdUsersUserIdResetPasswordEnrollmentPutError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,24 @@ use reqwest;
use super::{configuration, Error};
use crate::apis::ResponseContent;

/// struct for typed errors of method [`organization_sponsorship_self_hosted_sponsoring_org_id_delete`]
/// struct for typed errors of method
/// [`organization_sponsorship_self_hosted_sponsoring_org_id_delete`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OrganizationSponsorshipSelfHostedSponsoringOrgIdDeleteError {
UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`organization_sponsorship_self_hosted_sponsoring_org_id_delete_post`]
/// struct for typed errors of method
/// [`organization_sponsorship_self_hosted_sponsoring_org_id_delete_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OrganizationSponsorshipSelfHostedSponsoringOrgIdDeletePostError {
UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`organization_sponsorship_self_hosted_sponsoring_org_id_families_for_enterprise_post`]
/// struct for typed errors of method
/// [`organization_sponsorship_self_hosted_sponsoring_org_id_families_for_enterprise_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OrganizationSponsorshipSelfHostedSponsoringOrgIdFamiliesForEnterprisePostError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ pub struct SsoConfigurationData {
skip_serializing_if = "Option::is_none"
)]
pub member_decryption_type: Option<crate::models::MemberDecryptionType>,
/// Legacy property to determine if KeyConnector was enabled. Kept for backwards compatibility with old configs that will not have the new Bit.Core.Auth.Models.Data.SsoConfigurationData.MemberDecryptionType when deserialized from the database.
/// Legacy property to determine if KeyConnector was enabled. Kept for backwards compatibility
/// with old configs that will not have the new
/// Bit.Core.Auth.Models.Data.SsoConfigurationData.MemberDecryptionType when deserialized from
/// the database.
#[serde(
rename = "keyConnectorEnabled",
skip_serializing_if = "Option::is_none"
Expand Down
3 changes: 2 additions & 1 deletion crates/bitwarden-crypto/src/aes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ pub(crate) fn decrypt_aes256(
.decrypt_padded_mut::<Pkcs7>(&mut data)
.map_err(|_| CryptoError::KeyDecrypt)?;

// Data is decrypted in place and returns a subslice of the original Vec, to avoid cloning it, we truncate to the subslice length
// Data is decrypted in place and returns a subslice of the original Vec, to avoid cloning it,
// we truncate to the subslice length
let decrypted_len = decrypted_key_slice.len();
data.truncate(decrypted_len);

Expand Down
17 changes: 9 additions & 8 deletions crates/bitwarden-crypto/src/enc_string/asymmetric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ use crate::{

/// # Encrypted string primitive
///
/// [AsymmetricEncString] is a Bitwarden specific primitive that represents an asymmetrically encrypted string.
/// They are used together with the KeyDecryptable and KeyEncryptable traits to encrypt and decrypt data using
/// [AsymmetricCryptoKey]s.
/// [AsymmetricEncString] is a Bitwarden specific primitive that represents an asymmetrically
/// encrypted string. They are used together with the KeyDecryptable and KeyEncryptable traits to
/// encrypt and decrypt data using [AsymmetricCryptoKey]s.
///
/// The flexibility of the [AsymmetricEncString] type allows for different encryption algorithms to be used
/// which is represented by the different variants of the enum.
/// The flexibility of the [AsymmetricEncString] type allows for different encryption algorithms to
/// be used which is represented by the different variants of the enum.
///
/// ## Note
///
Expand All @@ -30,8 +30,8 @@ use crate::{
///
/// ## Serialization
///
/// [AsymmetricEncString] implements [Display] and [FromStr] to allow for easy serialization and uses a
/// custom scheme to represent the different variants.
/// [AsymmetricEncString] implements [Display] and [FromStr] to allow for easy serialization and
/// uses a custom scheme to represent the different variants.
///
/// The scheme is one of the following schemes:
/// - `[type].[data]`
Expand All @@ -54,7 +54,8 @@ pub enum AsymmetricEncString {
Rsa2048_OaepSha1_HmacSha256_B64 { data: Vec<u8>, mac: Vec<u8> },
}

/// To avoid printing sensitive information, [AsymmetricEncString] debug prints to `AsymmetricEncString`.
/// To avoid printing sensitive information, [AsymmetricEncString] debug prints to
/// `AsymmetricEncString`.
impl std::fmt::Debug for AsymmetricEncString {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("AsymmetricEncString").finish()
Expand Down
6 changes: 3 additions & 3 deletions crates/bitwarden-crypto/src/enc_string/symmetric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use crate::{

/// # Encrypted string primitive
///
/// [EncString] is a Bitwarden specific primitive that represents a symmetrically encrypted string. They are
/// are used together with the [KeyDecryptable] and [KeyEncryptable] traits to encrypt and decrypt
/// data using [SymmetricCryptoKey]s.
/// [EncString] is a Bitwarden specific primitive that represents a symmetrically encrypted string.
/// They are are used together with the [KeyDecryptable] and [KeyEncryptable] traits to encrypt and
/// decrypt data using [SymmetricCryptoKey]s.
///
/// The flexibility of the [EncString] type allows for different encryption algorithms to be used
/// which is represented by the different variants of the enum.
Expand Down
3 changes: 2 additions & 1 deletion crates/bitwarden-crypto/src/keys/shareable_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ pub fn derive_shareable_key(
) -> SymmetricCryptoKey {
// Because all inputs are fixed size, we can unwrap all errors here without issue

// TODO: Are these the final `key` and `info` parameters or should we change them? I followed the pattern used for sends
// TODO: Are these the final `key` and `info` parameters or should we change them? I followed
// the pattern used for sends
let res = Hmac::<sha2::Sha256>::new_from_slice(format!("bitwarden-{}", name).as_bytes())
.unwrap()
.chain_update(secret)
Expand Down
12 changes: 8 additions & 4 deletions crates/bitwarden-generators/src/passphrase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ pub struct PassphraseGeneratorRequest {
pub word_separator: String,
/// When set to true, capitalize the first letter of each word in the generated passphrase.
pub capitalize: bool,
/// When set to true, include a number at the end of one of the words in the generated passphrase.
/// When set to true, include a number at the end of one of the words in the generated
/// passphrase.
pub include_number: bool,
}

Expand All @@ -45,7 +46,8 @@ const MINIMUM_PASSPHRASE_NUM_WORDS: u8 = 3;
const MAXIMUM_PASSPHRASE_NUM_WORDS: u8 = 20;

/// Represents a set of valid options to generate a passhprase with.
/// To get an instance of it, use [`PassphraseGeneratorRequest::validate_options`](PassphraseGeneratorRequest::validate_options)
/// To get an instance of it, use
/// [`PassphraseGeneratorRequest::validate_options`](PassphraseGeneratorRequest::validate_options)
struct ValidPassphraseGeneratorOptions {
pub(super) num_words: u8,
pub(super) word_separator: String,
Expand All @@ -54,7 +56,8 @@ struct ValidPassphraseGeneratorOptions {
}

impl PassphraseGeneratorRequest {
/// Validates the request and returns an immutable struct with valid options to use with the passphrase generator.
/// Validates the request and returns an immutable struct with valid options to use with the
/// passphrase generator.
fn validate_options(self) -> Result<ValidPassphraseGeneratorOptions, PassphraseError> {
// TODO: Add password generator policy checks

Expand Down Expand Up @@ -173,7 +176,8 @@ mod tests {

let input = PassphraseGeneratorRequest {
num_words: 4,
word_separator: "πŸ‘¨πŸ»β€β€οΈβ€πŸ’‹β€πŸ‘¨πŸ»".into(), // This emoji is 35 bytes long, but represented as a single character
word_separator: "πŸ‘¨πŸ»β€β€οΈβ€πŸ’‹β€πŸ‘¨πŸ»".into(), /* This emoji is 35 bytes long, but represented
* as a single character */
capitalize: false,
include_number: true,
}
Expand Down
9 changes: 6 additions & 3 deletions crates/bitwarden-generators/src/password.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ impl CharSet {
self.include_if(true, other)
}

/// Includes the given characters in the set if the predicate is true. Any duplicate items will be ignored
/// Includes the given characters in the set if the predicate is true. Any duplicate items will
/// be ignored
pub fn include_if(mut self, predicate: bool, other: impl IntoIterator<Item = char>) -> Self {
if predicate {
self.0.extend(other);
Expand Down Expand Up @@ -122,7 +123,8 @@ impl Distribution<char> for CharSet {
}

/// Represents a set of valid options to generate a password with.
/// To get an instance of it, use [`PasswordGeneratorRequest::validate_options`](PasswordGeneratorRequest::validate_options)
/// To get an instance of it, use
/// [`PasswordGeneratorRequest::validate_options`](PasswordGeneratorRequest::validate_options)
struct PasswordGeneratorOptions {
pub(super) lower: (CharSet, usize),
pub(super) upper: (CharSet, usize),
Expand All @@ -134,7 +136,8 @@ struct PasswordGeneratorOptions {
}

impl PasswordGeneratorRequest {
/// Validates the request and returns an immutable struct with valid options to use with the password generator.
/// Validates the request and returns an immutable struct with valid options to use with the
/// password generator.
fn validate_options(self) -> Result<PasswordGeneratorOptions, PasswordError> {
// TODO: Add password generator policy checks

Expand Down
Loading

0 comments on commit 0e9b64f

Please sign in to comment.