From 1c8b13242d49088494403897b4b52c6d9a518827 Mon Sep 17 00:00:00 2001 From: Alberto Sonnino Date: Mon, 20 May 2024 16:18:26 +0100 Subject: [PATCH] configure pre-commit hooks --- .editorconfig | 32 ++++++++++++++++ .licensesnip | 2 + .pre-commit-config.yaml | 81 ++++++++++++++++++++++++++++++++++++++++ deny.toml | 72 +++++++++++++++++++++++++++++++++++ licensesnip.config.jsonc | 8 ++++ src/bip39.rs | 14 ++++--- src/gf256.rs | 6 ++- src/main.rs | 7 +++- src/shamir.rs | 3 ++ src/utils.rs | 3 ++ tarpaulin.toml | 12 ++++++ 11 files changed, 233 insertions(+), 7 deletions(-) create mode 100644 .editorconfig create mode 100644 .licensesnip create mode 100644 .pre-commit-config.yaml create mode 100644 deny.toml create mode 100644 licensesnip.config.jsonc create mode 100644 tarpaulin.toml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..8e5d587 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,32 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# editorconfig.org + +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +max_line_length = 100 +trim_trailing_whitespace = true + +[*.md] +indent_size = unset +max_line_length = 150 + +[{*.yml,*.yaml,*.toml}] +indent_size = 2 +max_line_length = 150 + +# Ignore paths +[{.git/**/*,**/*.lock,LICENSE}] +charset = unset +end_of_line = unset +indent_size = unset +indent_style = unset +insert_final_newline = unset +max_line_length = unset +trim_trailing_whitespace = unset diff --git a/.licensesnip b/.licensesnip new file mode 100644 index 0000000..591b633 --- /dev/null +++ b/.licensesnip @@ -0,0 +1,2 @@ +Copyright (c) Alberto Sonnino +SPDX-License-Identifier: Apache-2.0 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..ec67b9d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,81 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-merge-conflict + - id: check-yaml + - id: trailing-whitespace + - id: check-symlinks + - id: end-of-file-fixer + - id: mixed-line-ending + - id: trailing-whitespace + - repo: https://github.com/editorconfig-checker/editorconfig-checker.python + rev: "2.7.3" + hooks: + - id: editorconfig-checker + alias: ec + - repo: https://github.com/notken12/licensesnip + rev: 19b1186 + hooks: + - id: licensesnip + args: [] + pass_filenames: false + - repo: https://github.com/crate-ci/typos + rev: v1.19.0 + hooks: + - id: typos + pass_filenames: false + - repo: https://github.com/DevinR528/cargo-sort + rev: v1.0.9 + hooks: + - id: cargo-sort + args: ["--workspace"] + - repo: https://github.com/EmbarkStudios/cargo-deny + rev: 0.14.19 + hooks: + - id: cargo-deny + - repo: local + hooks: + - id: cargo-fmt + name: cargo-fmt + entry: cargo fmt + args: + - "--" + - "--config" + - "group_imports=StdExternalCrate,imports_granularity=Crate,imports_layout=HorizontalVertical" + language: rust + types: [rust] + pass_filenames: false + - id: cargo-check + name: cargo-check + entry: cargo check + language: rust + files: ^(crates/|Cargo\.(toml|lock)$) + pass_filenames: false + - id: cargo-test + name: cargo-test + entry: cargo test + language: rust + files: ^(crates/|Cargo\.(toml|lock)$) + pass_filenames: false + - id: clippy-with-tests + name: clippy-with-tests + entry: cargo clippy + args: ["--all-features", "--tests", "--", "-D", "warnings"] + language: rust + files: ^(crates/|Cargo\.(toml|lock)$) + pass_filenames: false + - id: clippy + name: clippy + entry: cargo clippy + args: ["--all-features", "--", "-D", "warnings"] + language: rust + files: ^(crates/|Cargo\.(toml|lock)$) + pass_filenames: false + - id: cargo-doc + name: cargo-doc + entry: env RUSTDOCFLAGS="-D warnings" cargo doc + args: ["--workspace", "--no-deps"] + language: rust + files: ^(crates/|Cargo\.(toml|lock)$) + pass_filenames: false diff --git a/deny.toml b/deny.toml new file mode 100644 index 0000000..98ac514 --- /dev/null +++ b/deny.toml @@ -0,0 +1,72 @@ +# This section is considered when running `cargo deny check advisories` +# More documentation for the advisories section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/advisories/cfg.html +[advisories] +version = 2 +ignore = [ + "RUSTSEC-2023-0071", + # Difference 2.0.0 is unmaintained. + "RUSTSEC-2020-0095", + # Rust-yaml is not maintained, but is a dependency in many of our packages. + "RUSTSEC-2024-0320", + # Ignore the h2 advisory as we do not have control over most of the H2 usage. + "RUSTSEC-2024-0332", +] + +# This section is considered when running `cargo deny check licenses` +# More documentation for the licenses section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/licenses/cfg.html +[licenses] +version = 2 +# List of explicitly allowed licenses +# See https://spdx.org/licenses/ for list of possible licenses +# [possible values: any SPDX 3.11 short identifier (+ optional exception)]. +allow = [ + "Apache-2.0", + "BSD-3-Clause", + "LicenseRef-ring", + "MIT", + "Unicode-DFS-2016", +] +# The confidence threshold for detecting a license from license text. +# The higher the value, the more closely the license text must be to the +# canonical license text of a valid SPDX license file. +# [possible values: any between 0.0 and 1.0]. +confidence-threshold = 0.8 + +[[licenses.clarify]] +name = "ring" +expression = "LicenseRef-ring" +license-files = [{ path = "LICENSE", hash = 0xbd0eed23 }] + +[licenses.private] +# If true, ignores workspace crates that aren't published, or are only +# published to private registries. +# To see how to mark a crate as unpublished (to the official registry), +# visit https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish-field. +ignore = true + +# This section is considered when running `cargo deny check bans`. +# More documentation about the 'bans' section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/bans/cfg.html +[bans] +# Lint level for when multiple versions of the same crate are detected +multiple-versions = "deny" +skip = [] +skip-tree = [] + +# This section is considered when running `cargo deny check sources`. +# More documentation about the 'sources' section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/sources/cfg.html +[sources] +# Lint level for what to happen when a crate from a crate registry that is not +# in the allow list is encountered +unknown-registry = "deny" +# Lint level for what to happen when a crate from a git repository that is not +# in the allow list is encountered +unknown-git = "deny" +allow-git = [] + +[sources.allow-org] +# 1 or more github.com organizations to allow git sources for +github = ["MystenLabs"] diff --git a/licensesnip.config.jsonc b/licensesnip.config.jsonc new file mode 100644 index 0000000..454f298 --- /dev/null +++ b/licensesnip.config.jsonc @@ -0,0 +1,8 @@ +{ + "use_gitignore": true, + "file_types": { + "move": { + "before_line": "// " + } + } +} diff --git a/src/bip39.rs b/src/bip39.rs index 1d52371..1063f4a 100644 --- a/src/bip39.rs +++ b/src/bip39.rs @@ -1,13 +1,17 @@ -use crate::{ - shamir::{FieldArray, ShamirSecretSharing, ShamirShare}, - utils::{bits_to_bytes, bytes_to_bits}, -}; +// Copyright (c) Alberto Sonnino +// SPDX-License-Identifier: Apache-2.0 + +use std::{array::TryFromSliceError, fmt::Debug, fs::read_to_string, path::Path}; use eyre::{ensure, eyre, Result}; use fastcrypto::hash::{HashFunction, Sha256}; use gf256::gf256; use rand::{CryptoRng, RngCore}; -use std::{array::TryFromSliceError, fmt::Debug, fs::read_to_string, path::Path}; + +use crate::{ + shamir::{FieldArray, ShamirSecretSharing, ShamirShare}, + utils::{bits_to_bytes, bytes_to_bits}, +}; /// Parameters of the bip-39 specification (24 words variant). const DICTIONARY_INDICES_BITS: usize = 11; diff --git a/src/gf256.rs b/src/gf256.rs index 0913b37..e191ca9 100644 --- a/src/gf256.rs +++ b/src/gf256.rs @@ -1,3 +1,6 @@ +// Copyright (c) Alberto Sonnino +// SPDX-License-Identifier: Apache-2.0 + use gf256::gf256; use rand::{CryptoRng, Rng, RngCore}; @@ -48,7 +51,8 @@ impl ShamirSecretSharing for gf256 { } } -/// NOTE: Chaos test is not implemented for GF(256) because the field is too small to prevent collisions. +/// NOTE: No chaos test is implemented for the group GF(256) because the field is too small +/// to prevent collisions. #[cfg(test)] mod test { use gf256::gf256; diff --git a/src/main.rs b/src/main.rs index 9166cce..0ec3688 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,6 @@ +// Copyright (c) Alberto Sonnino +// SPDX-License-Identifier: Apache-2.0 + mod bip39; mod gf256; mod shamir; @@ -11,7 +14,9 @@ use color_eyre::owo_colors::OwoColorize; use eyre::{ensure, Result}; use prettytable::{ format::{FormatBuilder, LinePosition, LineSeparator}, - Cell, Row, Table, + Cell, + Row, + Table, }; use shamir::ShamirSecretSharing; diff --git a/src/shamir.rs b/src/shamir.rs index e51043a..a6df2c8 100644 --- a/src/shamir.rs +++ b/src/shamir.rs @@ -1,3 +1,6 @@ +// Copyright (c) Alberto Sonnino +// SPDX-License-Identifier: Apache-2.0 + use std::{ array, collections::HashMap, diff --git a/src/utils.rs b/src/utils.rs index 2b42d87..04557b7 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,3 +1,6 @@ +// Copyright (c) Alberto Sonnino +// SPDX-License-Identifier: Apache-2.0 + /// Convert an iterator of bytes into a vector of bits. pub fn bytes_to_bits(bytes: &[u8]) -> Vec { bytes diff --git a/tarpaulin.toml b/tarpaulin.toml new file mode 100644 index 0000000..50b9d05 --- /dev/null +++ b/tarpaulin.toml @@ -0,0 +1,12 @@ +[default] +workspace = true +skip-clean = true +run-types = ["Bins", "Doctests", "Examples", "Lib", "Tests"] +out = ["Html", "Xml"] +# Don't include test and benchmark code in the coverage result. +exclude-files = [ + "crates/**/benches/**/*", + "crates/**/tests/**/*", + "crates/**/test_utils/**/*", +] +args = ["--include-ignored"]