cryptor

Crates.iocryptor
lib.rscryptor
version0.1.3
sourcesrc
created_at2017-05-21 10:22:47.071733
updated_at2017-05-25 00:01:27.560407
descriptionCryptor is encryption machine corresponding to the diversity of algorithms.
homepage
repositoryhttps://github.com/atsushi130/Cryptor
max_upload_size
id15447
size60,666
Atsushi Miyake (atsushi130)

documentation

README

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 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/

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 build
❯ cargo 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.

Commit count: 53

cargo fmt