sentc_crypto_common/
crypto.rs

1use alloc::string::String;
2
3use serde::{Deserialize, Serialize};
4use serde_json::{from_slice, from_str, to_string};
5
6use crate::SignKeyPairId;
7
8#[derive(Serialize, Deserialize)]
9pub struct SignHead
10{
11	pub id: SignKeyPairId,
12	pub alg: String, //in case at decrypt the user got no access to the verify key, but we still need to split data and sig
13}
14
15#[derive(Serialize, Deserialize)]
16pub struct EncryptedHead
17{
18	pub id: String,
19	pub sign: Option<SignHead>, //the key id of the sign key
20}
21
22impl EncryptedHead
23{
24	pub fn from_string(v: &str) -> serde_json::Result<Self>
25	{
26		from_str::<Self>(v)
27	}
28
29	pub fn from_slice(v: &[u8]) -> serde_json::Result<Self>
30	{
31		from_slice::<Self>(v)
32	}
33
34	pub fn to_string(&self) -> serde_json::Result<String>
35	{
36		to_string(self)
37	}
38}
39
40#[derive(Serialize, Deserialize)]
41pub struct GeneratedSymKeyHeadServerInput
42{
43	pub alg: String,
44	pub encrypted_key_string: String,
45	pub master_key_id: String, //the id of the key which was used to encrypt this key
46}
47
48impl GeneratedSymKeyHeadServerInput
49{
50	pub fn from_string(v: &str) -> serde_json::Result<Self>
51	{
52		from_str::<Self>(v)
53	}
54
55	pub fn to_string(&self) -> serde_json::Result<String>
56	{
57		to_string(self)
58	}
59}
60
61#[derive(Serialize, Deserialize)]
62pub struct GeneratedSymKeyHeadServerRegisterOutput
63{
64	pub key_id: String,
65}
66
67impl GeneratedSymKeyHeadServerRegisterOutput
68{
69	pub fn from_string(v: &str) -> serde_json::Result<Self>
70	{
71		from_str::<Self>(v)
72	}
73
74	pub fn to_string(&self) -> serde_json::Result<String>
75	{
76		to_string(self)
77	}
78}
79
80#[derive(Serialize, Deserialize)]
81pub struct GeneratedSymKeyHeadServerOutput
82{
83	pub alg: String,
84	pub encrypted_key_string: String,
85	pub master_key_id: String,
86	pub key_id: String,
87	pub time: u128,
88}
89
90impl GeneratedSymKeyHeadServerOutput
91{
92	pub fn from_string(v: &str) -> serde_json::Result<Self>
93	{
94		from_str::<Self>(v)
95	}
96
97	pub fn to_string(&self) -> serde_json::Result<String>
98	{
99		to_string(self)
100	}
101}