Skip to content

Commit

Permalink
configure pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
asonnino committed May 20, 2024
1 parent 02c73e4 commit 1c8b132
Show file tree
Hide file tree
Showing 11 changed files with 233 additions and 7 deletions.
32 changes: 32 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .licensesnip
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Copyright (c) Alberto Sonnino
SPDX-License-Identifier: Apache-2.0
81 changes: 81 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
72 changes: 72 additions & 0 deletions deny.toml
Original file line number Diff line number Diff line change
@@ -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"]
8 changes: 8 additions & 0 deletions licensesnip.config.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"use_gitignore": true,
"file_types": {
"move": {
"before_line": "// "
}
}
}
14 changes: 9 additions & 5 deletions src/bip39.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 5 additions & 1 deletion src/gf256.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Alberto Sonnino
// SPDX-License-Identifier: Apache-2.0

use gf256::gf256;
use rand::{CryptoRng, Rng, RngCore};

Expand Down Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Alberto Sonnino
// SPDX-License-Identifier: Apache-2.0

mod bip39;
mod gf256;
mod shamir;
Expand All @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions src/shamir.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Alberto Sonnino
// SPDX-License-Identifier: Apache-2.0

use std::{
array,
collections::HashMap,
Expand Down
3 changes: 3 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -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<bool> {
bytes
Expand Down
12 changes: 12 additions & 0 deletions tarpaulin.toml
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 1c8b132

Please sign in to comment.