mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-22 22:18:23 -05:00
efa8efc6c7
* attempt1 * rough draft * add features and their optional dependancies * add encryption and compression error variants * add a sample implementation to cache trait * Update src/cache/cacher.rs Co-authored-by: neon_arch <mustafadhuleb53@gmail.com> * adjust comment so feature flag would apply? * adjust feature flag so it applies? * formatting * Update src/cache/cacher.rs update documentation Co-authored-by: neon_arch <mustafadhuleb53@gmail.com> * [features]Add base64 and chacha20 dependencies for compress-cache-results and encrypt-cache-results * move encryption key and cipher logic to separate sub module * added cacha20 and cec-results feature * added cacha20 and cec-results feature * added compression and encryption helper functions to trait implementations * added compression and encryption implementation for inMemoryCache * base64 is only requried when redis-cache feature is enabled * add error case for base64 and encryption/compression implementation to redisCache * Refactor cacher to remove regex dependency * fmt cache error and cacher * Update Cargo.toml disabling the unneeded default-features Co-authored-by: neon_arch <mustafadhuleb53@gmail.com> * fix unused import warning for mimalloc * remove deprecated method * add doc comments for encryption module * fix known bugs and use cfg-if module * make cfg-if an optional dependency * use feature-flag instead of maco lint * add comment to explain type complexity * bump app version * Update src/cache/encryption.rs Co-authored-by: neon_arch <mustafadhuleb53@gmail.com> * fixed type complexity and add docs for types --------- Co-authored-by: Spencer Najib <spencernajib2@gmail.com> Co-authored-by: alamin655 <mdalamin655@outlook.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: neon_arch <mustafadhuleb53@gmail.com> Co-authored-by: Spencerjibz <=spencernajib2@gmail.com> Co-authored-by: spencer <spencer@DESKTOP-SIF13AR>
26 lines
903 B
Rust
26 lines
903 B
Rust
use chacha20poly1305::{
|
|
consts::{B0, B1},
|
|
ChaChaPoly1305,
|
|
};
|
|
use std::sync::OnceLock;
|
|
|
|
use chacha20::{
|
|
cipher::{
|
|
generic_array::GenericArray,
|
|
typenum::{UInt, UTerm},
|
|
StreamCipherCoreWrapper,
|
|
},
|
|
ChaChaCore,
|
|
};
|
|
|
|
/// The ChaCha20 core wrapped in a stream cipher for use in ChaCha20-Poly1305 authenticated encryption.
|
|
type StreamCipherCoreWrapperType =
|
|
StreamCipherCoreWrapper<ChaChaCore<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B1>, B0>>>;
|
|
/// Our ChaCha20-Poly1305 cipher instance, lazily initialized.
|
|
pub static CIPHER: OnceLock<ChaChaPoly1305<StreamCipherCoreWrapperType>> = OnceLock::new();
|
|
|
|
/// The type alias for our encryption key, a 32-byte array.
|
|
type GenericArrayType = GenericArray<u8, UInt<UInt<UInt<UInt<UTerm, B1>, B1>, B0>, B0>>;
|
|
/// Our encryption key, lazily initialized.
|
|
pub static ENCRYPTION_KEY: OnceLock<GenericArrayType> = OnceLock::new();
|