ipfs_api_prelude/request/
key.rs

1// Copyright 2017 rust-ipfs-api Developers
2//
3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. This file may not be
6// copied, modified, or distributed except according to those terms.
7//
8
9use crate::request::ApiRequest;
10use serde::{Serialize, Serializer};
11
12#[derive(Copy, Clone)]
13pub enum KeyType {
14    Rsa,
15    Ed25519,
16}
17
18impl Serialize for KeyType {
19    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
20    where
21        S: Serializer,
22    {
23        let s = match self {
24            KeyType::Rsa => "rsa",
25            KeyType::Ed25519 => "ed25519",
26        };
27
28        serializer.serialize_str(s)
29    }
30}
31
32#[derive(Serialize)]
33pub struct KeyGen<'a> {
34    #[serde(rename = "arg")]
35    pub name: &'a str,
36
37    #[serde(rename = "type")]
38    pub kind: KeyType,
39
40    pub size: i32,
41}
42
43impl<'a> ApiRequest for KeyGen<'a> {
44    const PATH: &'static str = "/key/gen";
45}
46
47pub struct KeyList;
48
49impl_skip_serialize!(KeyList);
50
51impl ApiRequest for KeyList {
52    const PATH: &'static str = "/key/list";
53}
54
55#[derive(Serialize)]
56pub struct KeyRename<'a, 'b> {
57    #[serde(rename = "arg")]
58    pub name: &'a str,
59
60    #[serde(rename = "arg")]
61    pub new: &'b str,
62
63    pub force: bool,
64}
65
66impl<'a, 'b> ApiRequest for KeyRename<'a, 'b> {
67    const PATH: &'static str = "/key/rename";
68}
69
70#[derive(Serialize)]
71pub struct KeyRm<'a> {
72    #[serde(rename = "arg")]
73    pub name: &'a str,
74}
75
76impl<'a> ApiRequest for KeyRm<'a> {
77    const PATH: &'static str = "/key/rm";
78}