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