1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-11-20 12:02:22 +03:00

Allow fetching more nodes by their IDs

This commit is contained in:
Quentin Gliech
2022-11-16 17:21:40 +01:00
parent 10815d8101
commit 78778648ca
18 changed files with 232 additions and 67 deletions

View File

@@ -40,6 +40,7 @@ pub enum InvalidID {
InvalidFormat,
InvalidUlid(#[from] ulid::DecodeError),
UnknownPrefix,
TypeMismatch { got: NodeType, expected: NodeType },
}
impl NodeType {
@@ -90,6 +91,19 @@ impl NodeType {
pub fn from_id(id: &ID) -> Result<(Self, Ulid), InvalidID> {
Self::deserialize(&id.0)
}
pub fn extract_ulid(self, id: &ID) -> Result<Ulid, InvalidID> {
let (node_type, ulid) = Self::deserialize(&id.0)?;
if node_type == self {
Ok(ulid)
} else {
Err(InvalidID::TypeMismatch {
got: node_type,
expected: self,
})
}
}
}
/// An object with an ID.