Skip to content

Commit e1a5859

Browse files
committed
Merge branch 'release/0.1.3'
2 parents 6cc055d + 707d9a4 commit e1a5859

File tree

7 files changed

+41
-21
lines changed

7 files changed

+41
-21
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "smart-id-rust-client"
3-
version = "0.1.2"
3+
version = "0.1.3"
44
description = "Smart ID Rust Client"
55
homepage = "https://smart-id.com"
66
authors = ["Michallis Pashidis <[email protected]>"]

examples/smart_id_client.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ async fn main() -> Result<()> {
2222

2323

2424
/// Example get Certificate
25-
//let _ = uc_get_certificate_choice(&cfg).await;
25+
let _ = uc_get_certificate_choice(&cfg).await;
2626

2727
/// Example authenticate user
28-
//let _ = uc_authenticate_by_semantic_identifier(&cfg).await;
28+
let _ = uc_authenticate_by_semantic_identifier(&cfg).await;
2929

3030
/// Example sign document digest
3131
let _ = uc_sign_by_semantic_identifier(&cfg).await;
@@ -36,7 +36,7 @@ async fn main() -> Result<()> {
3636
async fn uc_get_certificate_choice(cfg: &SmartIDConfig) -> Result<()> {
3737

3838
/// Create the semantic identifier
39-
let sem_id = SemanticsIdentifier::new_from_enum(IdentityType::PNO, CountryCode::BE, "81092402747");
39+
let sem_id = SemanticsIdentifier::new_from_enum_mock(IdentityType::PNO, CountryCode::BE);
4040

4141
/// Verify if a certificate exists for given id
4242
let res = get_certificate_by_semantic_identifier(&cfg, sem_id).await;
@@ -52,7 +52,7 @@ async fn uc_get_certificate_choice(cfg: &SmartIDConfig) -> Result<()> {
5252

5353
async fn uc_authenticate_by_semantic_identifier(cfg: &SmartIDConfig) -> Result<()> {
5454
/// Create the semantic identifier
55-
let sem_id = SemanticsIdentifier::new_from_enum(IdentityType::PNO, CountryCode::BE, "81092402747");
55+
let sem_id = SemanticsIdentifier::new_from_enum_mock(IdentityType::PNO, CountryCode::BE);
5656

5757
/// Define interactions
5858
let interactions: Vec<Interaction> = vec![Interaction::diplay_text_and_pin("Authenticate to Application: ReadMyCards")];
@@ -79,7 +79,7 @@ async fn uc_authenticate_by_semantic_identifier(cfg: &SmartIDConfig) -> Result<(
7979

8080
async fn uc_sign_by_semantic_identifier(cfg: &SmartIDConfig) -> Result<()> {
8181
/// Create the semantic identifier
82-
let sem_id = SemanticsIdentifier::new_from_enum(IdentityType::PNO, CountryCode::BE, "81092402747");
82+
let sem_id = SemanticsIdentifier::new_from_enum_mock(IdentityType::PNO, CountryCode::BE);
8383

8484
/// Define interactions
8585
let interactions: Vec<Interaction> = vec![Interaction::confirmation_message("Are you sure to sign document: something.pdf?"), Interaction::diplay_text_and_pin("Sign using ReadMyCards")];

src/client/reqwest_generic.rs

+18-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ use tokio::fs::File;
99
use tokio::time::sleep;
1010
use tracing::{debug, error};
1111

12+
const HEADER_CONTENT_TYPE: &'static str = "content-type";
13+
const HEADER_CONTENT_TYPE_DEFAULT: &'static str = "application/json";
14+
const HEADER_USER_AGENT: &'static str = "User-Agent";
15+
const HEADER_USER_AGENT_VERSION: &'static str = env!("CARGO_PKG_VERSION");
16+
const HEADER_USER_AGENT_RUST_VERSION: &'static str = env!("CARGO_PKG_RUST_VERSION");
17+
1218
/// Generic get JWT based on APIKEY
1319
/// Not used for Smart ID client
1420
pub async fn get_token<R>(url: &str, timeout_millis: Option<u64>) -> Result<R>
@@ -24,7 +30,8 @@ where
2430
.unwrap();
2531
client
2632
.get(url)
27-
.header("content-type", "application/json")
33+
.header(HEADER_CONTENT_TYPE, HEADER_CONTENT_TYPE_DEFAULT)
34+
.header(HEADER_USER_AGENT, format!("smart-id-rust-client/{:?}/rust/{:?}",HEADER_USER_AGENT_VERSION, HEADER_USER_AGENT_RUST_VERSION))
2835
.send()
2936
.await?
3037
.json::<R>()
@@ -50,7 +57,8 @@ where
5057
.unwrap();
5158
let send_response = client
5259
.get(url)
53-
.header("content-type", "application/json")
60+
.header(HEADER_CONTENT_TYPE, HEADER_CONTENT_TYPE_DEFAULT)
61+
.header(HEADER_USER_AGENT, format!("smart-id-rust-client/{:?}/rust/{:?}",HEADER_USER_AGENT_VERSION, HEADER_USER_AGENT_RUST_VERSION))
5462
.send()
5563
.await?;
5664
let status = send_response.status().as_u16();
@@ -80,7 +88,8 @@ pub async fn delete(
8088
.unwrap();
8189
let res = client
8290
.delete(url)
83-
.header("content-type", "application/json")
91+
.header(HEADER_CONTENT_TYPE, HEADER_CONTENT_TYPE_DEFAULT)
92+
.header(HEADER_USER_AGENT, format!("smart-id-rust-client/{:?}/rust/{:?}",HEADER_USER_AGENT_VERSION, HEADER_USER_AGENT_RUST_VERSION))
8493
.send()
8594
.await?;
8695
Ok(())
@@ -106,7 +115,8 @@ where
106115
.unwrap();
107116
let send_response = client
108117
.post(url)
109-
.header("content-type", "application/json")
118+
.header(HEADER_CONTENT_TYPE, HEADER_CONTENT_TYPE_DEFAULT)
119+
.header(HEADER_USER_AGENT, format!("smart-id-rust-client/{:?}/rust/{:?}",HEADER_USER_AGENT_VERSION, HEADER_USER_AGENT_RUST_VERSION))
110120
.json(req)
111121
.send()
112122
.await?;
@@ -141,7 +151,8 @@ where
141151
.unwrap();
142152
let send_response = client
143153
.post(url)
144-
.header("content-type", "application/json")
154+
.header(HEADER_CONTENT_TYPE, HEADER_CONTENT_TYPE_DEFAULT)
155+
.header(HEADER_USER_AGENT, format!("smart-id-rust-client/{:?}/rust/{:?}",HEADER_USER_AGENT_VERSION, HEADER_USER_AGENT_RUST_VERSION))
145156
.json(req)
146157
.send()
147158
.await?;
@@ -180,7 +191,8 @@ where
180191
.unwrap();
181192
client
182193
.put(url)
183-
.header("content-type", "application/json")
194+
.header(HEADER_CONTENT_TYPE, HEADER_CONTENT_TYPE_DEFAULT)
195+
.header(HEADER_USER_AGENT, format!("smart-id-rust-client/{:?}/rust/{:?}",HEADER_USER_AGENT_VERSION, HEADER_USER_AGENT_RUST_VERSION))
184196
.json(req)
185197
.send()
186198
.await?

src/client_controller.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub async fn ctrl_get_certificate_by_document_number(cfg: &SmartIDConfig, doc_nr
1919
let req = CertificateRequest::new(cfg).await;
2020
match sc.get_certificate_by_document_number(doc_nr.into(), &req).await {
2121
Ok(r) => ctrl_poll_session_status(cfg, r.session_id).await,
22-
Err(_) => Err(anyhow::anyhow!(SmartIdClientError::SessionNotFound))
22+
Err(e) => Err(anyhow::anyhow!(SmartIdClientError::SessionNotFound(e.to_string())))
2323
}
2424
}
2525

@@ -30,7 +30,7 @@ pub async fn ctrl_get_certificate_by_semantic_identifier(cfg: &SmartIDConfig, id
3030
let req = CertificateRequest::new(cfg).await;
3131
match sc.get_certificate_by_semantic_identifier(id, &req).await {
3232
Ok(r) => ctrl_poll_session_status(cfg, r.session_id).await,
33-
Err(_) => Err(anyhow::anyhow!(SmartIdClientError::SessionNotFound))
33+
Err(e) => Err(anyhow::anyhow!(SmartIdClientError::SessionNotFound(e.to_string())))
3434
}
3535
}
3636

@@ -39,7 +39,7 @@ pub async fn ctrl_authenticate_by_document_number(cfg: &SmartIDConfig, doc_nr: i
3939
let req = AuthenticationSessionRequest::new(cfg, interactions, hash, hash_type).await?;
4040
match sc.authenticate_by_document_number(doc_nr.into(), &req).await {
4141
Ok(r) => ctrl_poll_session_status(cfg, r.session_id).await,
42-
Err(_) => Err(anyhow::anyhow!(SmartIdClientError::SessionNotFound))
42+
Err(e) => Err(anyhow::anyhow!(SmartIdClientError::SessionNotFound(e.to_string())))
4343
}
4444
}
4545

@@ -48,7 +48,7 @@ pub async fn ctrl_authenticate_by_semantic_identifier(cfg: &SmartIDConfig, id: S
4848
let req = AuthenticationSessionRequest::new(cfg, interactions, hash, hash_type).await?;
4949
match sc.authenticate_by_semantic_identifier(id, &req).await {
5050
Ok(r) => ctrl_poll_session_status(cfg, r.session_id).await,
51-
Err(_) => Err(anyhow::anyhow!(SmartIdClientError::SessionNotFound))
51+
Err(e) => Err(anyhow::anyhow!(SmartIdClientError::SessionNotFound(e.to_string())))
5252
}
5353
}
5454

@@ -57,7 +57,7 @@ pub async fn ctrl_sign_by_document_number(cfg: &SmartIDConfig, doc_nr: impl Into
5757
let req = SignatureSessionRequest::new(cfg, interactions, hash, hash_type).await?;
5858
match sc.sign_by_document_number(doc_nr.into(), &req).await {
5959
Ok(r) => ctrl_poll_session_status(cfg, r.session_id).await,
60-
Err(_) => Err(anyhow::anyhow!(SmartIdClientError::SessionNotFound))
60+
Err(e) => Err(anyhow::anyhow!(SmartIdClientError::SessionNotFound(e.to_string())))
6161
}
6262
}
6363

@@ -66,7 +66,7 @@ pub async fn ctrl_sign_by_semantic_identifier(cfg: &SmartIDConfig, id: Semantics
6666
let req = SignatureSessionRequest::new(cfg, interactions, hash, hash_type).await?;
6767
match sc.sign_by_semantic_identifier(id, &req).await {
6868
Ok(r) => ctrl_poll_session_status(cfg, r.session_id).await,
69-
Err(_) => Err(anyhow::anyhow!(SmartIdClientError::SessionNotFound))
69+
Err(e) => Err(anyhow::anyhow!(SmartIdClientError::SessionNotFound(e.to_string())))
7070
}
7171
}
7272

src/error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ pub enum SmartIdClientError {
1212
SmartIdException(&'static str),
1313

1414
/// Session not found
15-
#[error("Session not found")]
16-
SessionNotFound,
15+
#[error("Session not found: {0}")]
16+
SessionNotFound(String),
1717

1818
#[error("Invalid request")]
1919
InvalidRequest,

src/models/common.rs

+8
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ impl SemanticsIdentifier {
114114
pub fn new_from_enum(identity_type: IdentityType, country_code: CountryCode, identity_number: impl Into<String>) -> Self {
115115
SemanticsIdentifier { identifier: format!("{:?}{:?}-{}", identity_type, country_code, identity_number.into()) }
116116
}
117+
118+
pub fn new_from_string_mock(identity_type: impl Into<String>, country_code: impl Into<String>) -> Self {
119+
SemanticsIdentifier { identifier: format!("{}{}-{}-MOCK-Q", identity_type.into(), country_code.into(), "00010299944") }
120+
}
121+
122+
pub fn new_from_enum_mock(identity_type: IdentityType, country_code: CountryCode) -> Self {
123+
SemanticsIdentifier { identifier: format!("{:?}{:?}-{}-MOCK-Q", identity_type, country_code, "00010299944") }
124+
}
117125
}
118126

119127

0 commit comments

Comments
 (0)