Skip to content

Commit 8a1f4f6

Browse files
committed
Add ArtifactRestorer trait
1 parent 005ec5e commit 8a1f4f6

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
use std::marker::PhantomData;
2+
3+
use async_trait::async_trait;
4+
use mithril_common::{
5+
entities::Certificate,
6+
signable_builder::{DummyBeacon, DummySignable},
7+
StdResult,
8+
};
9+
use serde::{Deserialize, Serialize};
10+
11+
use crate::artifact_builder::{Artifact, ArtifactRestorer};
12+
13+
/// Dummy artifact
14+
#[derive(Serialize, Deserialize, PartialEq, Debug)]
15+
pub struct DummyArtifact<'a> {
16+
message: String,
17+
beacon: DummyBeacon,
18+
phantom: PhantomData<&'a DummyBeacon>,
19+
}
20+
21+
impl<'a> DummyArtifact<'a> {
22+
/// Dummy artifact factory
23+
pub fn new(message: String, beacon: DummyBeacon) -> Self {
24+
Self {
25+
message,
26+
beacon,
27+
phantom: PhantomData,
28+
}
29+
}
30+
}
31+
32+
impl<'a> Artifact<'a> for DummyArtifact<'a> {}
33+
34+
/// A [DummyArtifact] restorer
35+
pub struct DummyArtifactRestorer {}
36+
37+
impl DummyArtifactRestorer {
38+
/// Dummy artifact builder restorer
39+
pub fn new() -> Self {
40+
Self {}
41+
}
42+
}
43+
44+
impl Default for DummyArtifactRestorer {
45+
fn default() -> Self {
46+
Self::new()
47+
}
48+
}
49+
50+
#[async_trait]
51+
impl<'a> ArtifactRestorer<'a, DummyBeacon, DummyArtifact<'a>> for DummyArtifactRestorer {
52+
async fn compute_artifact(
53+
&'a self,
54+
beacon: DummyBeacon,
55+
certificate: &Certificate,
56+
) -> StdResult<DummyArtifact> {
57+
Ok(DummyArtifact::new(
58+
format!("certificate id is {}", certificate.hash),
59+
beacon,
60+
))
61+
}
62+
63+
/// Compute a signable from an artifact
64+
async fn compute_signable(&self, artifact: DummyArtifact) -> StdResult<DummySignable> {
65+
Ok(DummySignable::new(artifact.message, artifact.beacon))
66+
}
67+
68+
/// Restore an artifact
69+
async fn restore_artifact(&'a self, artifact: DummyArtifact) -> StdResult<()> {
70+
Ok(())
71+
}
72+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use async_trait::async_trait;
2+
use mithril_common::{entities::Certificate, signable_builder::Beacon, StdResult};
3+
use serde::{Deserialize, Serialize};
4+
use std::fmt::Debug;
5+
6+
/// ArtifactRestorer is trait for restoring an artifact
7+
#[async_trait]
8+
trait ArtifactRestorer<'a, V, W>
9+
where
10+
V: Signable,
11+
W: Artifact<'a>,
12+
{
13+
/// Compute a signable from an artifact
14+
async fn compute_signable(&self, artifact: W) -> StdResult<V>;
15+
16+
/// Restore an artifact
17+
async fn restore_artifact(&'a self, artifact: W) -> StdResult<()>;
18+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//! The module used for building artifact
2+
3+
mod artifact_builder_service;
4+
mod dummy_artifact;
5+
mod interface;
6+
7+
pub use artifact_builder_service::*;
8+
pub use dummy_artifact::*;
9+
pub use interface::*;

0 commit comments

Comments
 (0)