sentc_crypto_light/
lib.rs1#![no_std]
2
3extern crate alloc;
4
5pub mod error;
6pub mod group;
7pub mod user;
8#[cfg(any(feature = "full_rustls", feature = "full_wasm"))]
9pub mod util_req_full;
10
11use alloc::string::String;
12
13#[cfg(feature = "server_test")]
14pub use sentc_crypto_common as sdk_common;
15use sentc_crypto_common::{DeviceId, UserId};
16use sentc_crypto_utils::cryptomat::KeyToString;
17use serde::{Deserialize, Serialize};
18pub use {sentc_crypto_core as sdk_core, sentc_crypto_utils as sdk_utils, sentc_crypto_std_keys as sdk_keys};
19
20use crate::error::SdkLightError;
21
22pub type StdDeviceKeyDataInt = sentc_crypto_utils::user::DeviceKeyDataInt<
23 sentc_crypto_std_keys::util::SecretKey,
24 sentc_crypto_std_keys::util::PublicKey,
25 sentc_crypto_std_keys::util::SignKey,
26 sentc_crypto_std_keys::util::VerifyKey,
27>;
28pub type StdUserPreVerifyLogin = sentc_crypto_utils::user::UserPreVerifyLogin<
29 sentc_crypto_std_keys::util::SecretKey,
30 sentc_crypto_std_keys::util::PublicKey,
31 sentc_crypto_std_keys::util::SignKey,
32 sentc_crypto_std_keys::util::VerifyKey,
33>;
34
35pub struct UserDataInt
36{
37 pub jwt: String,
38 pub refresh_token: String,
39 pub user_id: UserId,
40 pub device_id: DeviceId,
41
42 pub device_keys: StdDeviceKeyDataInt,
43}
44
45#[derive(Serialize, Deserialize)]
46pub struct UserDataExport
47{
48 pub device_keys: DeviceKeyDataExport,
49 pub jwt: String,
50 pub refresh_token: String,
51 pub user_id: UserId,
52 pub device_id: DeviceId,
53}
54
55impl TryFrom<UserDataInt> for UserDataExport
56{
57 type Error = SdkLightError;
58
59 fn try_from(value: UserDataInt) -> Result<Self, Self::Error>
60 {
61 Ok(Self {
62 device_keys: value.device_keys.try_into()?,
63 jwt: value.jwt,
64 refresh_token: value.refresh_token,
65 user_id: value.user_id,
66 device_id: value.device_id,
67 })
68 }
69}
70
71#[derive(Serialize, Deserialize)]
72pub struct DeviceKeyDataExport
73{
74 pub private_key: String, pub public_key: String,
76 pub sign_key: String,
77 pub verify_key: String,
78 pub exported_public_key: String,
79 pub exported_verify_key: String,
80}
81
82impl TryFrom<StdDeviceKeyDataInt> for DeviceKeyDataExport
83{
84 type Error = SdkLightError;
85
86 fn try_from(value: StdDeviceKeyDataInt) -> Result<Self, Self::Error>
87 {
88 Ok(Self {
89 private_key: value.private_key.to_string()?,
90 public_key: value.public_key.to_string()?,
91 sign_key: value.sign_key.to_string()?,
92 verify_key: value.verify_key.to_string()?,
93 exported_public_key: value
94 .exported_public_key
95 .to_string()
96 .map_err(|_e| SdkLightError::JsonToStringFailed)?,
97 exported_verify_key: value
98 .exported_verify_key
99 .to_string()
100 .map_err(|_e| SdkLightError::JsonToStringFailed)?,
101 })
102 }
103}