Skip to main content

smart_id_rust_client/models/api/
session_status.rs

1use crate::error::Result;
2use crate::error::SmartIdClientError;
3use crate::models::api::response::SmartIdAPIResponse;
4use crate::models::common::CertificateLevel;
5use crate::models::interaction::InteractionFlow;
6use crate::models::signature::{ResponseSignature, SignatureProtocol};
7use serde::{Deserialize, Serialize};
8use serde_with::skip_serializing_none;
9
10pub(crate) type SessionResponse = SmartIdAPIResponse<SessionStatusResponse>;
11
12/// Session Status
13///
14/// This struct represents the status of a session with the Smart ID service.
15/// It is returned from the Smart ID service session status endpoint.
16///
17/// # Properties
18///
19/// * `state` - The current state of the session, either `RUNNING` or `COMPLETE`.
20/// * `result` - The result of the session, if available. result.endResult will be `OK` if the session was successful.
21/// * `signature_protocol` - The protocol used for the signature, if available.
22/// * `signature` - The signature response, if available.
23/// * `cert` - The session certificate, if available. Contains the level of the certificate and the certificate value DER+Base64 encoded.
24/// * `ignored_properties` - Any values from requestProperties that were unsupported or ignored.
25/// * `interaction_type_used` - The interaction flow used during the session, if available.
26/// * `device_ip_address` - The IP address of the mobile device, if it was requested using "shareMdClientIpAddress" in the session creation parameters.
27#[skip_serializing_none]
28#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
29#[serde(rename_all = "camelCase")]
30pub struct SessionStatusResponse {
31    pub state: SessionState,
32    pub result: Option<SessionResult>,
33    pub signature_protocol: Option<SignatureProtocol>,
34    pub signature: Option<ResponseSignature>,
35    pub cert: Option<SessionCertificate>,
36    pub ignored_properties: Option<Vec<String>>,
37    pub interaction_type_used: Option<InteractionFlow>,
38    pub device_ip_address: Option<String>,
39}
40
41/// Session Certificate
42///
43/// This struct represents the certificate used in a session with the Smart ID service.
44/// During an auth flow a certificate that is non-repudiation capable is returned, for signing flows a certificate that is digital signature capable is returned.
45///
46/// # Properties
47///
48/// * `value` - The certificate value, DER+Base64 encoded. The certificate itself contains info on whether the certificate is QSCD-enabled, data which is not represented by certificate level.
49/// * `certificate_level` - The level of the certificate.
50#[skip_serializing_none]
51#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
52#[serde(rename_all = "camelCase")]
53pub struct SessionCertificate {
54    // Certificate value, DER+Base64 encoded. The certificate itself contains info on whether the certificate is QSCD-enabled, data which is not represented by certificate level.
55    pub value: String,
56    pub certificate_level: CertificateLevel,
57}
58
59/// Session Result
60///
61/// This struct represents the result of a session with the Smart ID service.
62/// It is part of the session status response.
63///
64/// # Properties
65///
66/// * `end_result` - The end result of the session. OK for success, otherwise an error.
67/// * `document_number` - The document number associated with the session, if available. Can be used in further signature and authentication requests.
68#[skip_serializing_none]
69#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
70#[serde(rename_all = "camelCase")]
71pub struct SessionResult {
72    pub end_result: EndResult,
73    pub document_number: Option<String>,
74}
75
76#[allow(non_camel_case_types)]
77#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
78#[non_exhaustive]
79pub enum SessionState {
80    #[default]
81    RUNNING,
82    COMPLETE,
83}
84
85#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
86#[allow(non_camel_case_types)]
87#[non_exhaustive]
88pub enum EndResult {
89    // Session was completed successfully, there is a certificate, document number and possibly signature in return structure.
90    OK,
91    // User refused the session.
92    USER_REFUSED,
93    // User refused on interaction screen, i.e. displayed text and PIN, or verification code choice.
94    USER_REFUSED_INTERACTION,
95    // There was a timeout, i.e. end user did not confirm or refuse the operation within given time frame.
96    TIMEOUT,
97    // For some reason, this RP request cannot be completed. User must either check his/her Smart-ID mobile application or turn to customer support for getting the exact reason.
98    DOCUMENT_UNUSABLE,
99    // In case the multiple-choice verification code was requested, the user did not choose the correct verification code.
100    WRONG_VC,
101    // User app version does not support any of the allowedInteractionsOrder interactions.
102    REQUIRED_INTERACTION_NOT_SUPPORTED_BY_APP,
103    // User has multiple accounts and pressed Cancel on device choice screen on any device.
104    USER_REFUSED_CERT_CHOICE,
105    // User pressed Cancel on PIN screen. Can be from the most common displayTextAndPIN flow or from verificationCodeChoice flow when user chosen the right code and then pressed cancel on PIN screen.
106    USER_REFUSED_DISPLAYTEXTANDPIN,
107    // User cancelled verificationCodeChoice screen.
108    USER_REFUSED_VC_CHOICE,
109    // User cancelled on confirmationMessage screen.
110    USER_REFUSED_CONFIRMATIONMESSAGE,
111    // User cancelled on confirmationMessageAndVerificationCodeChoice screen.
112    USER_REFUSED_CONFIRMATIONMESSAGE_WITH_VC_CHOICE,
113    // Failure in executing the protocol
114    PROTOCOL_FAILURE,
115    // Generic server error
116    SERVER_ERROR,
117    #[default]
118    UNKNOWN,
119}
120
121impl EndResult {
122    pub fn is_ok(&self) -> Result<()> {
123        match self {
124            EndResult::OK => Ok(()),
125            EndResult::USER_REFUSED => {
126                Err(SmartIdClientError::UserRefusedVerificationChoiceException)
127            }
128            EndResult::TIMEOUT => Err(SmartIdClientError::SessionTimeoutException),
129            EndResult::DOCUMENT_UNUSABLE => Err(SmartIdClientError::DocumentUnusableException),
130            EndResult::WRONG_VC => {
131                Err(SmartIdClientError::UserSelectedWrongVerificationCodeException)
132            }
133            EndResult::REQUIRED_INTERACTION_NOT_SUPPORTED_BY_APP => {
134                Err(SmartIdClientError::RequiredInteractionNotSupportedByAppException)
135            }
136            EndResult::USER_REFUSED_CERT_CHOICE => {
137                Err(SmartIdClientError::UserRefusedCertChoiceException)
138            }
139            EndResult::USER_REFUSED_DISPLAYTEXTANDPIN => {
140                Err(SmartIdClientError::UserRefusedDisplayTextAndPinException)
141            }
142            EndResult::USER_REFUSED_VC_CHOICE => {
143                Err(SmartIdClientError::UserRefusedVerificationChoiceException)
144            }
145            EndResult::USER_REFUSED_CONFIRMATIONMESSAGE => {
146                Err(SmartIdClientError::UserRefusedConfirmationMessageException)
147            }
148            EndResult::USER_REFUSED_CONFIRMATIONMESSAGE_WITH_VC_CHOICE => Err(
149                SmartIdClientError::UserRefusedConfirmationMessageWithVerificationChoiceException,
150            ),
151            EndResult::PROTOCOL_FAILURE => Err(SmartIdClientError::ProtocolFailureException),
152            EndResult::SERVER_ERROR => Err(SmartIdClientError::ServerErrorException),
153            EndResult::UNKNOWN | _ => Err(SmartIdClientError::SmartIdClientException(
154                "Unknown session end result",
155            )),
156        }
157    }
158}
159
160impl From<EndResult> for SmartIdClientError {
161    fn from(val: EndResult) -> Self {
162        match val {
163            EndResult::USER_REFUSED => SmartIdClientError::UserRefusedVerificationChoiceException,
164            EndResult::TIMEOUT => SmartIdClientError::SessionTimeoutException,
165            EndResult::DOCUMENT_UNUSABLE => SmartIdClientError::DocumentUnusableException,
166            EndResult::WRONG_VC => SmartIdClientError::UserSelectedWrongVerificationCodeException,
167            EndResult::REQUIRED_INTERACTION_NOT_SUPPORTED_BY_APP => {
168                SmartIdClientError::RequiredInteractionNotSupportedByAppException
169            }
170            EndResult::USER_REFUSED_CERT_CHOICE => {
171                SmartIdClientError::UserRefusedCertChoiceException
172            }
173            EndResult::USER_REFUSED_DISPLAYTEXTANDPIN => {
174                SmartIdClientError::UserRefusedDisplayTextAndPinException
175            }
176            EndResult::USER_REFUSED_VC_CHOICE => {
177                SmartIdClientError::UserRefusedVerificationChoiceException
178            }
179            EndResult::USER_REFUSED_CONFIRMATIONMESSAGE => {
180                SmartIdClientError::UserRefusedConfirmationMessageException
181            }
182            EndResult::USER_REFUSED_CONFIRMATIONMESSAGE_WITH_VC_CHOICE => {
183                SmartIdClientError::UserRefusedConfirmationMessageWithVerificationChoiceException
184            }
185            _ => SmartIdClientError::SmartIdClientException("Unknown session end result"),
186        }
187    }
188}