Skip to content

Commit

Permalink
v0.10.1 (#34)
Browse files Browse the repository at this point in the history
* clippy + fmt

* v0.10.1

* Capitalization
  • Loading branch information
brycx committed Feb 1, 2022
1 parent a511c5d commit acfa761
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 32 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "branca"
description = "Authenticated encrypted API tokens for Rust. A secure alternative to JWT."
version = "0.10.0"
version = "0.10.1"
authors = ["return"]
edition = "2018"
keywords = ["fernet", "branca", "cryptography", "aead", "xchacha20_poly1305"]
Expand All @@ -15,8 +15,8 @@ repository = "https://github.com/return/branca"
maintenance = { status = "actively-developed" }

[dependencies]
base-x = "0.2.6"
byteorder = "1.3.4"
base-x = "0.2.8"
byteorder = "1.4.3"
orion = "0.17.0"

[dev-dependencies]
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Branca is a secure alternative token format to JWT. This implementation is writt

# Security

_NOTE: Branca uses orion for its cryptographic primitives and due to orion not receiving any formal security audit, the same security risks that orion has also applies to this Branca implementation if one uses it in production. For a better understanding about the security risks involved, see the orion [wiki](https://github.com/orion-rs/orion/wiki/Security)._
_NOTE: Branca uses Orion for its cryptographic primitives and due to Orion not receiving any formal security audit, the same security risks that Orion has also applies to this Branca implementation if one uses it in production. For a better understanding about the security risks involved, see the Orion [wiki](https://github.com/orion-rs/orion/wiki/Security)._

**⚠️ Use at your own risk. ⚠️**

# Requirements

* Rust 1.51
* Rust 1.52
* Cargo

# Installation
Expand Down Expand Up @@ -90,7 +90,7 @@ if decoded.is_err() {
## Encode/Decode arbitrary data structures with Serde.
Since Branca is able to work with any format of data in the payload, it is possible for the payload to be anything from a JSON object, plaintext, raw bytes, protocol buffers or even a JWT.

Here is a example of using Branca to encode/decode a typical JSON object with serde_json.
Here is an example of using Branca to encode/decode a typical JSON object with serde_json.

Add the following into your Cargo.toml file:
```toml
Expand Down Expand Up @@ -143,7 +143,7 @@ fn main(){
}
```

Branca uses [Orion](https://github.com/orion-rs/orion) to generate secure random nonces when using the encode() and builder methods. By default, Branca does not allow setting the nonce directly since that there is a risk that it can be reused by the user which is a foot-gun.
Branca uses [Orion](https://github.com/orion-rs/orion) to generate secure random nonces when using the `encode()` and builder methods. By default, Branca does not allow setting the nonce directly since that there is a risk that it can be reused by the user which is a foot-gun.

The nonce generated **must be 24 bytes in length.** Keys **must be 32 bytes in length.**

Expand Down
48 changes: 23 additions & 25 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ mod unit_tests {
let key = b"supersecretkeyyoushouldnotcommit";
let mut token = Branca::new(key).unwrap();
let ciphertext = token.set_timestamp(123206400).encode(b"Test");
assert_eq!(ciphertext.is_ok(), true);
assert!(ciphertext.is_ok());
}

#[test]
Expand Down Expand Up @@ -693,7 +693,7 @@ mod unit_tests {
serde_json::from_str(&String::from_utf8_lossy(&json)).unwrap();

assert_eq!(serialized_json.a, "some string");
assert_eq!(serialized_json.b, false);
assert!(!serialized_json.b);
}

#[test]
Expand All @@ -719,7 +719,7 @@ mod unit_tests {
serde_json::from_str(&String::from_utf8_lossy(&json)).unwrap();

assert_eq!(serialized_json.a, "some string");
assert_eq!(serialized_json.b, false);
assert!(!serialized_json.b);
}

#[test]
Expand All @@ -738,9 +738,9 @@ mod unit_tests {
let mut token = Branca::new(key).unwrap();
let ciphertext = token.set_timestamp(123206400).encode(b"Test").unwrap();
let payload = token.decode(ciphertext.as_str(), 0);
match payload {
Err(e) => assert_eq!(e, BrancaError::ExpiredToken),
Ok(_) => {}

if let Err(e) = payload {
assert_eq!(e, BrancaError::ExpiredToken)
}
}

Expand All @@ -752,9 +752,8 @@ mod unit_tests {
let ttl = 3600;
let message = decode(ciphertext, key, ttl);

match message {
Err(e) => assert_eq!(e, BrancaError::ExpiredToken),
Ok(_) => {}
if let Err(e) = message {
assert_eq!(e, BrancaError::ExpiredToken)
}
}

Expand All @@ -766,9 +765,8 @@ mod unit_tests {
let ttl = 0;
let branca_token = decode(ciphertext, key, ttl);

match branca_token {
Err(e) => assert_eq!(e, BrancaError::DecryptFailed),
Ok(_) => {}
if let Err(e) = branca_token {
assert_eq!(e, BrancaError::DecryptFailed)
}
}

Expand All @@ -779,9 +777,8 @@ mod unit_tests {
let ttl = 0;
let branca_token = decode(ciphertext, key, ttl);

match branca_token {
Err(e) => assert_eq!(e, BrancaError::InvalidBase62Token),
Ok(_) => {}
if let Err(e) = branca_token {
assert_eq!(e, BrancaError::InvalidBase62Token)
}
}

Expand All @@ -792,9 +789,8 @@ mod unit_tests {
let timestamp = 123206400;
let branca_token = encode(message, key, timestamp);

match branca_token {
Err(e) => assert_eq!(e, BrancaError::BadKeyLength),
Ok(_) => {}
if let Err(e) = branca_token {
assert_eq!(e, BrancaError::BadKeyLength)
}
}

Expand All @@ -806,9 +802,8 @@ mod unit_tests {
let ttl = 0;
let branca_token = decode(ciphertext, key, ttl);

match branca_token {
Err(e) => assert_eq!(e, BrancaError::InvalidTokenVersion),
Ok(_) => {}
if let Err(e) = branca_token {
assert_eq!(e, BrancaError::InvalidTokenVersion)
}
}

Expand All @@ -824,9 +819,9 @@ mod unit_tests {
// 651323084: Some day in 1990
BigEndian::write_u32(&mut decoded[1..5], 651323084);

assert!(
decode(&b62_encode(BASE62, &decoded), key, 1000).unwrap_err()
== BrancaError::DecryptFailed
assert_eq!(
decode(&b62_encode(BASE62, &decoded), key, 1000).unwrap_err(),
BrancaError::DecryptFailed
);
}

Expand Down Expand Up @@ -876,7 +871,10 @@ mod unit_tests {
let mut token = encode(b"Hello world!", key, 0).unwrap();
token.push('_');

assert!(decode(&token, key, 0).unwrap_err() == BrancaError::InvalidBase62Token);
assert_eq!(
decode(&token, key, 0).unwrap_err(),
BrancaError::InvalidBase62Token
);
}

#[test]
Expand Down

0 comments on commit acfa761

Please sign in to comment.