Skip to content

Commit

Permalink
use unified rustfmt configuration for the entire project (mobilecoinf…
Browse files Browse the repository at this point in the history
…oundation#749)

* use unified rustfmt configuration for the entire project

* more rustfmt

* "fix" displaydoc multiline comments :/

* switch to forked displaydoc

* update displaydoc

* fmt
  • Loading branch information
eranrund authored Mar 17, 2021
1 parent bab7568 commit 77be6bf
Show file tree
Hide file tree
Showing 281 changed files with 3,629 additions and 2,475 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,3 @@ cpuid-bool = { git = "https://github.com/eranrund/RustCrypto-utils", rev = "74f8

# We need to patch aes-gcm so we can make some fields/functions/structs pub in order to have a constant time decrypt
aes-gcm = { git = "https://github.com/mobilecoinofficial/AEADs", rev = "d1a8517d3dd867ed9c5794002add67992a42f6aa" }

24 changes: 15 additions & 9 deletions account-keys/src/account_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ pub struct PublicAddress {
spend_public_key: RistrettoPublic,

/// This is the URL to talk to the fog report server.
/// Empty if no fog for this public address, should be parseable as mc_util_uri::FogUri.
/// Empty if no fog for this public address, should be parseable as
/// mc_util_uri::FogUri.
#[prost(string, tag = "3")]
fog_report_url: String,

Expand Down Expand Up @@ -89,7 +90,8 @@ impl fmt::Display for PublicAddress {
}

impl PublicAddress {
/// Create a new public address from CryptoNote key pair (with no account service)
/// Create a new public address from CryptoNote key pair (with no account
/// service)
///
/// # Arguments
/// `spend_public_key` - The user's public subaddress spend key `D`,
Expand All @@ -105,14 +107,17 @@ impl PublicAddress {
}
}

/// Create a new public address with specific public keys and account service name and authority sig.
/// Create a new public address with specific public keys and account
/// service name and authority sig.
///
/// # Arguments
/// `spend_public_key` - The user's public subaddress spend key `D`,
/// `view_public_key` - The user's public subaddress view key `C`,
/// `fog_report_url` - User's fog report server url
/// `fog_report_id` - The id labelling the report to use, from among the several reports which might be served by the fog report server.
/// `fog_authority_sig` - A signature over the fog authority fingerprint using the subaddress_spend_private_key
/// `fog_report_id` - The id labelling the report to use, from among the
/// several reports which might be served by the fog report server.
/// `fog_authority_sig` - A signature over the fog authority fingerprint
/// using the subaddress_spend_private_key
#[inline]
pub fn new_with_fog(
spend_public_key: &RistrettoPublic,
Expand Down Expand Up @@ -259,10 +264,10 @@ impl AccountKey {
/// * `view_private_key` - The user's private view key `a`.
/// * `fog_report_url` - Url of fog report service
/// * `fog_report_id` - The id labelling the report to use, from among the
/// several reports which might be served by the fog report server.
/// several reports which might be served by the fog report server.
/// * `fog_authority` - The DER-encoded subjectPublicKeyInfo of the fog
/// authority, which will be signed by the user when
/// constructing the public address.
/// authority, which will be signed by the user when constructing the
/// public address.
pub fn new_with_fog(
spend_private_key: &RistrettoPrivate,
view_private_key: &RistrettoPrivate,
Expand Down Expand Up @@ -579,7 +584,8 @@ mod account_key_tests {
let index = rng.next_u64();
let subaddress = account_key.subaddress(index);

// Note: The fog_authority_fingerprint is published, so it is known by the verifier.
// Note: The fog_authority_fingerprint is published, so it is known by the
// verifier.
verify_signature(&subaddress, &fog_authority_spki);
}
}
8 changes: 5 additions & 3 deletions account-keys/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
//! at least enough entropy as the length of any one of the derived keys.
//!
//! The RootIdentity object contains 32 bytes of "root entropy", used with HKDF
//! to produce the other MobileCoin private keys. This is useful because an AccountKey
//! derived this way can be represented with a smaller amount of information.
//! to produce the other MobileCoin private keys. This is useful because an
//! AccountKey derived this way can be represented with a smaller amount of
//! information.
//!
//! The other (fog-related) fields of RootIdentity are analogous to AccountKey.
Expand Down Expand Up @@ -98,7 +99,8 @@ pub struct RootIdentity {
}

impl RootIdentity {
/// Generate a random root identity with a specific fog_report_url configured
/// Generate a random root identity with a specific fog_report_url
/// configured
pub fn random_with_fog<T: RngCore + CryptoRng>(
rng: &mut T,
fog_report_url: &str,
Expand Down
5 changes: 3 additions & 2 deletions account-keys/src/view_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

//! CryptoNote-style View Key.
//!
//! A view key (a,B) contains half of a user's private information, and is used to identify
//! transaction outputs sent to the user, and to view the amounts of those outputs.
//! A view key (a,B) contains half of a user's private information, and is used
//! to identify transaction outputs sent to the user, and to view the amounts of
//! those outputs.
use core::hash::{Hash, Hasher};
use mc_crypto_keys::{RistrettoPrivate, RistrettoPublic};
Expand Down
2 changes: 1 addition & 1 deletion api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mc-watcher-api = { path = "../watcher/api" }

bs58 = "0.3.0"
crc = "1.8.1"
displaydoc = { version = "0.1.7", default-features = false }
displaydoc = { version = "0.2", default-features = false }
protobuf = "2.20"

[target.'cfg(any(target_feature = "avx2", target_feature = "avx"))'.dependencies]
Expand Down
7 changes: 4 additions & 3 deletions api/src/convert/archive_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ mod tests {
}

#[test]
// Attempting to convert an ArchiveBlock with invalid signature or contents should fail.
// Attempting to convert an ArchiveBlock with invalid signature or contents
// should fail.
fn try_from_blockchain_archive_block_rejects_invalid() {
let block_data = generate_test_blocks_data(1).pop().unwrap();

Expand Down Expand Up @@ -255,8 +256,8 @@ mod tests {
}

#[test]
// blockchain::ArchiveBlocks -> Vec<mc_transaction_core::BlockData> should fail if the blocks
// to not form a chain.
// blockchain::ArchiveBlocks -> Vec<mc_transaction_core::BlockData> should fail
// if the blocks to not form a chain.
fn test_try_from_blockchain_archive_blocks_rejects_invalid() {
let blocks_data = generate_test_blocks_data(10);
let mut archive_blocks = blockchain::ArchiveBlocks::from(&blocks_data[..]);
Expand Down
4 changes: 2 additions & 2 deletions api/src/convert/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ mod tests {

#[test]
// the blockchain::Block definition matches the Block prost attributes.
// This ensures the definition in the .proto files matches the prost attributes inside the
// Block struct.
// This ensures the definition in the .proto files matches the prost attributes
// inside the Block struct.
fn test_blockchain_block_matches_prost() {
let source_block = mc_transaction_core::Block {
id: mc_transaction_core::BlockID::try_from(&[2u8; 32][..]).unwrap(),
Expand Down
9 changes: 6 additions & 3 deletions api/src/convert/block_contents_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
use crate::{blockchain, convert::ConversionError};
use std::convert::TryFrom;

/// Convert mc_transaction_core::BlockContentsHash --> blockchain::BlockContentsHash.
/// Convert mc_transaction_core::BlockContentsHash -->
/// blockchain::BlockContentsHash.
impl From<&mc_transaction_core::BlockContentsHash> for blockchain::BlockContentsHash {
fn from(src: &mc_transaction_core::BlockContentsHash) -> Self {
let mut dst = blockchain::BlockContentsHash::new();
Expand All @@ -12,7 +13,8 @@ impl From<&mc_transaction_core::BlockContentsHash> for blockchain::BlockContents
}
}

/// Convert blockchain::BlockContentsHash --> mc_transaction_core::BlockContentsHash.
/// Convert blockchain::BlockContentsHash -->
/// mc_transaction_core::BlockContentsHash.
impl TryFrom<&blockchain::BlockContentsHash> for mc_transaction_core::BlockContentsHash {
type Error = ConversionError;

Expand All @@ -27,7 +29,8 @@ mod tests {
use super::*;

#[test]
// Unmarshalling too many bytes into a BlockContentsHash should produce an error.
// Unmarshalling too many bytes into a BlockContentsHash should produce an
// error.
fn test_from_blockchain_block_contents_hash_error() {
// Cannot convert 37 bytes to a BlockContentsHash.
let mut bad_block_contents_hash = blockchain::BlockContentsHash::new();
Expand Down
6 changes: 3 additions & 3 deletions api/src/convert/block_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ mod tests {
}

#[test]
// the blockchain::BlockSignature definition matches the BlockSignature prost attributes.
// This ensures the definition in the .proto files matches the prost attributes inside the
// BlockSignature struct.
// the blockchain::BlockSignature definition matches the BlockSignature prost
// attributes. This ensures the definition in the .proto files matches the
// prost attributes inside the BlockSignature struct.
fn test_blockchain_block_signature_matches_prost() {
let mut rng: StdRng = SeedableRng::from_seed([1u8; 32]);

Expand Down
3 changes: 2 additions & 1 deletion api/src/convert/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ pub enum ConversionError {
Other,
}

// This is needed for some code to compile, due to TryFrom being derived from From
// This is needed for some code to compile, due to TryFrom being derived from
// From
impl From<core::convert::Infallible> for ConversionError {
fn from(_src: core::convert::Infallible) -> Self {
unreachable!();
Expand Down
14 changes: 8 additions & 6 deletions api/src/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

//! Conversions between "API types" and "domain/persistence types".
//!
//! gRPC and Protobuf provide a reduced selection of types, and so there are some differences between
//! values stored in the ledger and values transmitted over the API. This module provides conversions
//! between "equivalent" types, such as `mc_api::blockchain::Block` and `mc_transaction_core::Block`.
//! gRPC and Protobuf provide a reduced selection of types, and so there are
//! some differences between values stored in the ledger and values transmitted
//! over the API. This module provides conversions between "equivalent" types,
//! such as `mc_api::blockchain::Block` and `mc_transaction_core::Block`.
mod error;

Expand Down Expand Up @@ -43,7 +44,8 @@ pub use self::error::ConversionError;

use std::path::PathBuf;

/// Helper method for getting the suggested path/filename for a given block index.
/// Helper method for getting the suggested path/filename for a given block
/// index.
pub fn block_num_to_s3block_path(block_index: mc_transaction_core::BlockIndex) -> PathBuf {
let filename = format!("{:016x}.pb", block_index);
let mut path = PathBuf::new();
Expand All @@ -55,8 +57,8 @@ pub fn block_num_to_s3block_path(block_index: mc_transaction_core::BlockIndex) -
}

/// Helper method for getting the suggested path/filename of a "merged block".
/// A "merged block" is a consecutive collection of blocks that were joined together to speed up
/// ledger syncing.
/// A "merged block" is a consecutive collection of blocks that were joined
/// together to speed up ledger syncing.
/// `bucket_size` specifies how many blocks are expected to be joined together.
pub fn merged_block_num_to_s3block_path(
bucket_size: u64,
Expand Down
3 changes: 2 additions & 1 deletion api/src/convert/public_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ mod tests {
use mc_account_keys::AccountKey;
use rand::{rngs::StdRng, SeedableRng};

// Test converting between external::PublicAddress and account_keys::PublicAddress
// Test converting between external::PublicAddress and
// account_keys::PublicAddress
#[test]
fn test_public_address_conversion() {
let mut rng: StdRng = SeedableRng::from_seed([123u8; 32]);
Expand Down
6 changes: 4 additions & 2 deletions api/src/convert/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ mod tests {
let charlie = AccountKey::random(&mut rng);

let minted_outputs: Vec<TxOut> = {
// Mint an initial collection of outputs, including one belonging to `sender_account`.
// Mint an initial collection of outputs, including one belonging to
// `sender_account`.
let mut recipient_and_amounts: Vec<(PublicAddress, u64)> = Vec::new();
recipient_and_amounts.push((alice.default_subaddress(), 65536));

Expand Down Expand Up @@ -104,7 +105,8 @@ mod tests {
assert_eq!(tx, recovered_tx);
}

// Converting mc_transaction_core::Tx -> external::Tx -> mc_transaction_core::Tx should be the identity function.
// Converting mc_transaction_core::Tx -> external::Tx -> mc_transaction_core::Tx
// should be the identity function.
{
let external_tx: external::Tx = external::Tx::from(&tx);
let recovered_tx: Tx = Tx::try_from(&external_tx).unwrap();
Expand Down
6 changes: 4 additions & 2 deletions api/src/convert/tx_out_confirmation_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ mod tests {
}

#[test]
// Unmarshalling too many bytes into a TxOutConfirmationNumber should produce an error.
// Unmarshalling too many bytes into a TxOutConfirmationNumber should produce an
// error.
fn test_confirmation_number_try_from_too_many_bytes() {
let mut source = external::TxOutConfirmationNumber::new();
source.set_hash(vec![7u8; 99]); // Too many bytes.
assert!(tx::TxOutConfirmationNumber::try_from(&source).is_err());
}

#[test]
// Unmarshalling too few bytes into a TxOutConfirmationNumber should produce an error.
// Unmarshalling too few bytes into a TxOutConfirmationNumber should produce an
// error.
fn test_confirmation_number_try_from_too_few_bytes() {
let mut source = external::TxOutConfirmationNumber::new();
source.set_hash(vec![7u8; 3]); // Too few bytes.
Expand Down
4 changes: 2 additions & 2 deletions api/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub enum Error {
}

/// A little-endian IEEE CRC32 checksum is prepended to payloads.
/// Since this is public information with a possibility of transcription failure,
/// a checksum is more appropriate than a hash function
/// Since this is public information with a possibility of transcription
/// failure, a checksum is more appropriate than a hash function
fn calculate_checksum(data: &[u8]) -> [u8; 4] {
crc32::checksum_ieee(data).to_le_bytes()
}
Expand Down
3 changes: 2 additions & 1 deletion api/tests/prost.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Tests that prost-versions of structures round-trip with the versions generated from external.proto
//! Tests that prost-versions of structures round-trip with the versions
//! generated from external.proto
use mc_account_keys::{AccountKey, PublicAddress, RootIdentity, ViewKey};
use mc_api::external;
Expand Down
2 changes: 1 addition & 1 deletion attest/ake/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mc-crypto-noise = { path = "../../crypto/noise", default-features = false }

aead = "0.3"
digest = { version = "0.9", default-features = false }
displaydoc = { version = "0.1.7", default-features = false }
displaydoc = { version = "0.2", default-features = false }
prost = { version = "0.6.1", default-features = false, features = ["prost-derive"] }
rand_core = "0.5"
serde = { version = "1.0", default-features = false, features = ["alloc"] }
Expand Down
2 changes: 1 addition & 1 deletion attest/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ bitflags = "1.2"
cfg-if = "0.1"
chrono = { version = "0.4.10", default-features = false, features = ["alloc"] }
digest = { version = "0.9", default-features = false }
displaydoc = { version = "0.1.7", default-features = false }
displaydoc = { version = "0.2", default-features = false }
failure = { version = "0.1.8", default-features = false, features = ["derive"] }
hex_fmt = "0.3"
rjson = "0.3.1"
Expand Down
7 changes: 0 additions & 7 deletions attest/core/rustfmt.toml

This file was deleted.

Loading

0 comments on commit 77be6bf

Please sign in to comment.