1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
mod ed25519;
use derive_more::From;
pub use self::ed25519::Ed25519Signature;
use crate::Error;
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, From, packable::Packable)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(tag = "type", content = "data")
)]
#[packable(unpack_error = Error)]
#[packable(tag_type = u8, with_error = Error::InvalidSignatureKind)]
pub enum Signature {
#[packable(tag = Ed25519Signature::KIND)]
Ed25519(Ed25519Signature),
}
impl Signature {
pub fn kind(&self) -> u8 {
match self {
Self::Ed25519(_) => Ed25519Signature::KIND,
}
}
}
#[cfg(feature = "dto")]
#[allow(missing_docs)]
pub mod dto {
use serde::{Deserialize, Serialize};
pub use super::ed25519::dto::Ed25519SignatureDto;
use super::*;
use crate::error::dto::DtoError;
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SignatureDto {
Ed25519(Ed25519SignatureDto),
}
impl From<&Signature> for SignatureDto {
fn from(value: &Signature) -> Self {
match value {
Signature::Ed25519(s) => SignatureDto::Ed25519(s.into()),
}
}
}
impl TryFrom<&SignatureDto> for Signature {
type Error = DtoError;
fn try_from(value: &SignatureDto) -> Result<Self, Self::Error> {
match value {
SignatureDto::Ed25519(s) => Ok(Signature::Ed25519(s.try_into()?)),
}
}
}
}