23 lines
635 B
Rust
23 lines
635 B
Rust
|
pub fn validate_public_key(public_key: &str) -> Result<(), String> {
|
||
|
if !public_key.starts_with('@') {
|
||
|
return Err("Expected '@' sigil as first character".to_string());
|
||
|
}
|
||
|
|
||
|
let dot_index = match public_key.rfind('.') {
|
||
|
Some(index) => index,
|
||
|
None => return Err("could not find '.' character".to_string()),
|
||
|
};
|
||
|
|
||
|
if !&public_key.ends_with(".ed25519") {
|
||
|
return Err("hashing algorithm must be ed25519".to_string());
|
||
|
}
|
||
|
|
||
|
let base64_str = &public_key[1..dot_index];
|
||
|
|
||
|
if base64_str.len() != 44 {
|
||
|
return Err("base64 data length is incorrect".to_string());
|
||
|
}
|
||
|
|
||
|
Ok(())
|
||
|
}
|