Remove get_cred_trust_level(), use scalar_u32() instead

This commit is contained in:
Vecna 2023-11-07 15:04:50 -05:00
parent f3fcec771e
commit f825cce0b9
2 changed files with 4 additions and 22 deletions

View File

@ -46,24 +46,6 @@ pub fn get_invitation_pub(lox_auth_pubkeys: &Vec<IssuerPubKey>) -> &IssuerPubKey
&lox_auth_pubkeys[4]
}
// Helper function to get credential trust level as i8
// (Note that this value should only be 0-4)
pub fn get_cred_trust_level(cred: &lox_library::cred::Lox) -> i8 {
let trust_levels: [Scalar; 5] = [
Scalar::zero(),
Scalar::one(),
Scalar::from(2u64),
Scalar::from(3u64),
Scalar::from(4u8),
];
for i in 0..trust_levels.len() {
if cred.trust_level == trust_levels[i] {
return i.try_into().unwrap();
}
}
-1
}
// Helper function to check if credential is eligible for
// promotion from level 0 to 1
pub async fn eligible_for_trust_promotion(
@ -74,7 +56,7 @@ pub async fn eligible_for_trust_promotion(
Some(v) => v,
None => return false,
};
get_cred_trust_level(cred) == 0
scalar_u32(&cred.trust_level).unwrap() == 0
&& level_since + trust_promotion::UNTRUSTED_INTERVAL <= get_today(net).await
}
@ -85,7 +67,7 @@ pub async fn eligible_for_level_up(net: &dyn Networking, cred: &lox_library::cre
Some(v) => v,
None => return false,
};
let trust_level: usize = get_cred_trust_level(cred).try_into().unwrap();
let trust_level: usize = scalar_u32(&cred.trust_level).unwrap().try_into().unwrap();
trust_level > 0
&& level_since + lox_library::proto::level_up::LEVEL_INTERVAL[trust_level]
<= get_today(net).await

View File

@ -145,7 +145,7 @@ async fn main() {
};
let (lox_cred, bucket) = if matches.opt_present("L") {
let old_level = get_cred_trust_level(&lox_cred);
let old_level = scalar_u32(&lox_cred.trust_level).unwrap();
// If trust level is 0, do trust promotion, otherwise level up.
let (cred, bucket) = if old_level == 0 {
@ -183,7 +183,7 @@ async fn main() {
};
save_object(&cred, &lox_cred_filename);
save_object(&bucket, &bucket_filename);
let new_level = get_cred_trust_level(&cred);
let new_level = scalar_u32(&cred.trust_level).unwrap();
if new_level > old_level {
println!("Old level: {}\nNew level: {}", old_level, new_level);
} else if new_level == old_level {