Amanda Graven fdc15123b0
Reorganize encyption related code
Some types used for encryption related tasks need to be used across more
internal crates than expected, so a few have been moved and renamed for
clarity.

* Rename the key_algorithms module in ruma-identifiers-validation to crypto_algorithms
* Move ruma_events::Algorithm to ruma-identifiers-validation and rename it EventEncryptionAlgorithm
* Move DeviceKeys from ruma-client-api to ruma-common
2020-08-10 18:38:53 +02:00

14 lines
436 B
Rust

use std::{num::NonZeroU8, str::FromStr};
use crate::{crypto_algorithms::DeviceKeyAlgorithm, Error};
pub fn validate(s: &str) -> Result<NonZeroU8, Error> {
let colon_idx = NonZeroU8::new(s.find(':').ok_or(Error::MissingDeviceKeyDelimiter)? as u8)
.ok_or(Error::UnknownKeyAlgorithm)?;
DeviceKeyAlgorithm::from_str(&s[0..colon_idx.get() as usize])
.map_err(|_| Error::UnknownKeyAlgorithm)?;
Ok(colon_idx)
}