use nuts_container::{Container, Error, Migration, Service, ServiceFactory};
use nuts_memory::MemoryBackend;
use std::path::PathBuf;
use thiserror::Error;
#[allow(dead_code)]
const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR");
#[allow(dead_code)]
pub fn fixture_password() -> Result<Vec<u8>, String> {
Ok(b"sample".to_vec())
}
#[allow(dead_code)]
pub fn fixture_path(dir: &str, name: &str) -> PathBuf {
[MANIFEST_DIR, "data", dir, name].iter().collect()
}
#[derive(Debug, Error)]
#[error(transparent)]
pub struct SampleError(#[from] pub Error<MemoryBackend>);
pub struct SampleMigration;
impl Migration for SampleMigration {
fn migrate_rev0(&self, _userdata: &[u8]) -> Result<(u32, Vec<u8>), String> {
Ok((666, vec![0x00, 0x00, 0x12, 0x67]))
}
}
#[derive(Debug)]
pub struct SampleService(Container<MemoryBackend>);
impl SampleService {
#[allow(dead_code)]
pub fn into_container(self) -> Container<MemoryBackend> {
self.0
}
}
impl Service<MemoryBackend> for SampleService {
type Migration = SampleMigration;
fn sid() -> u32 {
666
}
fn need_top_id() -> bool {
false
}
fn migration() -> SampleMigration {
SampleMigration
}
}
impl ServiceFactory<MemoryBackend> for SampleService {
type Service = Self;
type Err = SampleError;
fn create(container: Container<MemoryBackend>) -> Result<Self::Service, Self::Err> {
Ok(SampleService(container))
}
fn open(container: Container<MemoryBackend>) -> Result<Self::Service, Self::Err> {
Ok(SampleService(container))
}
}