diff --git a/.deepsource.toml b/.deepsource.toml new file mode 100644 index 0000000..d052a12 --- /dev/null +++ b/.deepsource.toml @@ -0,0 +1,8 @@ +version = 1 + +[[analyzers]] +name = "rust" +enabled = true + + [analyzers.meta] + msrv = "stable" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2b0b836 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,486 @@ +name: โฏ kyberlib release + +on: + pull_request: + branches: + - main + - 'feat/*' + push: + branches: + - main + - 'feat/*' + +jobs: + # This job checks a local package and all of its dependencies for + # errors. + check: + name: โฏ Check ๐Ÿ’ต + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - rust: stable + target: x86_64-unknown-linux-gnu + os: ubuntu-latest + + steps: + # Check out the repository code + - name: Checkout sources + id: checkout + uses: actions/checkout@v4 + + # Install the stable Rust toolchain + - name: Install stable toolchain + id: install-toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + # Cache dependencies to speed up subsequent builds + - name: Cache dependencies + id: cache-dependencies + uses: actions/cache@v3 + with: + path: ~/.cargo + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- + + # Run cargo check to check for errors + - uses: actions-rs/cargo@v1 + with: + command: check + args: --all-targets --workspace --all-features + + # This job runs the tests for the project. + test: + name: โฏ Test ๐Ÿงช + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - rust: stable + target: x86_64-unknown-linux-gnu + + steps: + # Check out the repository code + - name: Checkout sources + id: checkout + uses: actions/checkout@v4 + + # Install the stable Rust toolchain + - name: Install stable toolchain + id: install-toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + + # Cache dependencies to speed up subsequent builds + - name: Cache dependencies + id: cache-dependencies + uses: actions/cache@v3 + with: + path: ~/.cargo + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- + + # Run cargo hack to check for errors + - name: Install cargo-hack + uses: taiki-e/install-action@cargo-hack + id: install-cargo-hack + + - run: cargo test --all-targets --workspace --all-features + + # This job runs the tests for the project. + coverage: + name: โฏ Coverage ๐Ÿ“Š + if: github.ref == 'refs/heads/main' && github.event_name == 'push' + runs-on: ubuntu-latest + strategy: + matrix: + include: + - rust: stable + target: x86_64-unknown-linux-gnu + + steps: + # Check out the repository code + - name: Checkout sources + id: checkout + uses: actions/checkout@v4 + + # Install the stable Rust toolchain + - name: Install stable toolchain + id: install-toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + override: true + components: llvm-tools-preview + + # Cache dependencies to speed up subsequent builds + - name: Cache dependencies + id: cache-dependencies + uses: actions/cache@v3 + with: + path: ~/.cargo + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- + + # Install grcov + - name: Install grcov + run: | + mkdir -p "${HOME}/.local/bin" + curl -sL https://github.com/mozilla/grcov/releases/download/v0.8.18/grcov-x86_64-unknown-linux-gnu.tar.bz2 | tar jxf - -C "${HOME}/.local/bin" + echo "$HOME/.local/bin" >> $GITHUB_PATH + + # Use grcov to generate a coverage report + - name: Generate coverage report + id: coverage + uses: actions-rs/cargo@v1 + with: + command: xtask + args: coverage + + # Upload the coverage report to codecov + - name: Upload coverage report to codecov + id: codecov + uses: codecov/codecov-action@v3 + with: + files: coverage/*.lcov + + lints: + name: โฏ Lints ๐Ÿงน + runs-on: ubuntu-latest + strategy: + matrix: + include: + - rust: stable + target: x86_64-unknown-linux-gnu + steps: + # Check out the repository code + - name: Checkout sources + id: checkout + uses: actions/checkout@v4 + with: + submodules: true + + # Install the stable Rust toolchain + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + components: clippy + + # Cache dependencies to speed up subsequent builds + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: ~/.cargo + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- + + # Run cargo clippy to check for linting errors + - name: Run cargo clippy + if: github.ref == !github.event.check_run.conclusion + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --all-targets --all-features -- -D warnings + + # Run Cargo Format for the code style + - name: Run Cargo Format + id: run-check-format + if: github.ref == !github.event.check_run.conclusion + run: | + cargo check --all --all-features --workspace --verbose + + # Run cargo clippy to check for linting errors + - name: Run Clippy + id: run-check-clippy + if: github.ref == !github.event.check_run.conclusion + run: | + cargo clippy --all-targets --all-features --workspace -- -D warnings + + + build: + # This job builds the project for all the targets and generates a + # release artifact that contains the binaries for all the targets. + name: โฏ Build ๐Ÿ›  + if: github.ref == 'refs/heads/main' && github.event_name == 'push' + strategy: + fail-fast: false + matrix: + target: + # List of targets: https://doc.rust-lang.org/nightly/rustc/platform-support.html + + # FreeBSD targets ๐Ÿฌ + - x86_64-unknown-freebsd # 64-bit FreeBSD on x86-64 โœ… Tested + + # Linux targets ๐Ÿง + - aarch64-unknown-linux-gnu # 64-bit Linux systems on ARM architecture โœ… Tested + - aarch64-unknown-linux-musl # 64-bit Linux systems on ARM architecture โœ… Tested + - arm-unknown-linux-gnueabi # ARMv6 Linux (kernel 3.2, glibc 2.17) โœ… Tested + - armv7-unknown-linux-gnueabihf # ARMv7 Linux, hardfloat (kernel 3.2, glibc 2.17) โœ… Tested + - i686-unknown-linux-gnu # 32-bit Linux (kernel 3.2+, glibc 2.17+) โœ… Tested + - i686-unknown-linux-musl # 32-bit Linux (kernel 3.2+, musl libc) โœ… Tested + - x86_64-unknown-linux-gnu # 64-bit Linux (kernel 2.6.32+, glibc 2.11+) โœ… Tested + - x86_64-unknown-linux-musl # 64-bit Linux (kernel 2.6.32+, musl libc) โœ… Tested + + # macOS targets ๐ŸŽ + - aarch64-apple-darwin # 64-bit macOS on Apple Silicon โœ… Tested + - x86_64-apple-darwin # 64-bit macOS (10.7 Lion or later) โœ… Tested + + # Illumos targets ๐ŸŒž + - x86_64-unknown-illumos # 64-bit Illumos on x86-64 โœ… Tested + + include: + # FreeBSD targets ๐Ÿฌ + - target: x86_64-unknown-freebsd + os: ubuntu-latest + cross: true + + # Linux targets ๐Ÿง + - target: aarch64-unknown-linux-gnu + os: ubuntu-latest + cross: true + - target: aarch64-unknown-linux-musl + os: ubuntu-latest + cross: true + - target: arm-unknown-linux-gnueabi + os: ubuntu-latest + cross: true + - target: armv7-unknown-linux-gnueabihf + os: ubuntu-latest + cross: true + - target: i686-unknown-linux-gnu + os: ubuntu-latest + cross: true + - target: i686-unknown-linux-musl + os: ubuntu-latest + cross: true + - target: x86_64-unknown-linux-gnu + os: ubuntu-latest + cross: true + - target: x86_64-unknown-linux-musl + os: ubuntu-latest + cross: true + + # Illumos targets ๐ŸŒž + - target: x86_64-unknown-illumos + os: ubuntu-latest + cross: true + + # macOS targets ๐ŸŽ + - target: aarch64-apple-darwin + os: macos-latest + cross: true + - target: x86_64-apple-darwin + os: macos-latest + cross: true + + runs-on: ${{ matrix.os }} + + steps: + # Check out the repository code + - name: Checkout sources + id: checkout + uses: actions/checkout@v4 + + # Install the stable Rust toolchain + - name: Install stable toolchain + id: install-toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + # Cache dependencies to speed up subsequent builds + - name: Cache dependencies + id: cache-dependencies + uses: actions/cache@v3 + with: + path: ~/.cargo + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- + + # Install the targets for the cross compilation toolchain + - name: Install target + id: install-target + run: rustup target add ${{ matrix.target }} + + # Update the version number based on the Cargo.toml file + - name: Update version number + id: update-version + run: | + NEW_VERSION=$(grep version Cargo.toml | sed -n 2p | cut -d '"' -f 2) + echo "VERSION=$NEW_VERSION" >> $GITHUB_ENV + shell: /bin/bash -e {0} + + # Install the cross compilation toolchain + - name: Install Cross + id: install-cross + run: | + # Install cross + cargo install cross + # Clean the build artifacts + cargo clean --verbose + shell: /bin/bash -e {0} + + # Build the targets + - name: Build targets + id: build-targets + uses: actions-rs/cargo@v1 + with: + use-cross: true + command: build + args: --verbose --workspace --release --target ${{ matrix.target }} + + # Package the binary for each target + - name: Package the binary + id: package-binary + run: | + mkdir -p target/package + tar czf target/package/${{ matrix.target }}.tar.gz -C target/${{ matrix.target }}/release . + echo "${{ matrix.target }}.tar.gz=target/package/${{ matrix.target }}.tar.gz" >> $GITHUB_ENV + + # Upload the binary for each target + - name: Upload the binary + id: upload-binary + uses: actions/upload-artifact@v2 + with: + name: ${{ matrix.target }}.tar.gz + path: ${{ env[format('{0}.tar.gz', matrix.target)] }} + + # Release the binary to GitHub Releases + release: + name: โฏ Release ๐Ÿš€ + if: github.ref == 'refs/heads/main' && github.event_name == 'push' + needs: build + runs-on: ubuntu-latest + steps: + # Check out the repository code + - name: Checkout sources + uses: actions/checkout@v4 + + # Install the stable Rust toolchain + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + # Update the version number based on the Cargo.toml file + - name: Update version number + run: | + NEW_VERSION=$(grep version Cargo.toml | sed -n 2p | cut -d '"' -f 2) + echo "VERSION=$NEW_VERSION" >> $GITHUB_ENV + shell: /bin/bash -e {0} + + # Cache dependencies to speed up subsequent builds + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: ~/.cargo + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- + + # Download the artifacts from the build job + - name: Download artifacts + run: | + for target in x86_64-unknown-freebsd aarch64-unknown-linux-gnu aarch64-unknown-linux-musl arm-unknown-linux-gnueabi armv7-unknown-linux-gnueabihf i686-unknown-linux-gnu i686-unknown-linux-musl x86_64-unknown-linux-gnu x86_64-unknown-linux-musl aarch64-apple-darwin x86_64-apple-darwin x86_64-unknown-illumos; do + echo "Downloading $target artifact" + name="${target}.tar.gz" + echo "Artifact name: $name" + mkdir -p target/package + curl -sSL -H "Authorization: token ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.v3+json" -L "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/actions/runs/${RUN_ID}/artifacts/$kyberlib" -o "target/package/$kyberlib" + done + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RUN_ID: ${{ github.event.workflow_run.id }} + + # Generate the changelog based on git log and template file + - name: Generate Changelog + run: | + # Append version information to CHANGELOG.md + echo "## Release v${{ env.VERSION }} - $(date +'%Y-%m-%d')" >> ${{ github.workspace }}/CHANGELOG.md + # Copy content of template file to CHANGELOG.md + cat TEMPLATE.md >> ${{ github.workspace }}/CHANGELOG.md + # Append git log to CHANGELOG.md + echo "$(git log --pretty=format:'%s' --reverse $(git describe --tags --abbrev=0)..HEAD)" >> ${{ github.workspace }}/CHANGELOG.md + # Append empty line to CHANGELOG.md + echo "" >> ${{ github.workspace }}/CHANGELOG.md + + # Append the artifact links to the changelog + - name: Append Artifact Links + run: | + echo "" >> ${{ github.workspace }}/CHANGELOG.md + echo "## Artifacts ๐ŸŽ" >> ${{ github.workspace }}/CHANGELOG.md + for filename in target/package/*.tar.gz; do + link="$(basename $filename)" + echo "* [$link](${{ github.server_url }}/${{ github.repository }}/releases/download/v${{ env.VERSION }}/$link)" >> ${{ github.workspace }}/CHANGELOG.md + done + + # Create the release on GitHub Releases + - name: Create Release + id: create-release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: v${{ env.VERSION }} + release_name: kyberlib ๐Ÿฆ€ v${{ env.VERSION }} + body_path: ${{ github.workspace }}/CHANGELOG.md + draft: true + prerelease: false + + # Publish the release to Crates.io automatically + crate: + name: โฏ Crate.io ๐Ÿฆ€ + if: github.ref == 'refs/heads/main' && github.event_name == 'push' + needs: release + runs-on: ubuntu-latest + + steps: + # Check out the repository code + - name: Checkout + uses: actions/checkout@v4 + + # Install the stable Rust toolchain + - name: Install stable toolchain + id: install-toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + # Cache dependencies to speed up subsequent builds + - name: Cache dependencies + id: cache-dependencies + uses: actions/cache@v2 + with: + path: /home/runner/.cargo/registry/index/ + key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo-index- + + # Update the version number based on the Cargo.toml file + - name: Update version number + id: update-version + run: | + NEW_VERSION=$(grep version Cargo.toml | sed -n 2p | cut -d '"' -f 2) + echo "VERSION=$NEW_VERSION" >> $GITHUB_ENV + shell: /bin/bash -e {0} + + # Publish the Rust library to Crate.io + - name: Publish Library to Crate.io + id: publish-library + uses: actions-rs/cargo@v1 + env: + CARGO_API_TOKEN: ${{ secrets.CARGO_API_TOKEN }} + with: + use-cross: true + command: publish + args: --dry-run --verbose --token "${CARGO_API_TOKEN}" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7b5a0e0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +*.DS_Store +*.profraw +/.vscode/ +/output/ +/public/ +/target/ +build +Icon? +src/.DS_Store +tarpaulin-report.html diff --git a/AUTHORS.md b/AUTHORS.md new file mode 100644 index 0000000..0e2c8a5 --- /dev/null +++ b/AUTHORS.md @@ -0,0 +1,3 @@ +# Authors + +* [The kyberlib contributors](mailto:contact@kyberlib.com) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..344c59c --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,81 @@ +# Contributing to `kyberlib` + +Welcome! We're thrilled that you're interested in contributing to the +`kyberlib` library. Whether you're looking to evangelize, submit feedback, +or contribute code, we appreciate your involvement in making `kyberlib` a +better tool for everyone. Here's how you can get started. + +## Evangelize + +One of the simplest ways to help us out is by spreading the word about +kyberlib. We believe that a bigger, more involved community makes for a +better framework, and that better frameworks make the world a better +place. If you know people who might benefit from using kyberlib, please +let them know! + +## How to Contribute + +If you're interested in making a more direct contribution, there are +several ways you can help us improve kyberlib. Here are some guidelines +for submitting feedback, bug reports, and code contributions. + +### Feedback + +Your feedback is incredibly valuable to us, and we're always looking for +ways to make kyberlib better. If you have ideas, suggestions, or questions +about kyberlib, we'd love to hear them. Here's how you can provide +feedback: + +- Click [here][2] to submit a new feedback. +- Use a descriptive title that clearly summarizes your feedback. +- Provide a detailed description of the issue or suggestion. +- Be patient while we review and respond to your feedback. + +### Bug Reports + +If you encounter a bug while using kyberlib, please let us know so we can +fix it. Here's how you can submit a bug report: + +- Click [here][2] to submit a new issue. +- Use a descriptive title that clearly summarizes the bug. +- Provide a detailed description of the issue, including steps to + reproduce it. +- Be patient while we review and respond to your bug report. + +### Code Contributions + +If you're interested in contributing code to kyberlib, we're excited to +have your help! Here's what you need to know: + +#### Feature Requests + +If you have an idea for a new feature or improvement, we'd love to hear +it. Here's how you can contribute code for a new feature to kyberlib: + +- Fork the repo. +- Clone the kyberlib[1] repo by running: + `git clone https://github.com/sebastienrousseau/kyberlib` +- Edit files in the `src/` folder. The `src/` folder contains the source + code for kyberlib. +- Submit a pull request, and we'll review and merge your changes if they + fit with our vision for kyberlib. + +#### Submitting Code + +If you've identified a bug or have a specific code improvement in mind, +we welcome your pull requests. Here's how to submit your code changes: + +- Fork the repo. +- Clone the kyberlib repo by running: + `git clone https://github.com/sebastienrousseau/kyberlib` +- Edit files in the `src/` folder. The `src/` folder contains the source + code for kyberlib. +- Submit a pull request, and we'll review and merge your changes if they + fit with our vision for kyberlib. + +We hope that this guide has been helpful in explaining how you can +contribute to kyberlib. Thank you for your interest and involvement in our +project! + +[1]: https://github.com/sebastienrousseau/kyberlib +[2]: https://github.com/sebastienrousseau/kyberlib/issues/newHTTP/2 416 diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..529e367 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,869 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + +[[package]] +name = "anes" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" + +[[package]] +name = "anstyle" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" + +[[package]] +name = "anyhow" +version = "1.0.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + +[[package]] +name = "bumpalo" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" + +[[package]] +name = "cast" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "ciborium" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "effd91f6c78e5a4ace8a5d3c0b6bfaec9e2baaef55f3efc00e45fb2e477ee926" +dependencies = [ + "ciborium-io", + "ciborium-ll", + "serde", +] + +[[package]] +name = "ciborium-io" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdf919175532b369853f5d5e20b26b43112613fd6fe7aee757e35f7a44642656" + +[[package]] +name = "ciborium-ll" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "defaa24ecc093c77630e6c15e17c51f5e187bf35ee514f4e2d67baaa96dae22b" +dependencies = [ + "ciborium-io", + "half", +] + +[[package]] +name = "clap" +version = "4.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2275f18819641850fa26c89acc84d465c1bf91ce57bc2748b28c420473352f64" +dependencies = [ + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07cdf1b148b25c1e1f7a42225e30a0d99a615cd4637eae7365548dd4529b95bc" +dependencies = [ + "anstyle", + "clap_lex", +] + +[[package]] +name = "clap_lex" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" + +[[package]] +name = "criterion" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" +dependencies = [ + "anes", + "cast", + "ciborium", + "clap", + "criterion-plot", + "is-terminal", + "itertools", + "num-traits", + "once_cell", + "oorandom", + "plotters", + "rayon", + "regex", + "serde", + "serde_derive", + "serde_json", + "tinytemplate", + "walkdir", +] + +[[package]] +name = "criterion-plot" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" +dependencies = [ + "cast", + "itertools", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "deranged" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "dtt" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e274740bf3a29185381f8d9e881737a336f01717ed8a7b8514226a536794dd16" +dependencies = [ + "regex", + "serde", + "time", +] + +[[package]] +name = "either" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f258a7194e7f7c2a7837a8913aeab7fd8c383457034fa20ce4dd3dcb813e8eb8" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "getrandom" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "half" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" + +[[package]] +name = "hashbrown" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" + +[[package]] +name = "hermit-abi" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" + +[[package]] +name = "indexmap" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "is-terminal" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +dependencies = [ + "hermit-abi", + "rustix", + "windows-sys", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" + +[[package]] +name = "js-sys" +version = "0.3.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "kyberlib" +version = "0.0.1" +dependencies = [ + "anyhow", + "criterion", + "dtt", + "serde", + "serde_json", + "serde_yaml", + "toml", + "vrd", +] + +[[package]] +name = "libc" +version = "0.2.150" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" + +[[package]] +name = "linux-raw-sys" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "memchr" +version = "2.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" + +[[package]] +name = "memoffset" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num-traits" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" + +[[package]] +name = "oorandom" +version = "11.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" + +[[package]] +name = "plotters" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2c224ba00d7cadd4d5c660deaf2098e5e80e07846537c51f9cfa4be50c1fd45" +dependencies = [ + "num-traits", + "plotters-backend", + "plotters-svg", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "plotters-backend" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e76628b4d3a7581389a35d5b6e2139607ad7c75b17aed325f210aa91f4a9609" + +[[package]] +name = "plotters-svg" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38f6d39893cca0701371e3c27294f09797214b86f1fb951b89ade8ec04e2abab" +dependencies = [ + "plotters-backend", +] + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "proc-macro2" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rayon" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + +[[package]] +name = "regex" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] +name = "rustix" +version = "0.38.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ad981d6c340a49cdc40a1028d9c6084ec7e9fa33fcb839cab656a267071e234" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "ryu" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serde" +version = "1.0.192" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.192" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_spanned" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12022b835073e5b11e90a14f86838ceb1c8fb0325b72416845c487ac0fa95e80" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_yaml" +version = "0.9.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cc7a1570e38322cfe4154732e5110f887ea57e22b76f4bfd32b5bdd3368666c" +dependencies = [ + "indexmap", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + +[[package]] +name = "syn" +version = "2.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "time" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" +dependencies = [ + "deranged", + "powerfmt", + "serde", + "time-core", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "tinytemplate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" +dependencies = [ + "serde", + "serde_json", +] + +[[package]] +name = "toml" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1a195ec8c9da26928f773888e0742ca3ca1040c6cd859c919c9f59c1954ab35" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34d383cd00a163b4a5b85053df514d45bc330f6de7737edfe0a93311d1eaa03" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unsafe-libyaml" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28467d3e1d3c6586d8f25fa243f544f5800fec42d97032474e17222c2b75cfa" + +[[package]] +name = "vrd" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a81b8b5b404f3d7afa1b8142a6bc980c20cd68556c634c3db517871aa0402521" +dependencies = [ + "rand", +] + +[[package]] +name = "walkdir" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b" + +[[package]] +name = "web-sys" +version = "0.3.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5db499c5f66323272151db0e666cd34f78617522fb0c1604d31a27c50c206a85" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "winnow" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "829846f3e3db426d4cee4510841b71a8e58aa2a76b1132579487ae430ccd9c7b" +dependencies = [ + "memchr", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..a71cf30 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,108 @@ +[package] +authors = ["The kyberlib contributors "] +build = "build.rs" +categories = [ + "algorithms", + "cryptography", + "encoding" +] +description = """ + A Robust Rust Library for CRYSTALS-Kyber Post-Quantum Cryptography. +""" +documentation = "https://docs.rs/kyberlib" +edition = "2021" +exclude = [ + "/.git/*", + "/.github/*", + "/.gitignore", + "/.vscode/*" + ] +homepage = "https://kyberlib.com" +keywords = [ + "post-quantum", + "kyber", + "kem", + "cryptography", + "security" +] +license = "MIT OR Apache-2.0" +name = "kyberlib" +readme = "README.md" +repository = "https://github.com/sebastienrousseau/kyberlib" +rust-version = "1.71.1" +version = "0.0.1" +include = [ + "/CONTRIBUTING.md", + "/LICENSE-APACHE", + "/LICENSE-MIT", + "/build.rs", + "/Cargo.toml", + "/README.md", + "/src/**", +] + +# [[bench]] +# name = "benchmark" +# harness = false +# path = "benches/criterion.rs" + +# [profile.bench] +# debug = true + +[dependencies] +anyhow = "1.0.75" +dtt = "0.0.4" +serde = { version = "1.0.192", features = ["derive"] } +serde_json = "1.0.108" +serde_yaml = "0.9.27" +toml = "0.8.8" +vrd = "0.0.4" + +[dev-dependencies] +criterion = "0.5.1" + +[lib] +crate-type = ["lib"] +name = "kyberlib" +path = "src/lib.rs" + +[features] +default = [] + +[package.metadata.docs.rs] +all-features = true + +[profile.dev] +codegen-units = 256 +debug = true +debug-assertions = true +incremental = true +lto = false +opt-level = 0 +overflow-checks = true +panic = 'unwind' +rpath = false +strip = false + +[profile.release] +codegen-units = 1 +debug = false +debug-assertions = false +incremental = false +lto = true +opt-level = "s" +overflow-checks = false +panic = "abort" +rpath = false +strip = "symbols" + +[profile.test] +codegen-units = 256 +debug = true +debug-assertions = true +incremental = true +lto = false +opt-level = 0 +overflow-checks = true +rpath = false +strip = false diff --git a/README.md b/README.md new file mode 100644 index 0000000..46f0772 --- /dev/null +++ b/README.md @@ -0,0 +1,197 @@ + + + + + + +# kyberlib + +A Robust Rust Library for CRYSTALS-Kyber Post-Quantum Cryptography + + +
+ + +[![Made With Rust][made-with-rust-badge]][5] +[![Crates.io][crates-badge]][7] +[![Lib.rs][libs-badge]][9] +[![Docs.rs][docs-badge]][8] +[![License][license-badge]][2] + +โ€ข [Website][0] +โ€ข [Documentation][8] +โ€ข [Report Bug][3] +โ€ข [Request Feature][3] +โ€ข [Contributing Guidelines][4] + + +
+ + +![divider][divider] + +## Overview ๐Ÿ“– + +A Robust Rust Library for CRYSTALS-Kyber Post-Quantum Cryptography + +## Features โœจ + +- Feature 1 +- Feature 2 +- Feature 3 + +## Getting Started ๐Ÿš€ + +It takes just a few minutes to get up and running with `kyberlib`. + +### Installation + +To install `kyberlib`, you need to have the Rust toolchain installed on +your machine. You can install the Rust toolchain by following the +instructions on the [Rust website][13]. + +Once you have the Rust toolchain installed, you can install `kyberlib` +using the following command: + +```shell +cargo install kyberlib +``` + +You can then run the help command to see the available options: + +```shell +kyberlib --help +``` + +### Requirements + +The minimum supported Rust toolchain version is currently Rust +**1.71.1** or later (stable). + +### Platform support + +`kyberlib` is supported and tested on the following platforms: + +### Tier 1 platforms ๐Ÿ† + +| | Operating System | Target | Description | +| --- | --- | --- | --- | +| โœ… | Linux | aarch64-unknown-linux-gnu | 64-bit Linux systems on ARM architecture | +| โœ… | Linux | i686-unknown-linux-gnu | 32-bit Linux (kernel 3.2+, glibc 2.17+) | +| โœ… | Linux | x86_64-unknown-linux-gnu | 64-bit Linux (kernel 2.6.32+, glibc 2.11+) | +| โœ… | macOS | x86_64-apple-darwin | 64-bit macOS (10.7 Lion or later) | +| โœ… | Windows | i686-pc-windows-gnu | 32-bit Windows (7 or later) | +| โœ… | Windows | i686-pc-windows-msvc | 32-bit Windows (7 or later) | +| โœ… | Windows | x86_64-pc-windows-gnu | 64-bit Windows (7 or later) | +| โœ… | Windows | x86_64-pc-windows-msvc | 64-bit Windows (7 or later) | + +### Tier 2 platforms ๐Ÿฅˆ + +| | Operating System | Target | Description | +| --- | --- | --- | --- | +| โœ… | Linux | aarch64-unknown-linux-musl | 64-bit Linux systems on ARM architecture | +| โœ… | Linux | arm-unknown-linux-gnueabi | ARMv6 Linux (kernel 3.2, glibc 2.17) | +| โœ… | Linux | arm-unknown-linux-gnueabihf | ARMv7 Linux, hardfloat (kernel 3.2, glibc 2.17) | +| โœ… | Linux | armv7-unknown-linux-gnueabihf | ARMv7 Linux, hardfloat (kernel 3.2, glibc 2.17) | +| โœ… | Linux | mips-unknown-linux-gnu | MIPS Linux (kernel 2.6.32+, glibc 2.11+) | +| โœ… | Linux | mips64-unknown-linux-gnuabi64 | MIPS64 Linux (kernel 2.6.32+, glibc 2.11+) | +| โœ… | Linux | mips64el-unknown-linux-gnuabi64 | MIPS64 Linux (kernel 2.6.32+, glibc 2.11+) | +| โœ… | Linux | mipsel-unknown-linux-gnu | MIPS Linux (kernel 2.6.32+, glibc 2.11+) | +| โœ… | macOS | aarch64-apple-darwin | 64-bit macOS (10.7 Lion or later) | +| โœ… | Windows | aarch64-pc-windows-msvc | 64-bit Windows (7 or later) | + +The [GitHub Actions][10] shows the platforms in which the `kyberlib` +library tests are run. + +### Documentation + +**Info:** Please check out our [website][0] for more information. You can find our documentation on [docs.rs][8], [lib.rs][9] and +[crates.io][7]. + +## Usage ๐Ÿ“– + +To use the `kyberlib` library in your project, add the following to your +`Cargo.toml` file: + +```toml +[dependencies] +kyberlib = "0.0.1" +``` + +Add the following to your `main.rs` file: + +```rust +extern crate kyberlib; +use kyberlib::*; +``` + +then you can use the functions in your application code. + +### Examples + +To get started with `kyberlib`, you can use the examples provided in the +`examples` directory of the project. + +To run the examples, clone the repository and run the following command +in your terminal from the project root directory. + +```shell +cargo run --example kyberlib +``` + +## Semantic Versioning Policy ๐Ÿšฅ + +For transparency into our release cycle and in striving to maintain +backward compatibility, `kyberlib` follows [semantic versioning][6]. + +## License ๐Ÿ“ + +The project is licensed under the terms of MIT. + +## Contribution ๐Ÿค + +We welcome all people who want to contribute. Please see the +[contributing instructions][4] for more information. + +Contributions in any form (issues, pull requests, etc.) to this project +must adhere to the [Rust's Code of Conduct][11]. + +Unless you explicitly state otherwise, any contribution intentionally +submitted for inclusion in the work by you, as defined in the +Apache-2.0 license, shall be dual licensed as above, without any +additional terms or conditions. + +## Acknowledgements ๐Ÿ’™ + +A big thank you to all the awesome contributors of [kyberlib][5] for their +help and support. + +A special thank you goes to the [Rust Reddit][12] community for +providing a lot of useful suggestions on how to improve this project. + +[0]: https://kyberlib.com/ +[2]: http://opensource.org/licenses/MIT +[3]: https://github.com/sebastienrousseau/kyberlib/kyberlib/issues +[4]: https://github.com/sebastienrousseau/kyberlib/kyberlib/blob/main/CONTRIBUTING.md +[5]: https://github.com/sebastienrousseau/kyberlib/kyberlib/graphs/contributors +[6]: http://semver.org/ +[7]: https://crates.io/crates/kyberlib +[8]: https://docs.rs/kyberlib +[9]: https://lib.rs/crates/kyberlib +[10]: https://github.com/sebastienrousseau/kyberlib/kyberlib/actions +[11]: https://www.rust-lang.org/policies/code-of-conduct +[12]: https://www.reddit.com/r/rust/ +[13]: https://www.rust-lang.org/learn/get-started + +[crates-badge]: https://img.shields.io/crates/v/kyberlib.svg?style=for-the-badge 'Crates.io badge' +[divider]: https://kura.pro/common/images/elements/divider.svg "divider" +[docs-badge]: https://img.shields.io/docsrs/kyberlib.svg?style=for-the-badge 'Docs.rs badge' +[libs-badge]: https://img.shields.io/badge/lib.rs-v0.0.1-orange.svg?style=for-the-badge 'Lib.rs badge' +[license-badge]: https://img.shields.io/crates/l/kyberlib.svg?style=for-the-badge 'License badge' +[made-with-rust-badge]: https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust 'Made With Rust badge' diff --git a/TEMPLATE.md b/TEMPLATE.md new file mode 100644 index 0000000..5ea62b9 --- /dev/null +++ b/TEMPLATE.md @@ -0,0 +1,68 @@ + + + + + + +# kyberlib + +A Robust Rust Library for CRYSTALS-Kyber Post-Quantum Cryptography + + +
+ + +[![Made With Rust][made-with-rust-badge]][5] +[![Crates.io][crates-badge]][7] +[![Lib.rs][libs-badge]][9] +[![Docs.rs][docs-badge]][8] +[![License][license-badge]][2] + +โ€ข [Website][0] +โ€ข [Documentation][8] +โ€ข [Report Bug][3] +โ€ข [Request Feature][3] +โ€ข [Contributing Guidelines][4] + + +
+ + +![divider][divider] + +## Overview ๐Ÿ“– + +A Robust Rust Library for CRYSTALS-Kyber Post-Quantum Cryptography + +## Features โœจ + +- Feature 1 +- Feature 2 +- Feature 3 + +## Changelog ๐Ÿ“š + +- + +[0]: https://kyberlib.com/ +[2]: http://opensource.org/licenses/MIT +[3]: https://github.com/sebastienrousseau/kyberlib/kyberlib/issues +[4]: https://github.com/sebastienrousseau/kyberlib/kyberlib/blob/main/CONTRIBUTING.md +[5]: https://github.com/sebastienrousseau/kyberlib/kyberlib/graphs/contributors +[7]: https://crates.io/crates/kyberlib +[8]: https://docs.rs/kyberlib +[9]: https://lib.rs/crates/kyberlib + +[banner]: https://via.placeholder.com/1500x500.png/000000/FFFFFF?text=kyberlib "kyberlib's banner" +[crates-badge]: https://img.shields.io/crates/v/kyberlib.svg?style=for-the-badge 'Crates.io badge' +[divider]: https://via.placeholder.com/1024x1.png/d8dee4/FFFFFF?text=โˆ’ "kyberlib's divider" +[docs-badge]: https://img.shields.io/docsrs/kyberlib.svg?style=for-the-badge 'Docs.rs badge' +[libs-badge]: https://img.shields.io/badge/lib.rs-v0.0.1-orange.svg?style=for-the-badge 'Lib.rs badge' +[license-badge]: https://img.shields.io/crates/l/kyberlib.svg?style=for-the-badge 'License badge' +[made-with-rust-badge]: https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust 'Made With Rust badge' diff --git a/benches/criterion.rs b/benches/criterion.rs new file mode 100644 index 0000000..9d9fe06 --- /dev/null +++ b/benches/criterion.rs @@ -0,0 +1,50 @@ +// SPDX-FileCopyrightText: Copyright ยฉ 2023 kyberlib. All rights reserved. +// SPDX-License-Identifier: MIT + +extern crate criterion; + +use criterion::{criterion_group, criterion_main, Criterion}; +use kyberlib::{run, kyberlib_vec, kyberlib_map, kyberlib_join}; + +fn kyberlib_vec_benchmark(c: &mut Criterion) { + c.bench_function("kyberlib_vec_macro", |b| { + b.iter(|| { + kyberlib_vec![1, 2, 3, 4, 5] + }) + }); +} + +fn kyberlib_map_benchmark(c: &mut Criterion) { + c.bench_function("kyberlib_map_macro", |b| { + b.iter(|| { + kyberlib_map!["a" => 1, "b" => 2, "c" => 3, "d" => 4, "e" => 5] + }) + }); +} + +fn kyberlib_join_benchmark(c: &mut Criterion) { + c.bench_function("kyberlib_join_macro", |b| { + b.iter(|| { + kyberlib_join!["a", "b", "c", "d", "e"] + }) + }); +} + +fn kyberlib_benchmark(c: &mut Criterion) { + c.bench_function("kyberlib", |b| { + b.iter(|| { + for _ in 0..1000 { + run().unwrap(); + } + }) + }); +} + +criterion_group!( + kyberlib_macros_benchmark, + kyberlib_vec_benchmark, + kyberlib_map_benchmark, + kyberlib_join_benchmark, + kyberlib_benchmark +); +criterion_main!(kyberlib_macros_benchmark); diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..fd61ab1 --- /dev/null +++ b/build.rs @@ -0,0 +1,10 @@ +// SPDX-FileCopyrightText: Copyright ยฉ 2023 kyberlib. All rights reserved. +// SPDX-License-Identifier: MIT + +//! This is the main function for the build script. +//! +//! Currently, it only instructs Cargo to re-run this build script if `build.rs` is changed. +fn main() { + // Avoid unnecessary re-building. + println!("cargo:rerun-if-changed=build.rs"); +} diff --git a/deny.toml b/deny.toml new file mode 100644 index 0000000..2670118 --- /dev/null +++ b/deny.toml @@ -0,0 +1,71 @@ +[licenses] +# The lint level for crates which do not have a detectable license +unlicensed = "deny" + +# List of explicitly allowed licenses +# See https://spdx.org/licenses/ for list of possible licenses +# [possible values: any SPDX 3.7 short identifier (+ optional exception)]. +allow = [ + "Apache-2.0", + "MIT", + "CC0-1.0", + "ISC", + "0BSD", + "BSD-2-Clause", + "BSD-3-Clause", + "Unlicense", + "Unicode-DFS-2016", +] + +# List of banned licenses +[bans] +multiple-versions = "deny" + + +# The lint level for licenses considered copyleft +copyleft = "deny" + +# Blanket approval or denial for OSI-approved or FSF Free/Libre licenses +# * both - The license will only be approved if it is both OSI-approved *AND* FSF/Free +# * either - The license will be approved if it is either OSI-approved *OR* FSF/Free +# * osi-only - The license will be approved if is OSI-approved *AND NOT* FSF/Free +# * fsf-only - The license will be approved if is FSF/Free *AND NOT* OSI-approved +# * neither - The license will be denied if is FSF/Free *OR* OSI-approved +allow-osi-fsf-free = "either" + +# 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 + +# The graph highlighting used when creating dotgraphs for crates +# with multiple versions +# * lowest-version - The path to the lowest versioned duplicate is highlighted +# * simplest-path - The path to the version with the fewest edges is highlighted +# * all - Both lowest-version and simplest-path are used +highlight = "all" + +# List of crates that are allowed. Use with care! +allow = [] + +# List of crates to deny +deny = [ + # Each entry the name of a crate and a version range. If version is + # not specified, all versions will be matched. +] + +# Certain crates/versions that will be skipped when doing duplicate detection. +skip = [] + +# Similarly to `skip` allows you to skip certain crates during duplicate detection, +# unlike skip, it also includes the entire tree of transitive dependencies starting at +# the specified crate, up to a certain depth, which is by default infinite +skip-tree = [] + + +[advisories] +notice = "deny" +unmaintained = "deny" +unsound = "deny" +vulnerability = "deny" diff --git a/examples/example.rs b/examples/example.rs new file mode 100644 index 0000000..2a778e4 --- /dev/null +++ b/examples/example.rs @@ -0,0 +1,3 @@ +fn main() { + +} diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..9cad170 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,32 @@ +# SPDX-FileCopyrightText: Copyright ยฉ 2023 kyberlib. All rights reserved. +# SPDX-License-Identifier: MIT + +# See https://github.com/rust-lang/rustfmt/blob/master/Configurations.md +# for more configuration options + +comment_width = 72 # Maximum line width for comments +doc_comment_code_block_width = 72 # Maximum line width for code blocks in doc comments +edition = "2021" # Use a single edition only (Edition 2018 or Edition 2021) +empty_item_single_line = true # Put empty items on a single line +force_explicit_abi = true # Force explicit abi +format_code_in_doc_comments = true # Format code snippets in doc comments +format_macro_bodies = true # Format macro bodies +format_macro_matchers = true # Format macro matchers +group_imports = "StdExternalCrate" # Group imports by crate +hard_tabs = false # Use spaces instead of tabs +imports_granularity = "Module" # Group imports by module +imports_layout = "HorizontalVertical" # Layout imports horizontally and vertically +max_width = 72 # Maximum line width +merge_derives = true # Merge derives +newline_style = "Unix" # Prevent carriage returns from being added to the end of lines +normalize_comments = true # Normalize comments +normalize_doc_attributes = true # Normalize doc attributes +overflow_delimited_expr = true # Allow overflowing delimited expressions +remove_nested_parens = true # Remove nested parens +reorder_imports = true # Reorder imports +reorder_modules = true # Reorder modules +tab_spaces = 4 # Use 4 spaces for indentation +use_field_init_shorthand = true # Use field initialization shorthand when possible +use_small_heuristics = "Max" # Use max heuristics +use_try_shorthand = true # Use try shorthand when possible +wrap_comments = true # Wrap comments when line width exceeds max max_width diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..ac5b816 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,117 @@ +// SPDX-FileCopyrightText: Copyright ยฉ 2023 kyberlib. All rights reserved. +// SPDX-License-Identifier: MIT +//! +//! # `kyberlib` ๐Ÿฆ€ +//! +//! [![kyberlib](https://via.placeholder.com/1500x500.png/000000/FFFFFF?text=kyberlib)](https://kyberlib.com/ "kyberlib - A Robust Rust Library for CRYSTALS-Kyber Post-Quantum Cryptography") +//! +//! A Robust Rust Library for CRYSTALS-Kyber Post-Quantum Cryptography +//! +//! [![Crates.io](https://img.shields.io/crates/v/kyberlib.svg?style=for-the-badge&color=success&labelColor=27A006)](https://crates.io/crates/kyberlib "Crates.io") +//! [![Lib.rs](https://img.shields.io/badge/lib.rs-v0.0.1-success.svg?style=for-the-badge&color=8A48FF&labelColor=6F36E4)](https://lib.rs/crates/kyberlib "Lib.rs") +//! [![License](https://img.shields.io/crates/l/kyberlib.svg?style=for-the-badge&color=007EC6&labelColor=03589B)](MIT "MIT") +//! [![Rust](https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust)](https://www.rust-lang.org "Rust") +//! +//! ## Overview +//! +//! A Robust Rust Library for CRYSTALS-Kyber Post-Quantum Cryptography +//! +//! ## Features +//! +//! - ... +//! - ... +//! - ... +//! +//! ## Usage +//! +//! Add the following to your `Cargo.toml` file: +//! +//! ```toml +//! [dependencies] +//! kyberlib = "0.0.1" +//! serde = { version = "1.0", features = ["derive"] } +//! serde_json = "1.0" +//! ``` +//! +//! ## Examples +//! +//! Check out the examples folder for helpful snippets of code that +//! demonstrate how to use the `kyberlib` library. You can also check out +//! the [documentation](https://docs.rs/kyberlib) for more information on +//! how to use the library. +//! +//! ```rust +//! use kyberlib::kyberlib; +//! +//! ``` +//! +//! ## License +//! +//! The project is licensed under the terms of the MIT license. +//! +#![cfg_attr(feature = "bench", feature(test))] +#![deny(dead_code)] +#![deny(missing_debug_implementations)] +#![deny(missing_docs)] +#![forbid(unsafe_code)] +#![warn(unreachable_pub)] +#![doc( + html_favicon_url = "", + html_logo_url = "", + html_root_url = "https://docs.rs/kyberlib" +)] +#![crate_name = "kyberlib"] +#![crate_type = "lib"] + +/// The `loggers` module contains the loggers for the library. +pub mod loggers; + +/// The `macros` module contains functions for generating macros. +pub mod macros; + +use serde::{Deserialize, Serialize}; +use std::error::Error; + +#[non_exhaustive] +#[derive( + Clone, + Debug, + Deserialize, + Eq, + Hash, + Ord, + PartialEq, + PartialOrd, + Serialize, +)] + +#[allow(non_camel_case_types)] +/// kyberlib is a data structure that ... +pub struct kyberlib { + // Add any data fields needed here +} + +/// This is the main entry point for the kyberlib library. +pub fn run() -> Result<(), Box> { + // Add your code here + let name = "kyberlib"; + println!("Hello, {}!", { name }.to_uppercase()); + Ok(()) +} + + +impl kyberlib { + /// Creates a new instance of kyberlib + pub fn new() -> Self { + Self { + // Initialize any data fields here + } + } +} + +impl Default for kyberlib { + /// Creates a new instance of kyberlib with default values + fn default() -> Self { + Self::new() + } +} diff --git a/src/loggers.rs b/src/loggers.rs new file mode 100644 index 0000000..4d85fd7 --- /dev/null +++ b/src/loggers.rs @@ -0,0 +1,243 @@ +// Copyright ยฉ 2023 LibMake. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 OR MIT + +// Standard library imports for formatting and I/O operations. +use std::{ + fmt, + fs::OpenOptions, + io::{self, Write as IoWrite}, +}; + +/// Enum representing the different log formats that can be used. +/// +/// This enum allows the developer to specify the format in which log messages should be displayed. +/// +#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, PartialOrd)] +pub enum LogFormat { + /// The log format is set to the Common Log Format (CLF) + CLF, + /// The log format is set to the JSON format + JSON, + /// The log format is set to the Common Event Format (CEF) + CEF, + /// The log format is set to the Extended Log Format (ELF) + ELF, + /// The log format is set to the W3C Extended Log File Format + W3C, + /// The log format is set to the Graylog Extended Log Format (GELF) + GELF, +} + +/// Implements Display trait for `LogFormat` enum. +/// +/// This allows easy conversion of the log format enums to strings. +impl fmt::Display for LogFormat { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + writeln!(f, "{self:?}") + } +} + +/// An enumeration of the different levels that a log message can have. +/// Each variant of the enumeration represents a different level of +/// importance. +/// +/// # Arguments +/// +/// * `ALL` - The log level is set to all. +/// * `DEBUG` - The log level is set to debug. +/// * `DISABLED` - The log level is set to disabled. +/// * `ERROR` - The log level is set to error. +/// * `FATAL` - The log level is set to fatal. +/// * `INFO` - The log level is set to info. +/// * `NONE` - The log level is set to none. +/// * `TRACE` - The log level is set to trace. +/// * `VERBOSE` - The log level is set to verbose. +/// * `WARNING` - The log level is set to warning. +/// +#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, PartialOrd)] +pub enum LogLevel { + /// The log level is set to all. + ALL, + /// The log level is set to debug. + DEBUG, + /// The log level is set to disabled. + DISABLED, + /// The log level is set to error. + ERROR, + /// The log level is set to fatal. + FATAL, + /// The log level is set to info. + INFO, + /// The log level is set to none. + NONE, + /// The log level is set to trace. + TRACE, + /// The log level is set to verbose. + VERBOSE, + /// The log level is set to warning. + WARNING, +} +/// Display trait implementation for `LogLevel`. +/// +/// This converts the enum to a string representation. +impl fmt::Display for LogLevel { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{self:?}") + } +} + +/// Struct representing a log message. +/// +/// Contains all the elements that make up a complete log message. +#[derive(Debug, PartialEq, Eq, Hash, Clone)] +pub struct Log { + /// A string that holds a session ID. The session ID is a unique + /// identifier for the current session. A random GUID (Globally + /// Unique Identifier) is generated by default. + pub session_id: String, + /// A string that holds the timestamp in ISO 8601 format. + pub time: String, + /// A string that holds the level (INFO, WARN, ERROR, etc.). + pub level: LogLevel, + /// A string that holds the component name. + pub component: String, + /// A string that holds the description of the log message. + pub description: String, + /// A string that holds the log format. + pub format: LogFormat, +} + +impl Log { + /// Logs a message to the console using a pre-allocated buffer to + /// reduce memory allocation and flush the output buffer to ensure + /// that the message is written immediately. + /// + /// # Errors + /// + /// This function will panic if an error occurs when writing to the + /// pre-allocated buffer or flushing the output buffer. + pub fn log(&self) -> io::Result<()> { + // Open the file in append mode. If the file does not exist, create it. + let mut file = OpenOptions::new() + .write(true) + .truncate(true) + .open("kyberlib.log")?; + match self.format { + LogFormat::CLF => { + writeln!( + file, + "SessionID={}\tTimestamp={}\tDescription={}\tLevel={}\tComponent={}\tFormat={}", + self.session_id, + self.time, + self.description, + self.level, + self.component, + self.format + ) + } + LogFormat::JSON => { + writeln!( + file, + r#"{{"session_id": "{}", "timestamp": "{}", "description": "{}", "level": "{}", "component": "{}", "format": "{}"}}"#, + self.session_id, + self.time, + self.description, + self.level, + self.component, + self.format + ) + } + LogFormat::CEF => { + writeln!( + file, + r#"[CEF] + + 1 + kyberlib + Application + {} + Log + {} + {} + {} + localhost + localhost + - + - + - + - + - + - + + "#, + self.time, + self.level, + self.description, + self.session_id + ) + } + _ => Err(io::Error::new( + io::ErrorKind::InvalidInput, + "Unsupported log format", + )), + }?; + file.flush()?; + Ok(()) + } + + /// Creates a new `Log` instance. + /// + /// Initializes a new `Log` struct with the provided details. + /// + /// # Returns + /// + /// Returns a new instance of the `Log` struct. + pub fn new( + session_id: &str, + time: &str, + level: LogLevel, + component: &str, + description: &str, + format: LogFormat, + ) -> Self { + Self { + session_id: session_id.to_string(), + time: time.to_string(), + level, + component: component.to_string(), + description: description.to_string(), + format, + } + } +} + +/// Provides default values for `Log`. +/// +/// This implementation provides a quick way to generate a `Log` instance with default values. +impl Default for Log { + fn default() -> Self { + Self { + session_id: String::default(), + time: String::default(), + level: LogLevel::INFO, // Default log level + component: String::default(), + description: String::default(), + format: LogFormat::CLF, // Default log format + } + } +} +#[cfg(test)] +/// Tests for the `log_info!` macro. +mod tests { + use crate::kyberlib_log_info; + + #[test] + fn test_log_info() { + kyberlib_log_info!( + LogLevel::INFO, + "component", + "description", + LogFormat::CLF + ); + } +} diff --git a/src/macros.rs b/src/macros.rs new file mode 100644 index 0000000..a264f7e --- /dev/null +++ b/src/macros.rs @@ -0,0 +1,222 @@ +//! # Macros for the `kyberlib` crate. +//! +//! This crate provides the following macros: +//! +//! - `kyberlib`: The main macro for the `kyberlib` crate. +//! - `kyberlib_print`: Prints the arguments to the console. +//! - `kyberlib_vec`: Creates a new vector of the given elements. +//! - `kyberlib_map`: Creates a new map of the given key-value pairs. +//! - `kyberlib_assert`: Checks if the given expression is true. +//! - `kyberlib_min`: Returns the minimum of the given values. +//! - `kyberlib_max`: Returns the maximum of the given values. +//! - `kyberlib_split`: Splits a string into a vector of words. +//! - `kyberlib_join`: Joins a vector of strings into a single string. +//! - `kyberlib_print_vec`: Prints a vector of elements to the console. +//! - `kyberlib_log_info`: Logs information with the specified level, component, and format. +//! - `kyberlib_execute_and_log`: Executes a shell command and logs the start, completion, and any errors. +//! + +/// This macro takes any number of arguments and parses them into a +/// Rust value. +#[macro_export] +macro_rules! kyberlib { + ($($tt:tt)*) => { + // Parse the arguments into a Rust value. + $crate::parse!($($tt)*) + }; +} + +/// This macro prints the arguments to the console. +#[macro_export] +macro_rules! kyberlib_print { + ($($arg:tt)*) => { + println!("{}", format_args!("{}", $($arg)*)); + }; +} + +/// This macro creates a new vector of the given elements. +#[macro_export] +macro_rules! kyberlib_vec { + ($($elem:expr),*) => {{ + let mut v = Vec::new(); + $(v.push($elem);)* + v + }}; +} + +/// This macro creates a new map of the given key-value pairs. +#[macro_export] +macro_rules! kyberlib_map { + ($($key:expr => $value:expr),*) => {{ + use std::collections::HashMap; + let mut m = HashMap::new(); + $(m.insert($key, $value);)* + m + }}; +} + +/// This macro checks if the given expression is true. +#[macro_export] +macro_rules! kyberlib_assert { + ($($arg:tt)*) => { + if !$($arg)* { + panic!("Assertion failed!"); + } + }; +} + +/// This macro returns the minimum of the given values. +#[macro_export] +macro_rules! kyberlib_min { + ($($x:expr),*) => {{ + let mut min = $($x)*; + $(if min > $x { min = $x; })* + min + }}; +} + +/// This macro returns the maximum of the given values. +#[macro_export] +macro_rules! kyberlib_max { + ($($x:expr),*) => {{ + let mut max = $($x)*; + $(if max < $x { max = $x; })* + max + }}; +} + +/// This macro takes a string and splits it into a vector of words. +#[macro_export] +macro_rules! kyberlib_split { + ($s:expr) => {{ + let mut v = Vec::new(); + for w in $s.split_whitespace() { + v.push(w.to_string()); + } + v + }}; +} + +/// This macro takes a vector of strings and joins them together into a +/// single string. +#[macro_export] +macro_rules! kyberlib_join { + ($($s:expr),*) => {{ + let mut s = String::new(); + $( + s += &$s; + )* + s + }}; +} + +/// This macro takes a vector of elements and prints them to the +/// console. +#[macro_export] +macro_rules! kyberlib_print_vec { + ($($v:expr),*) => {{ + for v in $($v),* { + println!("{}", v); + } + }}; +} + +// Macro for logging information with various log levels and formats. +#[macro_export] +/// Logs information with the specified level, component, and format. +/// +/// # Parameters +/// +/// * `$level` - The log level for the message. +/// * `$component` - The component where the log message originates. +/// * `$description` - A description for the log message. +/// * `$format` - The format for the log message. +/// +/// # Returns +/// +/// This macro returns the created `Log` instance. +macro_rules! kyberlib_log_info { + ($level:expr, $component:expr, $description:expr, $format:expr) => {{ + use dtt::DateTime; + use vrd::Random; + use $crate::loggers::{Log, LogFormat, LogLevel}; + + // Get the current date and time in ISO 8601 format. + let date = DateTime::new(); + let iso = date.iso_8601; + + // Create a new random number generator + let mut rng = Random::default(); + let session_id = rng.rand().to_string(); + + let log = Log::new( + &session_id, + &iso, + $level, + $component, + $description, + $format, + ); + let _ = log.log(); + log // Return the Log instance + }}; +} +// Macro for executing a shell command and logging the operation. +#[macro_export] +/// Executes a shell command and logs the start, completion, and any errors. +/// +/// # Parameters +/// +/// * `$command` - The shell command to execute. +/// * `$package` - The name of the package being operated on. +/// * `$operation` - A description of the operation. +/// * `$start_message` - The message to log at the start of the operation. +/// * `$complete_message` - The message to log upon successful completion. +/// * `$error_message` - The message to log in case of an error. +/// +/// # Returns +/// +/// Returns a `Result<(), anyhow::Error>` to indicate the success or failure of the command execution. +macro_rules! kyberlib_execute_and_log { + ($command:expr, $package:expr, $operation:expr, $start_message:expr, $complete_message:expr, $error_message:expr) => {{ + use anyhow::{Context, Result as AnyResult}; + use $crate::loggers::{LogFormat, LogLevel}; + use $crate::kyberlib_log_info; + + kyberlib_log_info!( + LogLevel::INFO, + $operation, + $start_message, + LogFormat::CLF + ); + + $command + .run() + .map(|_| ()) + .map_err(|err| { + kyberlib_log_info!( + LogLevel::ERROR, + $operation, + $error_message, + LogFormat::CLF + ); + err + }) + .with_context(|| { + format!( + "Failed to execute '{}' for {} on package '{}'", + stringify!($command), + $operation, + $package + ) + })?; + + kyberlib_log_info!( + LogLevel::INFO, + $operation, + $complete_message, + LogFormat::CLF + ); + Ok(()) + }}; +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..671af24 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: Copyright ยฉ 2023 kyberlib. All rights reserved. +// SPDX-License-Identifier: MIT + +/// This is the main entry point for the kyberlib application. +fn main() { + // Call the `run()` function from the `kyberlib` module. + if let Err(err) = kyberlib::run() { + eprintln!("Error running kyberlib: {}", err); + std::process::exit(1); + } +} diff --git a/tests/test.rs b/tests/test.rs new file mode 100644 index 0000000..5d57298 --- /dev/null +++ b/tests/test.rs @@ -0,0 +1,11 @@ +#[cfg(test)] +mod tests { + + use kyberlib::kyberlib; + + #[test] + fn test_kyberlib() { + let kyberlib = kyberlib::new(); + assert_eq!(kyberlib, kyberlib::default()); + } +} diff --git a/tests/test_loggers.rs b/tests/test_loggers.rs new file mode 100644 index 0000000..8ef836e --- /dev/null +++ b/tests/test_loggers.rs @@ -0,0 +1,132 @@ +// Copyright ยฉ 2023 kyberlib. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 OR MIT + +#[cfg(test)] +mod tests { + + fn kyberlib_log_info( + level: LogLevel, + component: &str, + description: &str, + format: LogFormat, + ) { + let log = + kyberlib_log_info!(level, component, description, format); + assert_eq!(log.level, level); + assert_eq!(log.component, component); + assert_eq!(log.description, description); + assert_eq!(log.format, format); + } + + #[test] + fn test_macros() { + kyberlib_log_info( + LogLevel::ALL, + "component", + "description", + LogFormat::CLF, + ); + kyberlib_log_info( + LogLevel::DEBUG, + "component", + "description", + LogFormat::CLF, + ); + kyberlib_log_info( + LogLevel::DISABLED, + "component", + "description", + LogFormat::CLF, + ); + kyberlib_log_info( + LogLevel::ERROR, + "component", + "description", + LogFormat::CLF, + ); + kyberlib_log_info( + LogLevel::FATAL, + "component", + "description", + LogFormat::CLF, + ); + kyberlib_log_info( + LogLevel::INFO, + "component", + "description", + LogFormat::CLF, + ); + kyberlib_log_info( + LogLevel::NONE, + "component", + "description", + LogFormat::CLF, + ); + kyberlib_log_info( + LogLevel::TRACE, + "component", + "description", + LogFormat::CLF, + ); + kyberlib_log_info( + LogLevel::VERBOSE, + "component", + "description", + LogFormat::CLF, + ); + kyberlib_log_info( + LogLevel::WARNING, + "component", + "description", + LogFormat::CLF, + ); + } + + use kyberlib::{ + loggers::{Log, LogFormat, LogLevel}, + kyberlib_log_info, + }; + + #[test] + fn test_log_level_display() { + let level = LogLevel::INFO; + assert_eq!(format!("{level}"), "INFO"); + } + + #[test] + fn test_log_format_display() { + let format = LogFormat::JSON; + assert_eq!(format!("{format}"), "JSON\n"); + } + + #[test] + fn test_log_new() { + let log = Log::new( + "session123", + "2023-02-28T12:34:56Z", + LogLevel::WARNING, + "auth", + "Invalid credentials", + LogFormat::CLF, + ); + + assert_eq!(log.session_id, "session123"); + assert_eq!(log.time, "2023-02-28T12:34:56Z"); + assert_eq!(log.level, LogLevel::WARNING); + assert_eq!(log.component, "auth"); + assert_eq!(log.description, "Invalid credentials"); + assert_eq!(log.format, LogFormat::CLF); + } + + #[test] + fn test_log_default() { + let log = Log::default(); + + assert!(log.session_id.is_empty()); + assert!(log.time.is_empty()); + assert_eq!(log.level, LogLevel::INFO); + assert!(log.component.is_empty()); + assert!(log.description.is_empty()); + assert_eq!(log.format, LogFormat::CLF); + } +}