Skip to content

Commit

Permalink
Use stable rustfmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
briansmith committed Apr 10, 2019
1 parent 9f21115 commit f0d4d21
Show file tree
Hide file tree
Showing 60 changed files with 1,082 additions and 406 deletions.
71 changes: 51 additions & 20 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,18 @@ struct Target {
}

impl Target {
pub fn arch(&self) -> &str { &self.arch }
pub fn os(&self) -> &str { &self.os }
pub fn env(&self) -> &str { &self.env }
pub fn is_debug(&self) -> bool { self.is_debug }
pub fn arch(&self) -> &str {
&self.arch
}
pub fn os(&self) -> &str {
&self.os
}
pub fn env(&self) -> &str {
&self.env
}
pub fn is_debug(&self) -> bool {
self.is_debug
}
}

fn build_c_code(target: &Target, pregenerated: PathBuf, out_dir: &Path) {
Expand Down Expand Up @@ -440,8 +448,13 @@ fn build_c_code(target: &Target, pregenerated: PathBuf, out_dir: &Path) {
}

fn build_library(
target: &Target, out_dir: &Path, lib_name: &str, srcs: &[PathBuf], additional_srcs: &[PathBuf],
warnings_are_errors: bool, includes_modified: SystemTime,
target: &Target,
out_dir: &Path,
lib_name: &str,
srcs: &[PathBuf],
additional_srcs: &[PathBuf],
warnings_are_errors: bool,
includes_modified: SystemTime,
) {
// Compile all the (dirty) source files into object files.
let objs = additional_srcs
Expand All @@ -468,10 +481,10 @@ fn build_library(
"macos" => {
let _ = c.flag("-fPIC");
let _ = c.flag("-Wl,-dead_strip");
},
}
_ => {
let _ = c.flag("-Wl,--gc-sections".into());
},
}
}
for o in objs {
let _ = c.object(o);
Expand All @@ -494,7 +507,10 @@ fn build_library(
}

fn compile(
p: &Path, target: &Target, warnings_are_errors: bool, out_dir: &Path,
p: &Path,
target: &Target,
warnings_are_errors: bool,
out_dir: &Path,
includes_modified: SystemTime,
) -> String {
let ext = p.extension().unwrap().to_str().unwrap();
Expand Down Expand Up @@ -523,15 +539,20 @@ fn obj_path(out_dir: &Path, src: &Path, obj_ext: &str) -> PathBuf {
}

fn cc(
file: &Path, ext: &str, target: &Target, warnings_are_errors: bool, out_dir: &Path,
file: &Path,
ext: &str,
target: &Target,
warnings_are_errors: bool,
out_dir: &Path,
) -> Command {
let mut c = cc::Build::new();
let _ = c.include("include");
match ext {
"c" =>
"c" => {
for f in c_flags(target) {
let _ = c.flag(f);
},
}
}
"S" => (),
e => panic!("Unsupported file extension: {:?}", e),
};
Expand All @@ -546,11 +567,11 @@ fn cc(
// ``-gfull`` is required for Darwin's |-dead_strip|.
("macos", _) => {
let _ = c.flag("-gfull");
},
}
(_, "msvc") => (),
_ => {
let _ = c.flag("-g3");
},
}
};
if !target.is_debug() {
let _ = c.define("NDEBUG", None);
Expand Down Expand Up @@ -646,7 +667,10 @@ fn sources_for_arch(arch: &str) -> Vec<PathBuf> {
}

fn perlasm_src_dsts(
out_dir: &Path, arch: &str, os: Option<&str>, perlasm_format: &str,
out_dir: &Path,
arch: &str,
os: Option<&str>,
perlasm_format: &str,
) -> Vec<(PathBuf, PathBuf)> {
let srcs = sources_for_arch(arch);
let mut src_dsts = srcs
Expand Down Expand Up @@ -683,7 +707,9 @@ fn asm_srcs(perlasm_src_dsts: Vec<(PathBuf, PathBuf)>) -> Vec<PathBuf> {
.collect::<Vec<_>>()
}

fn is_perlasm(path: &PathBuf) -> bool { path.extension().unwrap().to_str().unwrap() == "pl" }
fn is_perlasm(path: &PathBuf) -> bool {
path.extension().unwrap().to_str().unwrap() == "pl"
}

fn asm_path(out_dir: &Path, src: &Path, os: Option<&str>, perlasm_format: &str) -> PathBuf {
let src_stem = src.file_stem().expect("source file without basename");
Expand All @@ -695,7 +721,9 @@ fn asm_path(out_dir: &Path, src: &Path, os: Option<&str>, perlasm_format: &str)
}

fn perlasm(
src_dst: &[(PathBuf, PathBuf)], arch: &str, perlasm_format: &str,
src_dst: &[(PathBuf, PathBuf)],
arch: &str,
perlasm_format: &str,
includes_modified: Option<SystemTime>,
) {
for (src, dst) in src_dst {
Expand Down Expand Up @@ -744,7 +772,9 @@ fn file_modified(path: &Path) -> SystemTime {
.expect("nah")
}

fn get_command(var: &str, default: &str) -> String { std::env::var(var).unwrap_or(default.into()) }
fn get_command(var: &str, default: &str) -> String {
std::env::var(var).unwrap_or(default.into())
}

fn check_all_files_tracked() {
for path in &["crypto", "include", "third_party/fiat"] {
Expand All @@ -757,8 +787,9 @@ fn is_tracked(file: &DirEntry) {
let cmp = |f| p == PathBuf::from(f);
let tracked = match p.extension().and_then(|p| p.to_str()) {
Some("h") | Some("inl") => RING_INCLUDES.iter().any(cmp),
Some("c") | Some("S") | Some("asm") =>
RING_SRCS.iter().any(|(_, f)| cmp(f)) || RING_TEST_SRCS.iter().any(cmp),
Some("c") | Some("S") | Some("asm") => {
RING_SRCS.iter().any(|(_, f)| cmp(f)) || RING_TEST_SRCS.iter().any(cmp)
}
Some("pl") => RING_SRCS.iter().any(|(_, f)| cmp(f)) || RING_PERL_INCLUDES.iter().any(cmp),
_ => true,
};
Expand Down
8 changes: 0 additions & 8 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
edition = "2018"
fn_args_density = "Compressed"
fn_single_line = true
match_arm_blocks = false
match_block_trailing_comma = true
max_width = 100
merge_imports = true
newline_style = "Unix"
reorder_imports = true
trailing_comma = "Vertical"
use_field_init_shorthand = true
use_try_shorthand = true
wrap_comments = true
64 changes: 49 additions & 15 deletions src/aead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ impl OpeningKey {
/// `key_bytes` must be exactly `algorithm.key_len` bytes long.
#[inline]
pub fn new(
algorithm: &'static Algorithm, key_bytes: &[u8],
algorithm: &'static Algorithm,
key_bytes: &[u8],
) -> Result<Self, error::Unspecified> {
Ok(Self {
key: Key::new(algorithm, key_bytes)?,
Expand All @@ -63,7 +64,9 @@ impl OpeningKey {

/// The key's AEAD algorithm.
#[inline(always)]
pub fn algorithm(&self) -> &'static Algorithm { self.key.algorithm() }
pub fn algorithm(&self) -> &'static Algorithm {
self.key.algorithm()
}
}

/// Authenticates and decrypts (“opens”) data in place.
Expand Down Expand Up @@ -111,7 +114,10 @@ impl OpeningKey {
/// does not allow us to have two slices, one mutable and one immutable, that
/// reference overlapping memory.)
pub fn open_in_place<'a, A: AsRef<[u8]>>(
key: &OpeningKey, nonce: Nonce, Aad(aad): Aad<A>, in_prefix_len: usize,
key: &OpeningKey,
nonce: Nonce,
Aad(aad): Aad<A>,
in_prefix_len: usize,
ciphertext_and_tag_modified_in_place: &'a mut [u8],
) -> Result<&'a mut [u8], error::Unspecified> {
open_in_place_(
Expand All @@ -124,7 +130,10 @@ pub fn open_in_place<'a, A: AsRef<[u8]>>(
}

fn open_in_place_<'a>(
key: &OpeningKey, nonce: Nonce, aad: Aad<&[u8]>, in_prefix_len: usize,
key: &OpeningKey,
nonce: Nonce,
aad: Aad<&[u8]>,
in_prefix_len: usize,
ciphertext_and_tag_modified_in_place: &'a mut [u8],
) -> Result<&'a mut [u8], error::Unspecified> {
let ciphertext_and_tag_len = ciphertext_and_tag_modified_in_place
Expand Down Expand Up @@ -178,7 +187,8 @@ impl SealingKey {
/// Constructs a new sealing key from `key_bytes`.
#[inline]
pub fn new(
algorithm: &'static Algorithm, key_bytes: &[u8],
algorithm: &'static Algorithm,
key_bytes: &[u8],
) -> Result<Self, error::Unspecified> {
Ok(Self {
key: Key::new(algorithm, key_bytes)?,
Expand All @@ -187,7 +197,9 @@ impl SealingKey {

/// The key's AEAD algorithm.
#[inline(always)]
pub fn algorithm(&self) -> &'static Algorithm { self.key.algorithm() }
pub fn algorithm(&self) -> &'static Algorithm {
self.key.algorithm()
}
}

/// Encrypts and signs (“seals”) data in place.
Expand All @@ -208,7 +220,11 @@ impl SealingKey {
///
/// `aad` is the additional authenticated data, if any.
pub fn seal_in_place<A: AsRef<[u8]>>(
key: &SealingKey, nonce: Nonce, Aad(aad): Aad<A>, in_out: &mut [u8], out_suffix_capacity: usize,
key: &SealingKey,
nonce: Nonce,
Aad(aad): Aad<A>,
in_out: &mut [u8],
out_suffix_capacity: usize,
) -> Result<usize, error::Unspecified> {
seal_in_place_(
key,
Expand All @@ -220,7 +236,11 @@ pub fn seal_in_place<A: AsRef<[u8]>>(
}

fn seal_in_place_(
key: &SealingKey, nonce: Nonce, aad: Aad<&[u8]>, in_out: &mut [u8], out_suffix_capacity: usize,
key: &SealingKey,
nonce: Nonce,
aad: Aad<&[u8]>,
in_out: &mut [u8],
out_suffix_capacity: usize,
) -> Result<usize, error::Unspecified> {
if out_suffix_capacity < key.key.algorithm.tag_len() {
return Err(error::Unspecified);
Expand Down Expand Up @@ -248,12 +268,16 @@ pub struct Aad<A: AsRef<[u8]>>(A);
impl<A: AsRef<[u8]>> Aad<A> {
/// Construct the `Aad` from the given bytes.
#[inline]
pub fn from(aad: A) -> Self { Aad(aad) }
pub fn from(aad: A) -> Self {
Aad(aad)
}
}

impl Aad<[u8; 0]> {
/// Construct an empty `Aad`.
pub fn empty() -> Self { Self::from([]) }
pub fn empty() -> Self {
Self::from([])
}
}

/// `OpeningKey` and `SealingKey` are type-safety wrappers around `Key`, which
Expand Down Expand Up @@ -291,7 +315,9 @@ impl Key {

/// The key's AEAD algorithm.
#[inline(always)]
fn algorithm(&self) -> &'static Algorithm { self.algorithm }
fn algorithm(&self) -> &'static Algorithm {
self.algorithm
}
}

/// An AEAD Algorithm.
Expand Down Expand Up @@ -332,17 +358,23 @@ const fn max_input_len(block_len: usize, overhead_blocks_per_nonce: usize) -> u6
impl Algorithm {
/// The length of the key.
#[inline(always)]
pub fn key_len(&self) -> usize { self.key_len }
pub fn key_len(&self) -> usize {
self.key_len
}

/// The length of a tag.
///
/// See also `MAX_TAG_LEN`.
#[inline(always)]
pub fn tag_len(&self) -> usize { TAG_LEN }
pub fn tag_len(&self) -> usize {
TAG_LEN
}

/// The length of the nonces.
#[inline(always)]
pub fn nonce_len(&self) -> usize { NONCE_LEN }
pub fn nonce_len(&self) -> usize {
NONCE_LEN
}
}

derive_debug_via_id!(Algorithm);
Expand All @@ -355,7 +387,9 @@ enum AlgorithmID {
}

impl PartialEq for Algorithm {
fn eq(&self, other: &Self) -> bool { self.id == other.id }
fn eq(&self, other: &Self) -> bool {
self.id == other.id
}
}

impl Eq for Algorithm {}
Expand Down
Loading

0 comments on commit f0d4d21

Please sign in to comment.