1use crate::{NumBytes, Read, UnsignedInt, Write};
2use alloc::string::String;
3use core::fmt;
4
5macro_rules! key_type {
6 ($ident:ident, $bytes:literal) => {
7 #[derive(Read, Write, NumBytes, Clone)]
11 #[eosio(crate_path = "crate::bytes")]
12 pub struct $ident {
13 pub type_: UnsignedInt,
15 pub data: [u8; $bytes],
17 }
18
19 impl $ident {
20 #[must_use]
22 pub const fn as_bytes(&self) -> &[u8; $bytes] {
23 &self.data
24 }
25
26 #[must_use]
28 pub const fn to_bytes(&self) -> [u8; $bytes] {
29 self.data
30 }
31
32 #[must_use]
34 pub fn as_slice(&self) -> &[u8] {
35 &self.data
36 }
37 }
38
39 impl Default for $ident {
40 #[must_use]
41 fn default() -> Self {
42 Self {
43 type_: UnsignedInt::default(),
44 data: [0_u8; $bytes],
45 }
46 }
47 }
48
49 impl PartialEq for $ident {
50 #[must_use]
51 fn eq(&self, other: &Self) -> bool {
52 self.type_ == other.type_ && self.as_slice() == other.as_slice()
53 }
54 }
55
56 impl fmt::Debug for $ident {
57 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
58 fmt::Debug::fmt(&self.type_, f)?;
59 fmt::Debug::fmt(self.as_slice(), f)
60 }
61 }
62 };
63}
64
65key_type!(PublicKey, 34);
66key_type!(Signature, 66);
67
68#[derive(Read, Write, NumBytes, Clone)]
70#[eosio(crate_path = "crate::bytes")]
71pub struct PrivateKey(String);