Skip to content

Commit

Permalink
Merge pull request #14 from atsushi130/release/v0.1.3
Browse files Browse the repository at this point in the history
Released v0.1.3
  • Loading branch information
atsushi authored May 25, 2017
2 parents c366b9d + 5fee3b9 commit 24504c3
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
[package]
name = "cryptor"
version = "0.1.2"
version = "0.1.3"
authors = ["atsushi130 <[email protected]>"]
license = "MIT/Apache-2.0"
description = "Cryptor is encryption machine corresponding to the diversity of algorithms."
readme = "README.md"
repository = "https://github.com/atsushi130/Cryptor"
keywords = ["enigma", "cipher", "encrypt", "decrypt", "base64"]

[badges]
travis-ci = { repository = "atsushi130/Cryptor" }

[dependencies]
lazy_static = "0.2.8"
base64 = "~0.5.0"
Expand Down
45 changes: 24 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# Cryptor
[![MIT / Apache2.0 dual licensed](https://img.shields.io/badge/dual%20license-MIT%20/%20Apache%202.0-blue.svg)](./LICENSE.md)
[![MIT / Apache2.0 dual licensed](https://img.shields.io/badge/dual%20license-MIT%20/%20Apache%202.0-blue.svg)](./LICENSE-MIT.md)
[![Travis Build Status](https://api.travis-ci.org/atsushi130/Cryptor.svg?branch=master)](https://travis-ci.org/atsushi130/Cryptor)
[![crates.io](https://img.shields.io/crates/v/cryptor.svg)](https://crates.io/crates/cryptor)
[![Document](https://img.shields.io/badge/Cryptor-Document-3B5998.svg)](https://docs.rs/cryptor/0.1.1/cryptor/)
[![Document](https://img.shields.io/badge/Cryptor-Document-3B5998.svg)](https://docs.rs/cryptor/0.1.3/cryptor/)

Cryptor is encryption machine corresponding to the diversity of algorithms.

## Dependencies
Insert to Cargo.toml of your project.
```toml
[dependencies]
cryptor = "0.1.2"
cryptor = "0.1.3"
```
or
```console
// Newest version
cargo add cryptor

// Version specification
cargo add [email protected].2
cargo add [email protected].3

// If not exist on crates.io
mkdir lib
Expand Down Expand Up @@ -51,12 +51,10 @@ pub trait Algorithm {

Cryptor have member with Algorithm trait. Dependency injection your implemented structure to Cryptor.
```rust
let mut cryptor = Cryptor {
algorithm: YourAlgorithm { ... }
};
let mut cryptor = Cryptor::new(YourAlgorithm);
```

Return type of encrypt and decrypt method is `CryptoValue<YourAlgorithm>`;
Return type of encrypt and decrypt method is `CryptoValue<YourAlgorithm>`.
```rust
let encrypted: CryptoValue<YourAlgorithm> = cryptor.encrypt(&string);
println!("encrypted string is {}", encrypted.text);
Expand All @@ -65,19 +63,6 @@ let decrypted: CryptoValue<YourAlgorithm> = cryptor.decrypt(&string);
println!("decrypted string is {}", decrypted.text);
```

Encrypter have member with Algorithm trait. Dependency injection your implemented structure to Encrypter.
```rust
let mut encrypter = Encrypter {
hash: YourAlgorithm { ... }
};
```

Return type of encrypt method is `EncryptValue<YourAlgorithm>`.
```rust
let encrypted: EncryptValue<YourAlgorithm> = encrypter.encrypt(&character);
println!("encrypted character is {}", encrypted.text);
```

## Run
```console
cargo build
Expand All @@ -91,5 +76,23 @@ println!("encrypted character is {}", encrypted.text);

```

## Change logs
**v0.1.3**
Defined associated function to builds new Cryptor.
```rust
impl<T: Algorithm> Cryptor<T> {
pub fn new(algorithm: T) -> Self {
Cryptor {
algorithm
}
}
}
```

**changed usage**
```rust
let mut cryptor = Cryptor::new(your_algorithm);
```

## LICENSE
**This project is dual-licensed under MIT and Apache 2.0.**
3 changes: 2 additions & 1 deletion src/cryptor/algorithm/base64/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Base64
[![Base64](https://img.shields.io/badge/Cryptor-Base64-6fb536.svg)](https://github.com/atsushi130/Cryptor/tree/master/src/cryptor/algorithm/base64)
[![Document](https://img.shields.io/badge/Base64-Document-3B5998.svg)](https://docs.rs/cryptor/0.1.3/cryptor/cryptor/struct.Base64.html)

## Usage
**Import modules**
Expand All @@ -11,7 +12,7 @@ use cryptor::cryptor::{ Cryptor, CryptoValue };

**Setup Cryptor**
```rust
let mut cryptor = Cryptor { algorithm: Base64 };
let mut cryptor = Cryptor::new(Base64);
```

**Encryption**
Expand Down
4 changes: 2 additions & 2 deletions src/cryptor/algorithm/enigma/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Enigma
[![Enigma](https://img.shields.io/badge/Cryptor-Enigma-6fb536.svg)](https://github.com/atsushi130/Cryptor/tree/master/src/cryptor/algorithm/enigma)
[![Document](https://img.shields.io/badge/Enigma-Document-3B5998.svg)](https://docs.rs/cryptor/0.1.1/cryptor/cryptor/struct.Enigma.html)
[![Document](https://img.shields.io/badge/Enigma-Document-3B5998.svg)](https://docs.rs/cryptor/0.1.3/cryptor/cryptor/struct.Enigma.html)

## Usage
**Import modules**
Expand All @@ -27,7 +27,7 @@ let enigma = Enigma::new(

**Setup Cryptor**
```rust
let mut cryptor = Cryptor { algorithm: enigma };
let mut cryptor = Cryptor::new(enigma);
```

**Encryption**
Expand Down
4 changes: 1 addition & 3 deletions src/cryptor/algorithm/enigma/enigma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ impl Enigma {
}

fn build_base64_cryptor(&self) -> Cryptor<Base64> {
Cryptor {
algorithm: Base64
}
Cryptor::new(Base64)
}
}
6 changes: 6 additions & 0 deletions src/cryptor/cryptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ pub struct Cryptor<T: Algorithm> {

impl<T: Algorithm> Cryptor<T> {

pub fn new(algorithm: T) -> Self {
Cryptor {
algorithm
}
}

pub fn encrypt(&mut self, string: &str) -> CryptoValue<T::V> {
self.algorithm.encrypt(string)
}
Expand Down
9 changes: 5 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ mod utility;

#[cfg(not(test))]
fn main() {
let mut cryptor = Cryptor {
algorithm: Enigma::new(

let enigma = Enigma::new(
vec![
Router::new(SubstitutionTable::new(SUBSTITUTION_TABLE1.to_vec())),
Router::new(SubstitutionTable::new(SUBSTITUTION_TABLE2.to_vec())),
Router::new(SubstitutionTable::new(SUBSTITUTION_TABLE3.to_vec())),
],
Plugboard::new(SubstitutionTable::new(PLUGBOARD.to_vec())),
Reflector::new(SubstitutionTable::new(REFLECTOR.to_vec()))
)
};
);

let mut cryptor = Cryptor::new(enigma);

let characters1 = "0V+/;e.\"%¥HN=P\"%WLkKC=xK[N<(DemmE=+.D\"bErC#X!|^G.{#5:KVr";
let characters2 = "**~_}*jl\'*fK\'=eG\'\'sP\'\\n<MMY@";
Expand Down
32 changes: 16 additions & 16 deletions tests/cryptor_tests/cryptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,43 @@ mod encrypter_tests {
#[test]
fn encryptable() {

#[allow(unused_mut)]
let mut encrypter = Cryptor {
algorithm: Enigma::new(
let enigma = Enigma::new(
vec![
Router::new(SubstitutionTable::new(ALPHABETS.to_vec())),
Router::new(SubstitutionTable::new(ALPHABETS.to_vec())),
Router::new(SubstitutionTable::new(ALPHABETS.to_vec()))
],
Plugboard::new(SubstitutionTable::new(ALPHABETS.to_vec())),
Reflector::new(SubstitutionTable::new(ALPHABETS.to_vec()))
)
};
);

#[allow(unused_mut)]
let mut encrypter = Cryptor::new(enigma);

let result: CryptoValue<Enigma> = encrypter.encrypt(&'A');
assert_eq!("A", result.text);
let result: CryptoValue<Enigma> = encrypter.encrypt(&"A");
assert_eq!("QQ==", result.text);
}

#[test]
fn encryptable_two_characters() {

#[allow(unused_mut)]
let mut encrypter = Cryptor {
algorithm: Enigma::new(
let enigma = Enigma::new(
vec![
Router::new(SubstitutionTable::new(ALPHABETS.to_vec())),
Router::new(SubstitutionTable::new(ALPHABETS.to_vec())),
Router::new(SubstitutionTable::new(ALPHABETS.to_vec()))
],
Plugboard::new(SubstitutionTable::new(ALPHABETS.to_vec())),
Reflector::new(SubstitutionTable::new(ALPHABETS.to_vec()))
)
};
);

#[allow(unused_mut)]
let mut encrypter = Cryptor::new(enigma);

let result1: CryptoValue<Enigma> = encrypter.encrypt(&'A');
let result2: CryptoValue<Enigma> = encrypter.encrypt(&'A');
let result1: CryptoValue<Enigma> = encrypter.encrypt(&"A");
let result2: CryptoValue<Enigma> = encrypter.encrypt(&"A");

assert_eq!("A", result1.text);
assert_eq!("A", result2.text);
assert_eq!("QQ==", result1.text);
assert_eq!("QQ==", result2.text);
}
}
1 change: 1 addition & 0 deletions tests/cryptor_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
// This file may not be copied, modified, or distributed except according to those terms.

pub mod algorithm;
pub mod cryptor;

0 comments on commit 24504c3

Please sign in to comment.