ssi_dids_core/resolution/
static_resolver.rs1use std::collections::HashMap;
2
3use crate::{DIDBuf, DIDResolver, DID};
4
5use super::{Error, Options, Output};
6
7#[derive(Debug, Default, Clone)]
9pub struct StaticDIDResolver {
10 map: HashMap<DIDBuf, Output<Vec<u8>>>,
11}
12
13impl StaticDIDResolver {
14 pub fn new() -> Self {
15 Self::default()
16 }
17
18 pub fn len(&self) -> usize {
19 self.map.len()
20 }
21
22 pub fn is_empty(&self) -> bool {
23 self.map.is_empty()
24 }
25
26 pub fn insert(&mut self, did: DIDBuf, value: Output<Vec<u8>>) -> Option<Output<Vec<u8>>> {
27 self.map.insert(did, value)
28 }
29}
30
31impl DIDResolver for StaticDIDResolver {
32 async fn resolve_representation<'a>(
33 &'a self,
34 did: &'a DID,
35 _options: Options,
36 ) -> Result<Output<Vec<u8>>, Error> {
37 match self.map.get(did) {
38 Some(data) => Ok(data.clone()),
39 None => Err(Error::NotFound),
40 }
41 }
42}