You've already forked authentication-service
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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user