Skip to content

Latest commit

 

History

History
98 lines (80 loc) · 2.52 KB

README.md

File metadata and controls

98 lines (80 loc) · 2.52 KB

Cryptor

MIT / Apache2.0 dual licensed Travis Build Status crates.io Document

Cryptor is encryption machine corresponding to the diversity of algorithms.

Dependencies

Insert to Cargo.toml of your project.

[dependencies]
cryptor = "0.1.3"

or

// Newest versioncargo add cryptor

// Version specificationcargo add cryptor@0.1.3

// If not exist on crates.iomkdir libcd libgit clone https://github.com/atsushi130/Cryptorcd ..cargo add cryptor --path=lib/cryptor/

Default crypto algorithm

  • Enigma
  • Base64

Usage

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);

Run

cargo buildcargo run

Test

cargo test

Change logs

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);

LICENSE

This project is dual-licensed under MIT and Apache 2.0.