Skip to content

Commit

Permalink
Add integrity variants for each factor source (#308)
Browse files Browse the repository at this point in the history
add integrity variants for each factor source
  • Loading branch information
matiasbzurovski authored Dec 18, 2024
1 parent 6a4b46e commit af654a9
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/sargon-uniffi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "sargon-uniffi"
# Don't forget to update version in crates/sargon/Cargo.toml
version = "1.1.89"
version = "1.1.90"
edition = "2021"
build = "build.rs"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ pub enum FactorSourceIntegrity {
Device(DeviceFactorSourceIntegrity),

Ledger(LedgerHardwareWalletFactorSource),

OffDeviceMnemonic(OffDeviceMnemonicFactorSource),

ArculusCard(ArculusCardFactorSource),

Password(PasswordFactorSource),
}
2 changes: 1 addition & 1 deletion crates/sargon/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "sargon"
# Don't forget to update version in crates/sargon-uniffi/Cargo.toml
version = "1.1.89"
version = "1.1.90"
edition = "2021"
build = "build.rs"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,43 @@ pub enum FactorSourceIntegrity {
Device(DeviceFactorSourceIntegrity),

Ledger(LedgerHardwareWalletFactorSource),

OffDeviceMnemonic(OffDeviceMnemonicFactorSource),

ArculusCard(ArculusCardFactorSource),

Password(PasswordFactorSource),
}

impl HasSampleValues for FactorSourceIntegrity {
fn sample() -> Self {
Self::Device(DeviceFactorSourceIntegrity::sample())
Self::sample_device()
}

fn sample_other() -> Self {
Self::Ledger(LedgerHardwareWalletFactorSource::sample())
Self::sample_ledger()
}
}

impl FactorSourceIntegrity {
pub fn sample_device() -> Self {
DeviceFactorSourceIntegrity::sample().into()
}

pub fn sample_ledger() -> Self {
LedgerHardwareWalletFactorSource::sample().into()
}

pub fn sample_off_device_mnemonic() -> Self {
OffDeviceMnemonicFactorSource::sample().into()
}

pub fn sample_arculus_card() -> Self {
ArculusCardFactorSource::sample().into()
}

pub fn sample_password() -> Self {
PasswordFactorSource::sample().into()
}
}

Expand All @@ -30,6 +58,24 @@ impl From<LedgerHardwareWalletFactorSource> for FactorSourceIntegrity {
}
}

impl From<OffDeviceMnemonicFactorSource> for FactorSourceIntegrity {
fn from(value: OffDeviceMnemonicFactorSource) -> Self {
Self::OffDeviceMnemonic(value)
}
}

impl From<ArculusCardFactorSource> for FactorSourceIntegrity {
fn from(value: ArculusCardFactorSource) -> Self {
Self::ArculusCard(value)
}
}

impl From<PasswordFactorSource> for FactorSourceIntegrity {
fn from(value: PasswordFactorSource) -> Self {
Self::Password(value)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -60,4 +106,28 @@ mod tests {
LedgerHardwareWalletFactorSource::sample().into()
)
}

#[test]
fn from_off_device_mnemonic() {
assert_eq!(
SUT::sample_off_device_mnemonic(),
OffDeviceMnemonicFactorSource::sample().into()
)
}

#[test]
fn from_arculus_card() {
assert_eq!(
SUT::sample_arculus_card(),
ArculusCardFactorSource::sample().into()
)
}

#[test]
fn from_password() {
assert_eq!(
SUT::sample_password(),
PasswordFactorSource::sample().into()
)
}
}

0 comments on commit af654a9

Please sign in to comment.