Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate get_x methods #69

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ jobs:
run: CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage' LLVM_PROFILE_FILE='cargo-test-%p-%m.profraw' cargo test --features=gen_secret
- name: otpauth+gensecret feature
run: CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage' LLVM_PROFILE_FILE='cargo-test-%p-%m.profraw' cargo test --features=gen_secret,otpauth
- name: Check for breaking changes
uses: obi1kenobi/cargo-semver-checks-action@v2
with:
feature-group: all-features
verbose: true
continue-on-error: true
- name: Create coverage file
run: ./grcov . --binary-path ./target/debug/deps/ -s . -t cobertura --branch --ignore-not-existing --ignore '../*' --ignore "/*" -o target/coverage/cobertura.xml
- name: Upload to codecov.io
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# [5.6.0](https://github.com/constantoine/totp-rs/releases/tag/v5.6.0) (10/06/2024)
### Changes
- Deprecated `get_qr_base64` in favor of `to_qr_base64`.
- Deprecated `get_qr_png` in favor of `to_qr_png`.
- Deprecated `get_url` in favor of `to_url`.
- Deprecated `get_secret_base32` in favor of `to_secret_base32`.

### Notes
- Deprecated methods will disappear with `6.0.0`.
- Added `cargo-semver-checks` as part of the CI.

### Special thanks
* [@virtualritz](https://github.com/virtualritz) for bringing my attention to #65.

# [5.5.0](https://github.com/constantoine/totp-rs/releases/tag/v5.5.0) (19/01/2024)
### Changes
- Documentation now indicates required feature.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "totp-rs"
version = "5.5.1"
version = "5.6.0"
authors = ["Cleo Rebert <cleo.rebert@gmail.com>"]
rust-version = "1.61"
edition = "2021"
Expand Down
64 changes: 32 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ Be aware that some authenticator apps will accept the `SHA256` and `SHA512` algo
### qr
With optional feature "qr", you can use it to generate a base64 png qrcode. This will enable feature `otpauth`.
### otpauth
With optional feature "otpauth", support parsing the TOTP parameters from an `otpauth` URL, and generating an `otpauth` URL. It adds 2 fields to `TOTP`.
With optional feature "otpauth", support parsing the TOTP parameters from an `otpauth` URL, and generating an `otpauth` URL. It adds 2 fields to `Totp`.
### serde_support
With optional feature "serde_support", library-defined types `TOTP` and `Algorithm` and will be Deserialize-able and Serialize-able.
With optional feature "serde_support", library-defined types `Totp` and `Algorithm` and will be Deserialize-able and Serialize-able.
### gen_secret
With optional feature "gen_secret", a secret will be generated for you to store in database.
### zeroize
Securely zero secret information when the TOTP struct is dropped.
Securely zero secret information when the `Totp` struct is dropped.
### steam
Add support for Steam TOTP tokens.

Expand All @@ -34,7 +34,7 @@ Add support for Steam TOTP tokens.
4. [Enable otpauth url support](#with-otpauth-url-support)
5. [Enable gen_secret support](#with-gensecret)
6. [With RFC-6238 compliant default](#with-rfc-6238-compliant-default)
7. [New TOTP from steam secret](#new-totp-from-steam-secret)
7. [New Totp from steam secret](#new-totp-from-steam-secret)

### Understanding Secret
---
Expand All @@ -51,15 +51,15 @@ Secret::Encoded("KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ".to_string())
Add it to your `Cargo.toml`:
```toml
[dependencies]
totp-rs = "^5.0"
totp-rs = "^5.6"
```
You can then do something like:
```Rust
use std::time::SystemTime;
use totp_rs::{Algorithm, TOTP, Secret};
use totp_rs::{Algorithm, Totp, Secret};

fn main() {
let totp = TOTP::new(
let totp = Totp::new(
Algorithm::SHA1,
6,
1,
Expand All @@ -73,10 +73,10 @@ fn main() {
Which is equivalent to:
```Rust
use std::time::SystemTime;
use totp_rs::{Algorithm, TOTP, Secret};
use totp_rs::{Algorithm, Totp, Secret};

fn main() {
let totp = TOTP::new(
let totp = Totp::new(
Algorithm::SHA1,
6,
1,
Expand All @@ -92,15 +92,15 @@ fn main() {
Add it to your `Cargo.toml`:
```toml
[dependencies.totp-rs]
version = "^5.3"
version = "^5.6"
features = ["qr"]
```
You can then do something like:
```Rust
use totp_rs::{Algorithm, TOTP, Secret};
use totp_rs::{Algorithm, Totp, Secret};

fn main() {
let totp = TOTP::new(
let totp = Totp::new(
Algorithm::SHA1,
6,
1,
Expand All @@ -109,7 +109,7 @@ fn main() {
Some("Github".to_string()),
"constantoine@github.com".to_string(),
).unwrap();
let qr_code = totp.get_qr_base64()?;
let qr_code = totp.to_qr_base64()?;
println!("{}", qr_code);
}
```
Expand All @@ -128,16 +128,16 @@ features = ["serde_support"]
Add it to your `Cargo.toml`:
```toml
[dependencies.totp-rs]
version = "^5.0"
version = "^5.6"
features = ["otpauth"]
```
You can then do something like:
```Rust
use totp_rs::TOTP;
use totp_rs::Totp;

fn main() {
let otpauth = "otpauth://totp/GitHub:constantoine@github.com?secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ&issuer=GitHub";
let totp = TOTP::from_url(otpauth).unwrap();
let totp = Totp::from_url(otpauth).unwrap();
println!("{}", totp.generate_current().unwrap());
}
```
Expand All @@ -147,15 +147,15 @@ fn main() {
Add it to your `Cargo.toml`:
```toml
[dependencies.totp-rs]
version = "^5.3"
version = "^5.6"
features = ["gen_secret"]
```
You can then do something like:
```Rust
use totp_rs::{Algorithm, TOTP, Secret};
use totp_rs::{Algorithm, Totp, Secret};

fn main() {
let totp = TOTP::new(
let totp = Totp::new(
Algorithm::SHA1,
6,
1,
Expand All @@ -164,16 +164,16 @@ fn main() {
Some("Github".to_string()),
"constantoine@github.com".to_string(),
).unwrap();
let qr_code = totp.get_qr_base64()?;
let qr_code = totp.to_qr_base64()?;
println!("{}", qr_code);
}
```
Which is equivalent to
```Rust
use totp_rs::{Algorithm, TOTP, Secret};
use totp_rs::{Algorithm, Totp, Secret};

fn main() {
let totp = TOTP::new(
let totp = Totp::new(
Algorithm::SHA1,
6,
1,
Expand All @@ -182,7 +182,7 @@ fn main() {
Some("Github".to_string()),
"constantoine@github.com".to_string(),
).unwrap();
let qr_code = totp.get_qr_base64()?;
let qr_code = totp.to_qr_base64()?;
println!("{}", qr_code);
}
```
Expand All @@ -191,7 +191,7 @@ fn main() {
---
You can do something like this
```Rust
use totp_rs::{Algorithm, TOTP, Secret, Rfc6238};
use totp_rs::{Algorithm, Totp, Secret, Rfc6238};

fn main () {
let mut rfc = Rfc6238::with_defaults(
Expand All @@ -202,37 +202,37 @@ fn main () {
// optional, set digits
rfc.digits(8).unwrap();

// create a TOTP from rfc
let totp = TOTP::from_rfc6238(rfc).unwrap();
// create a Totp from rfc
let totp = Totp::from_rfc6238(rfc).unwrap();
let code = totp.generate_current().unwrap();
println!("code: {}", code);
}
```
With `gen_secret` feature, you can go even further and have all values by default and a secure secret.

Note: With `otpauth` feature, `TOTP.issuer` will be `None`, and `TOTP.account_name` will be `""`. Be sure to set those fields before generating an URL/QRCode
Note: With `otpauth` feature, `Totp.issuer` will be `None`, and `Totp.account_name` will be `""`. Be sure to set those fields before generating an URL/QRCode
```Rust
fn main() {
let totp = TOTP::default();
let totp = Totp::default();
let code = totp.generate_current().unwrap();
println!("code: {}", code);
}
```

### New TOTP from steam secret
### New Totp from steam secret
---
Add it to your `Cargo.toml`:
```toml
[dependencies.totp-rs]
version = "^5.3"
version = "^5.6"
features = ["steam"]
```
You can then do something like:
```Rust
use totp_rs::{TOTP, Secret};
use totp_rs::{Totp, Secret};

fn main() {
let totp = TOTP::new_steam(
let totp = Totp::new_steam(
Secret::Encoded("KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ".to_string()).to_bytes().unwrap(),
).unwrap();
let code = totp.generate_current().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions examples/gen_secret.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#[cfg(all(feature = "gen_secret", feature = "otpauth"))]
use totp_rs::{Algorithm, Secret, TOTP};
use totp_rs::{Algorithm, Secret, Totp};

#[cfg(all(feature = "gen_secret", feature = "otpauth"))]
fn main() {
let secret = Secret::generate_secret();

let totp = TOTP::new(
let totp = Totp::new(
Algorithm::SHA1,
6,
1,
Expand Down
6 changes: 3 additions & 3 deletions examples/rfc-6238.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use totp_rs::{Rfc6238, TOTP};
use totp_rs::{Rfc6238, Totp};

#[cfg(feature = "otpauth")]
fn main() {
Expand All @@ -10,7 +10,7 @@ fn main() {
rfc.account_name("user-account".to_string());

// create a TOTP from rfc
let totp = TOTP::from_rfc6238(rfc).unwrap();
let totp = Totp::from_rfc6238(rfc).unwrap();
let code = totp.generate_current().unwrap();
println!("code: {}", code);
}
Expand All @@ -23,7 +23,7 @@ fn main() {
rfc.digits(8).unwrap();

// create a TOTP from rfc
let totp = TOTP::from_rfc6238(rfc).unwrap();
let totp = Totp::from_rfc6238(rfc).unwrap();
let code = totp.generate_current().unwrap();
println!("code: {}", code);
}
10 changes: 5 additions & 5 deletions examples/secret.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use totp_rs::{Algorithm, Secret, TOTP};
use totp_rs::{Algorithm, Secret, Totp};

#[cfg(feature = "otpauth")]
fn main() {
// create TOTP from base32 secret
let secret_b32 = Secret::Encoded(String::from("OBWGC2LOFVZXI4TJNZTS243FMNZGK5BNGEZDG"));
let totp_b32 = TOTP::new(
let totp_b32 = Totp::new(
Algorithm::SHA1,
6,
1,
Expand All @@ -31,7 +31,7 @@ fn main() {
0x63, 0x72, 0x65, 0x74, 0x2d, 0x31, 0x32, 0x33,
];
let secret_raw = Secret::Raw(secret.to_vec());
let totp_raw = TOTP::new(
let totp_raw = Totp::new(
Algorithm::SHA1,
6,
1,
Expand All @@ -53,7 +53,7 @@ fn main() {
fn main() {
// create TOTP from base32 secret
let secret_b32 = Secret::Encoded(String::from("OBWGC2LOFVZXI4TJNZTS243FMNZGK5BNGEZDG"));
let totp_b32 = TOTP::new(Algorithm::SHA1, 6, 1, 30, secret_b32.to_bytes().unwrap()).unwrap();
let totp_b32 = Totp::new(Algorithm::SHA1, 6, 1, 30, secret_b32.to_bytes().unwrap()).unwrap();

println!(
"base32 {} ; raw {}",
Expand All @@ -71,7 +71,7 @@ fn main() {
0x63, 0x72, 0x65, 0x74, 0x2d, 0x31, 0x32, 0x33,
];
let secret_raw = Secret::Raw(secret.to_vec());
let totp_raw = TOTP::new(Algorithm::SHA1, 6, 1, 30, secret_raw.to_bytes().unwrap()).unwrap();
let totp_raw = Totp::new(Algorithm::SHA1, 6, 1, 30, secret_raw.to_bytes().unwrap()).unwrap();

println!("raw {} ; base32 {}", secret_raw, secret_raw.to_encoded());
println!(
Expand Down
6 changes: 3 additions & 3 deletions examples/steam.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#[cfg(feature = "steam")]
use totp_rs::{Secret, TOTP};
use totp_rs::{Secret, Totp};

#[cfg(feature = "steam")]
#[cfg(feature = "otpauth")]
fn main() {
// create TOTP from base32 secret
let secret_b32 = Secret::Encoded(String::from("OBWGC2LOFVZXI4TJNZTS243FMNZGK5BNGEZDG"));
let totp_b32 = TOTP::new_steam(secret_b32.to_bytes().unwrap(), "user-account".to_string());
let totp_b32 = Totp::new_steam(secret_b32.to_bytes().unwrap(), "user-account".to_string());

println!(
"base32 {} ; raw {}",
Expand All @@ -24,7 +24,7 @@ fn main() {
fn main() {
// create TOTP from base32 secret
let secret_b32 = Secret::Encoded(String::from("OBWGC2LOFVZXI4TJNZTS243FMNZGK5BNGEZDG"));
let totp_b32 = TOTP::new_steam(secret_b32.to_bytes().unwrap());
let totp_b32 = Totp::new_steam(secret_b32.to_bytes().unwrap());

println!(
"base32 {} ; raw {}",
Expand Down
6 changes: 3 additions & 3 deletions examples/ttl.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use totp_rs::{Algorithm, TOTP};
use totp_rs::{Algorithm, Totp};

#[cfg(not(feature = "otpauth"))]
fn main() {
let totp = TOTP::new(Algorithm::SHA1, 6, 1, 30, "my-secret".as_bytes().to_vec()).unwrap();
let totp = Totp::new(Algorithm::SHA1, 6, 1, 30, "my-secret".as_bytes().to_vec()).unwrap();

loop {
println!(
Expand All @@ -17,7 +17,7 @@ fn main() {

#[cfg(feature = "otpauth")]
fn main() {
let totp = TOTP::new(
let totp = Totp::new(
Algorithm::SHA1,
6,
1,
Expand Down
Loading
Loading