AskryptFile

Struct AskryptFile 

Source
pub struct AskryptFile {
    pub version: String,
    pub question0: String,
    pub params: KdfParams,
    pub qs: String,
    pub master: String,
    pub data: String,
}
Expand description

Main Askrypt file structure in JSON format

Fields§

§version: String§question0: String§params: KdfParams§qs: String§master: String§data: String

Implementations§

Source§

impl AskryptFile

Source

pub fn create( questions: Vec<String>, answers: Vec<String>, secret_data: Vec<SecretEntry>, iterations0: Option<u32>, iterations1: Option<u32>, ) -> Result<Self, Box<dyn Error>>

Create a new AskryptFile from questions, answers, and secret data

§Arguments
  • questions - A vector of at least 2 questions
  • answers - A vector of normalized answers (must be pre-normalized, same length as questions)
  • secret_data - A vector of SecretEntry items to encrypt
  • iterations0 - Optional iterations for first KDF (default: 600000)
  • iterations1 - Optional iterations for second KDF (default: 600000)
§Returns

Returns a Result containing the AskryptFile or an error

§Example
use askrypt::{AskryptFile, SecretEntry};

let questions = vec![
    "What is your mother's maiden name?".to_string(),
    "What was your first pet's name?".to_string(),
    "What city were you born in?".to_string(),
];
let answers = vec![
    "Smith".to_string(),
    "Fluffy".to_string(),
    "New York".to_string(),
];
let data = vec![
    SecretEntry {
        name: "example".to_string(),
        secret: "password123".to_string(),
        url: "https://example.com".to_string(),
        notes: "My account".to_string(),
        entry_type: "password".to_string(),
        tags: vec![],
        created: "2024-01-01T00:00:00Z".to_string(),
        modified: "2024-01-01T00:00:00Z".to_string(),
    }
];

let askrypt_file = AskryptFile::create(questions, answers, data, Some(6000), Some(6000)).unwrap();
Source

pub fn decrypt( &self, questions_data: QuestionsData, answers: Vec<String>, ) -> Result<Vec<SecretEntry>, Box<dyn Error>>

Decrypt an AskryptFile and retrieve the secret data using the answers

§Arguments
  • answers - A vector of normalized answers (must be pre-normalized)
§Returns

Returns a Result containing the decrypted Vec or an error

§Example
use askrypt::{AskryptFile, SecretEntry };

let questions = vec![
    "What is your mother's maiden name?".to_string(),
    "What was your first pet's name?".to_string(),
    "What city were you born in?".to_string(),
];
let answers = vec![
    "Smith".to_string(),
    "Fluffy".to_string(),
    "New York".to_string(),
];
let data = vec![
    SecretEntry {
        name: "example".to_string(),
        secret: "password123".to_string(),
        url: "https://example.com".to_string(),
        notes: "My account".to_string(),
        entry_type: "password".to_string(),
        tags: vec![],
        created: "2024-01-01T00:00:00Z".to_string(),
        modified: "2024-01-01T00:00:00Z".to_string(),
    }
];

let askrypt_file = AskryptFile::create(questions, answers.clone(), data.clone(), Some(6000), Some(6000)).unwrap();
let questions_data = askrypt_file.get_questions_data(answers[0].clone()).unwrap();
let decrypted_data = askrypt_file.decrypt(questions_data, answers[1..].into()).unwrap();
assert_eq!(decrypted_data, data);
Source

pub fn get_questions_data( &self, first_answer: String, ) -> Result<QuestionsData, Box<dyn Error>>

Get QuestionsData by first normalized answer from the AskryptFile

§Arguments
  • first_answer - The normalized first answer to decrypt the remaining questions
§Returns

Returns a Result containing QuestionsData or an error

Source

pub fn save_to_file<P: AsRef<Path>>( &self, path: P, ) -> Result<(), Box<dyn Error>>

Save the AskryptFile to a JSON file

§Arguments
  • path - The file path where the JSON file should be saved
§Returns

Returns a Result indicating success or an error

Source

pub fn load_from_file<P: AsRef<Path>>(path: P) -> Result<Self, Box<dyn Error>>

Load an AskryptFile from a JSON file

§Arguments
  • path - The file path to load the JSON file from
§Returns

Returns a Result containing the loaded AskryptFile or an error

Trait Implementations§

Source§

impl Clone for AskryptFile

Source§

fn clone(&self) -> AskryptFile

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AskryptFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for AskryptFile

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for AskryptFile

Source§

fn eq(&self, other: &AskryptFile) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for AskryptFile

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for AskryptFile

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,