1pub mod types;
4
5#[allow(unused_imports)]
6use types::*;
7
8#[derive(Clone)]
10pub struct KeysClient {
11 client: crate::client::Client,
12}
13
14impl KeysClient {
15 pub fn new(client: crate::client::Client) -> Self {
16 KeysClient { client }
17 }
18
19 pub async fn list_keys(
21 &self,
22 query: Option<ListKeysQuery>,
23 ) -> Result<ListKeysResponse, crate::error::Error> {
24 let mut path = String::from("/keys");
25 if let Some(query) = &query {
26 let mut q: Vec<String> = Vec::new();
27 if let Some(v) = &query.limit {
28 q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
29 }
30 if let Some(v) = &query.pagination_token {
31 q.push(format!(
32 "paginationToken={}",
33 urlencoding::encode(&v.to_string())
34 ));
35 }
36 if let Some(v) = &query.owner {
37 q.push(format!("owner={}", urlencoding::encode(&v.to_string())));
38 }
39 if !q.is_empty() {
40 path.push('?');
41 path.push_str(&q.join("&"));
42 }
43 }
44 self.client
45 .request::<ListKeysResponse>(reqwest::Method::GET, &path, None, false)
46 .await
47 }
48
49 pub async fn create_key(
51 &self,
52 body: CreateKeyRequest,
53 ) -> Result<CreateKeyResponse, crate::error::Error> {
54 let path = String::from("/keys");
55 let body = serde_json::to_value(&body)?;
56 self.client
57 .request::<CreateKeyResponse>(reqwest::Method::POST, &path, Some(&body), true)
58 .await
59 }
60
61 pub async fn delegate_key(
66 &self,
67 key_id: String,
68 body: DelegateKeyRequest,
69 ) -> Result<DelegateKeyResponse, crate::error::Error> {
70 let path = format!("/keys/{}/delegate", urlencoding::encode(&key_id));
71 let body = serde_json::to_value(&body)?;
72 self.client
73 .request::<DelegateKeyResponse>(reqwest::Method::POST, &path, Some(&body), true)
74 .await
75 }
76
77 pub async fn get_key(&self, key_id: String) -> Result<GetKeyResponse, crate::error::Error> {
79 let path = format!("/keys/{}", urlencoding::encode(&key_id));
80 self.client
81 .request::<GetKeyResponse>(reqwest::Method::GET, &path, None, false)
82 .await
83 }
84
85 pub async fn update_key(
87 &self,
88 key_id: String,
89 body: UpdateKeyRequest,
90 ) -> Result<UpdateKeyResponse, crate::error::Error> {
91 let path = format!("/keys/{}", urlencoding::encode(&key_id));
92 let body = serde_json::to_value(&body)?;
93 self.client
94 .request::<UpdateKeyResponse>(reqwest::Method::PUT, &path, Some(&body), true)
95 .await
96 }
97
98 pub async fn delete_key(
100 &self,
101 key_id: String,
102 ) -> Result<DeleteKeyResponse, crate::error::Error> {
103 let path = format!("/keys/{}", urlencoding::encode(&key_id));
104 self.client
105 .request::<DeleteKeyResponse>(reqwest::Method::DELETE, &path, None, true)
106 .await
107 }
108
109 pub async fn derive_key(
114 &self,
115 key_id: String,
116 body: DeriveKeyRequest,
117 ) -> Result<DeriveKeyResponse, crate::error::Error> {
118 let path = format!("/keys/{}/derive", urlencoding::encode(&key_id));
119 let body = serde_json::to_value(&body)?;
120 self.client
121 .request::<DeriveKeyResponse>(reqwest::Method::POST, &path, Some(&body), true)
122 .await
123 }
124
125 pub async fn export_key(
130 &self,
131 key_id: String,
132 body: ExportKeyRequest,
133 ) -> Result<ExportKeyResponse, crate::error::Error> {
134 let path = format!("/keys/{}/export", urlencoding::encode(&key_id));
135 let body = serde_json::to_value(&body)?;
136 self.client
137 .request::<ExportKeyResponse>(reqwest::Method::POST, &path, Some(&body), true)
138 .await
139 }
140
141 pub async fn list_signatures(
143 &self,
144 key_id: String,
145 query: Option<ListSignaturesQuery>,
146 ) -> Result<ListSignaturesResponse, crate::error::Error> {
147 let mut path = format!("/keys/{}/signatures", urlencoding::encode(&key_id));
148 if let Some(query) = &query {
149 let mut q: Vec<String> = Vec::new();
150 if let Some(v) = &query.limit {
151 q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
152 }
153 if let Some(v) = &query.pagination_token {
154 q.push(format!(
155 "paginationToken={}",
156 urlencoding::encode(&v.to_string())
157 ));
158 }
159 if !q.is_empty() {
160 path.push('?');
161 path.push_str(&q.join("&"));
162 }
163 }
164 self.client
165 .request::<ListSignaturesResponse>(reqwest::Method::GET, &path, None, false)
166 .await
167 }
168
169 pub async fn generate_signature(
174 &self,
175 key_id: String,
176 body: GenerateSignatureRequest,
177 ) -> Result<GenerateSignatureResponse, crate::error::Error> {
178 let path = format!("/keys/{}/signatures", urlencoding::encode(&key_id));
179 let body = serde_json::to_value(&body)?;
180 self.client
181 .request::<GenerateSignatureResponse>(reqwest::Method::POST, &path, Some(&body), true)
182 .await
183 }
184
185 pub async fn get_signature(
187 &self,
188 key_id: String,
189 signature_id: String,
190 ) -> Result<GetSignatureResponse, crate::error::Error> {
191 let path = format!(
192 "/keys/{}/signatures/{}",
193 urlencoding::encode(&key_id),
194 urlencoding::encode(&signature_id)
195 );
196 self.client
197 .request::<GetSignatureResponse>(reqwest::Method::GET, &path, None, false)
198 .await
199 }
200
201 pub async fn import_key(
206 &self,
207 body: ImportKeyRequest,
208 ) -> Result<ImportKeyResponse, crate::error::Error> {
209 let path = String::from("/keys/import");
210 let body = serde_json::to_value(&body)?;
211 self.client
212 .request::<ImportKeyResponse>(reqwest::Method::POST, &path, Some(&body), true)
213 .await
214 }
215}