1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;

#[derive(Serialize, Deserialize, Debug, PartialEq)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum SessionStatus {
    Initialized,
    Connected,
    Cancelled,
    Done,
    Timeout,
}

#[derive(Serialize, Deserialize, Debug, PartialEq)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ProofStatus {
    /// Proof is valid
    Valid,
    /// Proof is invalid
    Invalid,
    /// Attribute-based signature had invalid timestamp
    InvalidTimestamp,
    /// Proof does not correspond to a specified request
    UnmatchedRequest,
    /// Proof does not contain all requested attributes
    MissingAttributes,
    /// Attributes were expired at proof creation time (now, or according to timestamp in case of abs)
    Expired,
}

#[derive(Serialize, Deserialize, Debug, PartialEq)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum AttributeProofStatus {
    /// Attribute is disclosed and matches the value
    Present,
    /// Attribute is disclosed, but wasn't requested in request
    Extra,
    /// Attribute is disclosed but is null
    Null,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub enum SessionType {
    Disclosing,
    Signing,
    Issuing,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Qr {
    pub u: String,
    pub irmaqr: SessionType,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct SessionToken(pub String);

impl<'a> Into<&'a str> for &'a SessionToken {
    fn into(self) -> &'a str {
        &self.0
    }
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct SessionPackage {
    pub session_ptr: Qr,
    pub token: SessionToken,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct DisclosedAttribute {
    pub rawvalue: Option<String>,
    pub value: BTreeMap<String, String>,
    pub id: String,
    pub status: AttributeProofStatus,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct SessionResult {
    pub token: SessionToken,
    pub status: SessionStatus,
    #[serde(rename = "type")]
    pub stype: SessionType,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub proof_status: Option<ProofStatus>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub disclosed: Option<Vec<Vec<DisclosedAttribute>>>,
    // TODO signature irma.SignedMessage
    // TODO error irma.RemoteError
}