aboutsummaryrefslogtreecommitdiff
path: root/rust/src/implementation/passwordmaker/helperthread/profile_to_domain.rs
blob: 152ba8f00a8911a664733996c9f85e529f753ab7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/// This whole module may look dumb, but that might change, once the public interface of passwordmaker_rs starts to deviate from the saved data.

use passwordmaker_rs::{HashAlgorithm,UseLeetWhenGenerating,LeetLevel};

pub(super) fn convert_hash_algorithm(stored_algo : &crate::implementation::profiles::HashAlgorithm) -> HashAlgorithm {
    use crate::implementation::profiles::HashAlgorithm as PHashAlgorithm;
    match stored_algo {
        PHashAlgorithm::Md4 => HashAlgorithm::Md4,
        PHashAlgorithm::HmacMd4 => HashAlgorithm::HmacMd4,
        PHashAlgorithm::Md5 => HashAlgorithm::Md5,
        PHashAlgorithm::Md5Version06 => HashAlgorithm::Md5Version06,
        PHashAlgorithm::HmacMd5 => HashAlgorithm::HmacMd5,
        PHashAlgorithm::HmacMd5Version06 => HashAlgorithm::HmacMd5Version06,
        PHashAlgorithm::Sha1 => HashAlgorithm::Sha1,
        PHashAlgorithm::HmacSha1 => HashAlgorithm::HmacSha1,
        PHashAlgorithm::Sha256 => HashAlgorithm::Sha256,
        PHashAlgorithm::HmacSha256 => HashAlgorithm::HmacSha256,
        PHashAlgorithm::Ripemd160 => HashAlgorithm::Ripemd160,
        PHashAlgorithm::HmacRipemd160 => HashAlgorithm::HmacRipemd160,
    }
}

pub(super) fn convert_leet(stored_leet : &crate::implementation::profiles::UseLeetWhenGenerating) -> UseLeetWhenGenerating {
    use crate::implementation::profiles::UseLeetWhenGenerating as PUseLeetWhenGenerating;
    match stored_leet {
        PUseLeetWhenGenerating::NotAtAll => UseLeetWhenGenerating::NotAtAll,
        PUseLeetWhenGenerating::Before { level } => UseLeetWhenGenerating::Before { level: convert_leet_level(level) },
        PUseLeetWhenGenerating::After { level } => UseLeetWhenGenerating::After { level: convert_leet_level(level) },
        PUseLeetWhenGenerating::BeforeAndAfter { level } => UseLeetWhenGenerating::BeforeAndAfter { level: convert_leet_level(level) },
    }
}

fn convert_leet_level(stored_level : &crate::implementation::profiles::LeetLevel) -> LeetLevel {
    use crate::implementation::profiles::LeetLevel as PLeetLevel;
    match stored_level {
        PLeetLevel::One => LeetLevel::One,
        PLeetLevel::Two => LeetLevel::Two,
        PLeetLevel::Three => LeetLevel::Three,
        PLeetLevel::Four => LeetLevel::Four,
        PLeetLevel::Five => LeetLevel::Five,
        PLeetLevel::Six => LeetLevel::Six,
        PLeetLevel::Seven => LeetLevel::Seven,
        PLeetLevel::Eight => LeetLevel::Eight,
        PLeetLevel::Nine => LeetLevel::Nine,
    }
}