fn split_hash(hash: &str) -> BcryptResult<HashParts> {
    let mut parts = HashParts {
        cost: 0,
        salt: "".to_string(),
        hash: "".to_string(),
    };

    // Should be [prefix, cost, hash]
    let raw_parts: Vec<_> = hash.split('$').filter(|s| !s.is_empty()).collect();

    if raw_parts.len() != 3 {
        return Err(BcryptError::InvalidHash(hash.to_string()));
    }

    if raw_parts[0] != "2y" && raw_parts[0] != "2b" && raw_parts[0] != "2a" {
        return Err(BcryptError::InvalidPrefix(raw_parts[0].to_string()));
    }

    if let Ok(c) = raw_parts[1].parse::<u32>() {
        parts.cost = c;
    } else {
        return Err(BcryptError::InvalidCost(raw_parts[1].to_string()));
    }

    if raw_parts[2].len() == 53 {
        parts.salt = raw_parts[2][..22].chars().collect();
        parts.hash = raw_parts[2][22..].chars().collect();
    } else {
        return Err(BcryptError::InvalidHash(hash.to_string()));
    }

    Ok(parts)
}
/// Takes a full hash and split it into 3 parts:
/// cost, salt and hash
Takes a full hash and split it into 3 parts:
cost, salt and hash
Takes a full hash and split it into 3 parts : cost salt and hash
fn split_hash(hash: &str) -> BcryptResult<HashParts> {
    let mut parts = HashParts {
        cost: 0,
        salt: "".to_string(),
        hash: "".to_string(),
    };
    // Should be [prefix, cost, hash]
    let raw_parts: Vec<_> = hash.split('$').filter(|s| !s.is_empty()).collect();
    if raw_parts.len() != 3 {
        return Err(BcryptError::InvalidHash(hash.to_string()));
    }
    if raw_parts[0] != "2y" && raw_parts[0] != "2b" && raw_parts[0] != "2a" {
        return Err(BcryptError::InvalidPrefix(raw_parts[0].to_string()));
    }
    if let Ok(c) = raw_parts[1].parse::<u32>() {
        parts.cost = c;
    } else {
        return Err(BcryptError::InvalidCost(raw_parts[1].to_string()));
    }
    if raw_parts[2].len() == 53 {
        parts.salt = raw_parts[2][..22].chars().collect();
        parts.hash = raw_parts[2][22..].chars().collect();
    } else {
        return Err(BcryptError::InvalidHash(hash.to_string()));
    }
    Ok(parts)
}
fn split_hash ( hash : & str ) -> BcryptResult < HashParts > { let mut parts = HashParts { cost : 0 , salt : " " . to_string ( ) , hash : " " . to_string ( ) , } ; // Should be [prefix, cost, hash] let raw_parts : Vec < _ > = hash . split ( '$' ) . filter ( | s | ! s . is_empty ( ) ) . collect ( ) ; if raw_parts . len ( ) != 3 { return Err ( BcryptError :: InvalidHash ( hash . to_string ( ) ) ) ; } if raw_parts [ 0 ] != " " && raw_parts [ 0 ] != " " && raw_parts [ 0 ] != " " { return Err ( BcryptError :: InvalidPrefix ( raw_parts [ 0 ] . to_string ( ) ) ) ; } if let Ok ( c ) = raw_parts [ 1 ] . parse :: < u32 > ( ) { parts . cost = c ; } else { return Err ( BcryptError :: InvalidCost ( raw_parts [ 1 ] . to_string ( ) ) ) ; } if raw_parts [ 2 ] . len ( ) == 53 { parts . salt = raw_parts [ 2 ] [ .. 22 ] . chars ( ) . collect ( ) ; parts . hash = raw_parts [ 2 ] [ 22 .. ] . chars ( ) . collect ( ) ; } else { return Err ( BcryptError :: InvalidHash ( hash . to_string ( ) ) ) ; } Ok ( parts ) }
Takes a full hash and split it into 3 parts:
cost, salt and hash
Takes a full hash and split it into 3 parts : cost salt and hash
hash
&str