ssh_agent/proto/
private_key.rs

1use serde::{Deserialize, Serialize};
2use serde::de::{Deserializer, Error};
3use serde::ser::{Serializer, SerializeTuple};
4use super::error::ProtoError;
5use super::key_type::{KeyType, KeyTypeEnum};
6
7pub type MpInt = Vec<u8>;
8
9#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
10pub struct DssPrivateKey {
11    pub p: MpInt,
12    pub q: MpInt,
13    pub g: MpInt,
14    pub y: MpInt,
15    pub x: MpInt
16}
17
18#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
19pub struct Ed25519PrivateKey {
20    pub enc_a: Vec<u8>,
21    pub k_enc_a: Vec<u8>
22}
23
24#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
25pub struct RsaPrivateKey {
26    pub n: MpInt,
27    pub e: MpInt,
28    pub d: MpInt,
29    pub iqmp: MpInt,
30    pub p: MpInt,
31    pub q: MpInt
32}
33
34#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
35pub struct EcDsaPrivateKey {
36    pub identifier: String,
37    pub q: MpInt,
38    pub d: MpInt
39}
40
41#[derive(Clone, Debug, Eq, Hash, PartialEq)]
42pub enum PrivateKey {
43    Dss(DssPrivateKey),
44    Ed25519(Ed25519PrivateKey),
45    Rsa(RsaPrivateKey),
46    EcDsa(EcDsaPrivateKey)
47}
48
49impl KeyType for RsaPrivateKey {
50    const KEY_TYPE: &'static str = "ssh-rsa";
51}
52
53impl KeyType for DssPrivateKey {
54    const KEY_TYPE: &'static str = "ssh-dss";
55}
56
57impl KeyType for Ed25519PrivateKey {
58    const KEY_TYPE: &'static str = "ssh-ed25519";
59}
60
61impl KeyType for EcDsaPrivateKey {
62    const KEY_TYPE: &'static str = "ecdsa-sha2";
63    
64    fn key_type(&self) -> String {
65        format!("{}-{}", Self::KEY_TYPE, self.identifier)
66    }
67}
68
69impl_key_type_enum_ser_de!(
70    PrivateKey,
71    (PrivateKey::Dss, DssPrivateKey),
72    (PrivateKey::Rsa, RsaPrivateKey),
73    (PrivateKey::EcDsa, EcDsaPrivateKey),
74    (PrivateKey::Ed25519, Ed25519PrivateKey)
75);