libp2p_identity/generated/
keys_proto.rs1#![allow(non_snake_case)]
4#![allow(non_upper_case_globals)]
5#![allow(non_camel_case_types)]
6#![allow(unused_imports)]
7#![allow(unknown_lints)]
8#![allow(clippy::all)]
9#![cfg_attr(rustfmt, rustfmt_skip)]
10
11
12use quick_protobuf::{MessageInfo, MessageRead, MessageWrite, BytesReader, Writer, WriterBackend, Result};
13use quick_protobuf::sizeofs::*;
14use super::*;
15
16#[derive(Debug, PartialEq, Eq, Clone, Copy)]
17pub enum KeyType {
18 RSA = 0,
19 Ed25519 = 1,
20 Secp256k1 = 2,
21 ECDSA = 3,
22}
23
24impl Default for KeyType {
25 fn default() -> Self {
26 KeyType::RSA
27 }
28}
29
30impl From<i32> for KeyType {
31 fn from(i: i32) -> Self {
32 match i {
33 0 => KeyType::RSA,
34 1 => KeyType::Ed25519,
35 2 => KeyType::Secp256k1,
36 3 => KeyType::ECDSA,
37 _ => Self::default(),
38 }
39 }
40}
41
42impl<'a> From<&'a str> for KeyType {
43 fn from(s: &'a str) -> Self {
44 match s {
45 "RSA" => KeyType::RSA,
46 "Ed25519" => KeyType::Ed25519,
47 "Secp256k1" => KeyType::Secp256k1,
48 "ECDSA" => KeyType::ECDSA,
49 _ => Self::default(),
50 }
51 }
52}
53
54#[allow(clippy::derive_partial_eq_without_eq)]
55#[derive(Debug, Default, PartialEq, Clone)]
56pub struct PublicKey {
57 pub Type: keys_proto::KeyType,
58 pub Data: Vec<u8>,
59}
60
61impl<'a> MessageRead<'a> for PublicKey {
62 fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
63 let mut msg = Self::default();
64 while !r.is_eof() {
65 match r.next_tag(bytes) {
66 Ok(8) => msg.Type = r.read_enum(bytes)?,
67 Ok(18) => msg.Data = r.read_bytes(bytes)?.to_owned(),
68 Ok(t) => { r.read_unknown(bytes, t)?; }
69 Err(e) => return Err(e),
70 }
71 }
72 Ok(msg)
73 }
74}
75
76impl MessageWrite for PublicKey {
77 fn get_size(&self) -> usize {
78 0
79 + 1 + sizeof_varint(*(&self.Type) as u64)
80 + 1 + sizeof_len((&self.Data).len())
81 }
82
83 fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
84 w.write_with_tag(8, |w| w.write_enum(*&self.Type as i32))?;
85 w.write_with_tag(18, |w| w.write_bytes(&**&self.Data))?;
86 Ok(())
87 }
88}
89
90#[allow(clippy::derive_partial_eq_without_eq)]
91#[derive(Debug, Default, PartialEq, Clone)]
92pub struct PrivateKey {
93 pub Type: keys_proto::KeyType,
94 pub Data: Vec<u8>,
95}
96
97impl<'a> MessageRead<'a> for PrivateKey {
98 fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
99 let mut msg = Self::default();
100 while !r.is_eof() {
101 match r.next_tag(bytes) {
102 Ok(8) => msg.Type = r.read_enum(bytes)?,
103 Ok(18) => msg.Data = r.read_bytes(bytes)?.to_owned(),
104 Ok(t) => { r.read_unknown(bytes, t)?; }
105 Err(e) => return Err(e),
106 }
107 }
108 Ok(msg)
109 }
110}
111
112impl MessageWrite for PrivateKey {
113 fn get_size(&self) -> usize {
114 0
115 + 1 + sizeof_varint(*(&self.Type) as u64)
116 + 1 + sizeof_len((&self.Data).len())
117 }
118
119 fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
120 w.write_with_tag(8, |w| w.write_enum(*&self.Type as i32))?;
121 w.write_with_tag(18, |w| w.write_bytes(&**&self.Data))?;
122 Ok(())
123 }
124}
125