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

Add integrity variants for each factor source #308

Merged
merged 1 commit into from
Dec 18, 2024
Merged
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
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()
)
}
}
Loading