-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from atsushi130/develop
v0.1.2
- Loading branch information
Showing
13 changed files
with
121 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
[package] | ||
name = "cryptor" | ||
version = "0.1.1" | ||
version = "0.1.2" | ||
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"] | ||
keywords = ["enigma", "cipher", "encrypt", "decrypt", "base64"] | ||
|
||
[dependencies] | ||
lazy_static = "0.2.8" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,22 +2,23 @@ | |
[![MIT / Apache2.0 dual licensed](https://img.shields.io/badge/dual%20license-MIT%20/%20Apache%202.0-blue.svg)](./LICENSE.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/) | ||
|
||
Cryptor is encryption machine corresponding to the diversity of algorithms. | ||
|
||
## Dependencies | ||
Insert to Cargo.toml of your project. | ||
```toml | ||
[dependencies] | ||
cryptor = "0.1.0" | ||
cryptor = "0.1.2" | ||
``` | ||
or | ||
```console | ||
// Newest version | ||
❯ cargo add cryptor | ||
|
||
// Version specification | ||
❯ cargo add [email protected].0 | ||
❯ cargo add [email protected].2 | ||
|
||
// If not exist on crates.io | ||
❯ mkdir lib | ||
|
@@ -27,8 +28,9 @@ or | |
❯ cargo add cryptor --path=lib/cryptor/ | ||
``` | ||
|
||
## Default Crypto algorithm | ||
- [Enigma](https://github.com/atsushi130/Cryptor/tree/master/src/cryptor/algorithm/enigma) | ||
## Default crypto algorithm | ||
- [![Enigma](https://img.shields.io/badge/Cryptor-Enigma-6fb536.svg)](https://github.com/atsushi130/Cryptor/tree/master/src/cryptor/algorithm/enigma) | ||
- [![Base64](https://img.shields.io/badge/Cryptor-Base64-6fb536.svg)](https://github.com/atsushi130/Cryptor/tree/master/src/cryptor/algorithm/base64) | ||
|
||
## Usage | ||
|
||
|
@@ -70,7 +72,7 @@ let mut encrypter = Encrypter { | |
}; | ||
``` | ||
|
||
Return type of encrypt method is `EncryptValue<YourAlgorithm>`; | ||
Return type of encrypt method is `EncryptValue<YourAlgorithm>`. | ||
```rust | ||
let encrypted: EncryptValue<YourAlgorithm> = encrypter.encrypt(&character); | ||
println!("encrypted character is {}", encrypted.text); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Base64 | ||
[![Base64](https://img.shields.io/badge/Cryptor-Base64-6fb536.svg)](https://github.com/atsushi130/Cryptor/tree/master/src/cryptor/algorithm/base64) | ||
|
||
## Usage | ||
**Import modules** | ||
```rust | ||
extern crate cryptor; | ||
use cryptor::cryptor::{ Base64 }; | ||
use cryptor::cryptor::{ Cryptor, CryptoValue }; | ||
``` | ||
|
||
**Setup Cryptor** | ||
```rust | ||
let mut cryptor = Cryptor { algorithm: Base64 }; | ||
``` | ||
|
||
**Encryption** | ||
```rust | ||
let encrypted: CryptoValue<Base64> = cryptor.encrypt(&"A quick brown fox jumps over the lazy dog."); | ||
println!("encrypted: {}", encrypted.text); | ||
``` | ||
|
||
**Decryption** | ||
```rust | ||
let decrypted: CryptoValue<Base64>> = cryptor.encrypt(&encrypted); | ||
println!("decrypted: {}", decrypted); // decrypted: A quick brown fox jumps over the lazy dog. | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
// Copyright (c) 2017 Atsushi Miyake | ||
// | ||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or http://apache.org/licenses/LICENSE-2.0> | ||
// or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option. | ||
// This file may not be copied, modified, or distributed except according to those terms. | ||
|
||
/// data_encoding module | ||
use base64::{ encode, decode }; | ||
|
||
/// algorithm module | ||
use super::super::{Algorithm, CryptoValue}; | ||
|
||
pub struct Base64; | ||
|
||
impl Algorithm for Base64 { | ||
|
||
type V = Base64; | ||
|
||
fn encrypt(&mut self, string: &str) -> CryptoValue<Self::V> { | ||
let bytes = string.as_bytes(); | ||
let encoded = encode(&bytes); | ||
CryptoValue::new(&encoded) | ||
} | ||
|
||
fn decrypt(&mut self, string: &str) -> CryptoValue<Self::V> { | ||
let bytes = decode(string).unwrap(); | ||
let decoded = String::from_utf8(bytes).unwrap(); | ||
CryptoValue::new(&decoded) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
// Copyright (c) 2017 Atsushi Miyake | ||
// | ||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or http://apache.org/licenses/LICENSE-2.0> | ||
// or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option. | ||
// This file may not be copied, modified, or distributed except according to those terms. | ||
|
||
mod base64; | ||
pub use self::base64::Base64; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
mod base64_tests { | ||
|
||
use cryptor::cryptor::{ Base64, Algorithm }; | ||
|
||
#[test] | ||
fn encryptable() { | ||
let mut base64 = Base64; | ||
let result = base64.encrypt("A"); | ||
assert_eq!("QQ==", result.text); | ||
} | ||
|
||
#[test] | ||
fn decryptable() { | ||
let mut base64 = Base64; | ||
let result = base64.decrypt("QQ=="); | ||
assert_eq!("A", result.text); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
pub mod base64; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters