Skip to content

Commit

Permalink
cargo format
Browse files Browse the repository at this point in the history
  • Loading branch information
aviramha committed Aug 9, 2021
1 parent 2c84329 commit b2e3cf2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/exc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use pyo3::create_exception;

create_exception!(rfernet, DecryptionError, pyo3::exceptions::PyTypeError);
19 changes: 12 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use pyo3::exceptions;
use pyo3::prelude::*;
use pyo3::types::PyBytes;


mod exc;

#[pyclass]
Expand All @@ -25,7 +24,7 @@ impl Fernet {
None => Err(exceptions::PyValueError::new_err("Invalid arguments")),
Some(fernet_obj) => Ok(Fernet {
fernet_: fernet_obj,
})
}),
}
}

Expand All @@ -40,14 +39,18 @@ impl Fernet {

fn decrypt(&self, py: Python, token: &str) -> PyResult<PyObject> {
match self.fernet_.decrypt(token) {
Err(_err) => Err(exc::DecryptionError::new_err("Decryption failed, token or key invalid.")),
Err(_err) => Err(exc::DecryptionError::new_err(
"Decryption failed, token or key invalid.",
)),
Ok(data) => Ok(PyBytes::new(py, &data).into()),
}
}

fn decrypt_with_ttl(&self, py: Python, token: &str, ttl_secs: u64) -> PyResult<PyObject> {
match self.fernet_.decrypt_with_ttl(token, ttl_secs) {
Err(_err) => Err(exc::DecryptionError::new_err("Decryption failed, token or key invalid.")),
Err(_err) => Err(exc::DecryptionError::new_err(
"Decryption failed, token or key invalid.",
)),
Ok(data) => Ok(PyBytes::new(py, &data).into()),
}
}
Expand All @@ -61,8 +64,8 @@ impl MultiFernet {
match fernets {
None => Err(exceptions::PyValueError::new_err("Invalid arguments")),
Some(f) => Ok(MultiFernet {
fernet_: fernet::MultiFernet::new(f)
})
fernet_: fernet::MultiFernet::new(f),
}),
}
}

Expand All @@ -72,7 +75,9 @@ impl MultiFernet {

fn decrypt(&self, py: Python, token: &str) -> PyResult<PyObject> {
match self.fernet_.decrypt(token) {
Err(_err) => Err(exc::DecryptionError::new_err("Decryption failed, token or key invalid.")),
Err(_err) => Err(exc::DecryptionError::new_err(
"Decryption failed, token or key invalid.",
)),
Ok(data) => Ok(PyBytes::new(py, &data).into()),
}
}
Expand Down

0 comments on commit b2e3cf2

Please sign in to comment.