Skip to main content

heika_core/
signature.rs

1//! 署名。
2
3use core::fmt;
4use core::str::FromStr;
5
6use crate::hex::{self, ParseHexError};
7
8/// Ed25519 の署名。前半の32バイトが R、後半の32バイトが S。
9/// 文字列にするときは、Symbol の慣習に合わせて大文字の16進にする。
10#[derive(Clone, Copy, PartialEq, Eq, Hash)]
11pub struct Signature(pub [u8; 64]);
12
13impl fmt::Display for Signature {
14    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15        f.write_str(&hex::encode(&self.0))
16    }
17}
18
19impl fmt::Debug for Signature {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        write!(f, "Signature({self})")
22    }
23}
24
25impl FromStr for Signature {
26    type Err = ParseHexError;
27
28    fn from_str(text: &str) -> Result<Self, Self::Err> {
29        hex::decode(text).map(Self)
30    }
31}