ssi_vc/v1/data_model/
presentation.rs1use iref::Uri;
2use ssi_claims_core::VerifiableClaims;
3
4use crate::v1::syntax::VERIFIABLE_PRESENTATION_TYPE;
5
6use super::Credential;
7
8pub trait Presentation {
10 type Credential: Credential;
12
13 fn id(&self) -> Option<&Uri> {
15 None
16 }
17
18 fn additional_types(&self) -> &[String] {
20 &[]
21 }
22
23 fn types(&self) -> PresentationTypes {
24 PresentationTypes {
25 base_type: true,
26 additional_types: self.additional_types().iter(),
27 }
28 }
29
30 fn verifiable_credentials(&self) -> &[Self::Credential] {
31 &[]
32 }
33
34 fn holder(&self) -> Option<&Uri> {
35 None
36 }
37}
38
39pub trait VerifiablePresentation: Presentation + VerifiableClaims {}
40
41impl<T: Presentation + VerifiableClaims> VerifiablePresentation for T {}
42
43pub struct PresentationTypes<'a> {
44 base_type: bool,
45 additional_types: std::slice::Iter<'a, String>,
46}
47
48impl<'a> PresentationTypes<'a> {
49 pub fn from_additional_types(additional_types: &'a [String]) -> Self {
50 Self {
51 base_type: true,
52 additional_types: additional_types.iter(),
53 }
54 }
55}
56
57impl<'a> Iterator for PresentationTypes<'a> {
58 type Item = &'a str;
59
60 fn next(&mut self) -> Option<Self::Item> {
61 if self.base_type {
62 self.base_type = false;
63 Some(VERIFIABLE_PRESENTATION_TYPE)
64 } else {
65 self.additional_types.next().map(String::as_str)
66 }
67 }
68}