Cryptor is encryption machine corresponding to the diversity of algorithms.
Insert to Cargo.toml of your project.
[dependencies]
cryptor = "0.1.3"
or
// Newest version
❯ cargo add cryptor
// Version specification
❯ cargo add cryptor@0.1.3
// If not exist on crates.io
❯ mkdir lib
❯ cd lib
❯ git clone https://github.com/atsushi130/Cryptor
❯ cd ..
❯ cargo add cryptor --path=lib/cryptor/
Import modules
extern crate cryptor;
use cryptor::cryptor::{ Cryptor, CryptoValue, Algorithm };
Implement structure with this Algorithm trait.
pub trait Algorithm {
type V: Algorithm;
fn encrypt(&mut self, character: &char) -> CryptoValue<Self::V>;
fn decrypt(&mut self, character: &char) -> CryptoValue<Self::V>;
}
Cryptor have member with Algorithm trait. Dependency injection your implemented structure to Cryptor.
let mut cryptor = Cryptor::new(YourAlgorithm);
Return type of encrypt and decrypt method is CryptoValue<YourAlgorithm>
.
let encrypted: CryptoValue<YourAlgorithm> = cryptor.encrypt(&string);
println!("encrypted string is {}", encrypted.text);
let decrypted: CryptoValue<YourAlgorithm> = cryptor.decrypt(&string);
println!("decrypted string is {}", decrypted.text);
❯ cargo build
❯ cargo run
❯ cargo test
v0.1.3
Defined associated function to builds new Cryptor.
impl<T: Algorithm> Cryptor<T> {
pub fn new(algorithm: T) -> Self {
Cryptor {
algorithm
}
}
}
changed usage
let mut cryptor = Cryptor::new(your_algorithm);
This project is dual-licensed under MIT and Apache 2.0.