chore(release): v0.3.0

This commit is contained in:
MedzikUser 2022-06-23 11:47:54 +02:00
parent c858a1b161
commit f5cea73f80
No known key found for this signature in database
GPG Key ID: A5FAC1E185C112DB
6 changed files with 29 additions and 77 deletions

View File

@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
## [0.3.0] - 2022-06-23
- updated dependencies
### Features
- **jwt**: pub use type `TokenData`
## [0.2.1] - 2022-06-18
### Added
- [Examples](https://github.com/MedzikUser/rust-crypto-utils/tree/v0.2.1/examples)
@ -24,7 +29,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Sha1, Sha256, Sha512 hasher
<!-- next-url -->
[Unreleased]: https://github.com/MedzikUser/imgurs/compare/v0.2.1...HEAD
[Unreleased]: https://github.com/MedzikUser/imgurs/compare/v0.3.0...HEAD
[0.3.0]: https://github.com/MedzikUser/imgurs/commits/v0.3.0
[0.2.1]: https://github.com/MedzikUser/imgurs/commits/v0.2.1
[0.2.0]: https://github.com/MedzikUser/imgurs/commits/v0.2.0
[0.1.0]: https://github.com/MedzikUser/imgurs/commits/v0.1.0

20
Cargo.lock generated
View File

@ -81,7 +81,7 @@ dependencies = [
[[package]]
name = "crypto-utils"
version = "0.2.1"
version = "0.3.0"
dependencies = [
"anyhow",
"chrono",
@ -224,18 +224,18 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.39"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f"
checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.18"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1"
checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804"
dependencies = [
"proc-macro2",
]
@ -323,7 +323,7 @@ dependencies = [
"num-bigint",
"num-traits",
"thiserror",
"time 0.3.9",
"time 0.3.11",
]
[[package]]
@ -334,9 +334,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]]
name = "syn"
version = "1.0.96"
version = "1.0.98"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf"
checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd"
dependencies = [
"proc-macro2",
"quote",
@ -376,9 +376,9 @@ dependencies = [
[[package]]
name = "time"
version = "0.3.9"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2702e08a7a860f005826c6815dcac101b19b5eb330c27fe4a5928fec1d20ddd"
checksum = "72c91f41dcb2f096c05f0873d667dceec1087ce5bcf984ec8ffb19acddbb3217"
dependencies = [
"itoa",
"libc",

View File

@ -1,6 +1,6 @@
[package]
name = "crypto-utils"
version = "0.2.1"
version = "0.3.0"
description = "Cryptography Utils for Rust"
authors = ["MedzikUser <nivua1fn@duck.com>"]
license = "MIT"

View File

@ -1,8 +1,5 @@
//! Module for creating and decoding json web token.
//!
//! **Required `jwt` feature!**
//!
//! Examples:
//! ```
//! use crypto_utils::jsonwebtoken::{Claims, Token};
//!
@ -21,7 +18,7 @@
use chrono::{Duration, Utc};
use jsonwebtoken::{
errors::Error, Algorithm, DecodingKey, EncodingKey, Header, TokenData, Validation,
errors::Error, Algorithm, DecodingKey, EncodingKey, Header, Validation,
};
use serde::{Deserialize, Serialize};
@ -57,6 +54,9 @@ impl Claims {
}
}
/// The return type of a successful call to [decode](Token::decode).
pub type TokenData = jsonwebtoken::TokenData<Claims>;
/// Json Web Token
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Token {
@ -112,7 +112,7 @@ impl Token {
/// // decode token
/// let decoded = Token::decode(secret, token.encoded).unwrap();
/// ```
pub fn decode(key: &[u8], token: String) -> Result<TokenData<Claims>, Error> {
pub fn decode(key: &[u8], token: String) -> Result<TokenData, Error> {
jsonwebtoken::decode::<Claims>(
&token,
&DecodingKey::from_secret(key),

View File

@ -16,70 +16,19 @@
//!
//! ```toml
//! [dependencies]
//! crypto-utils = "0.2.1"
//! crypto-utils = "0.3.0"
//! ```
//!
//! ## How to use?
//!
//! ### Compute a Sha hash
//!
//! Add `sha` features (is enabled by default)
//!
//! ```toml
//! [dependencies]
//! crypto-utils = { version = "...", features = ["sha"] }
//! ```
//!
//! Quick and easy Sha1, Sha256 and Sha512 hash computing.
//!
//! ```
//! use crypto_utils::sha::{Algorithm, CryptographicHash};
//!
//! // input data for a hasher
//! let input = "P@ssw0rd"; // &str
//!
//! // compute hash
//! let hash_bytes = CryptographicHash::hash(Algorithm::SHA1, input.as_bytes()); // Vec<u8>
//!
//! // decode hash to a String
//! let hash = hex::encode(hash_bytes); // String
//!
//! assert_eq!(hash, "21bd12dc183f740ee76f27b78eb39c8ad972a757".to_string())
//! ```
//!
//! ### Json Web Token
//!
//! Add `jwt` features (is enabled by default)
//!
//! ```toml
//! [dependencies]
//! crypto-utils = { version = "...", features = ["jwt"] }
//! ```
//!
//! Create and decode a token
//!
//! ```
//! use crypto_utils::jsonwebtoken::{Claims, Token};
//!
//! let secret = b"secret";
//! let user_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
//!
//! // create claims
//! let claims = Claims::new(user_id, 24);
//!
//! // create token
//! let token = Token::new(secret, claims).unwrap();
//!
//! // decode token
//! let decoded = Token::decode(secret, token.encoded).unwrap();
//! ```
//! Check [jsonwebtoken] and [sha] module
//!
//! ## All Feature flags
//!
//! | Feature | Description | Dependencies | Default |
//! |:-----------|:-------------------------------------------------------------|:-------------------------------------------|:--------|
//! | `sha` | Enable support for the Sha1, Sha256 and Sha512 hasher | `sha` and `sha2` | yes |
//! | `jwt` | Enable support for the Json Web Token utils | `chrono`, `serde` and `jsonwebtoken` | yes |
//! | Feature | Description | Dependencies | Default |
//! |:---------|:------------------------------------------------------------|:----------------------------------------|:--------|
//! | `sha` | Enable support for the Sha1, Sha256 and Sha512 hasher | `sha` and `sha2` | yes |
//! | `jwt` | Enable support for the Json Web Token utils | `chrono`, `serde` and `jsonwebtoken` | yes |
#![warn(missing_docs)]

View File

@ -1,8 +1,5 @@
//! Module for creating sha1, sha256 and sha512 hashes.
//!
//! **Required `sha` feature!**
//!
//! Examples:
//! ```
//! use crypto_utils::sha::{Algorithm, CryptographicHash};
//!