2020-01-22 14:57:26 -08:00
|
|
|
/// An Ed25519 signature.
|
2020-06-09 17:06:17 -07:00
|
|
|
#[derive(Copy, Clone, Eq, PartialEq)]
|
2020-01-22 14:57:26 -08:00
|
|
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
2020-01-22 16:58:18 -08:00
|
|
|
#[allow(non_snake_case)]
|
2020-01-22 14:57:26 -08:00
|
|
|
pub struct Signature {
|
2020-01-22 16:58:18 -08:00
|
|
|
pub(crate) R_bytes: [u8; 32],
|
2020-01-22 14:57:26 -08:00
|
|
|
pub(crate) s_bytes: [u8; 32],
|
|
|
|
}
|
|
|
|
|
2020-06-09 17:06:17 -07:00
|
|
|
impl core::fmt::Debug for Signature {
|
|
|
|
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
|
|
|
|
fmt.debug_struct("Signature")
|
|
|
|
.field("R_bytes", &hex::encode(&self.R_bytes))
|
|
|
|
.field("s_bytes", &hex::encode(&self.s_bytes))
|
|
|
|
.finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 14:57:26 -08:00
|
|
|
impl From<[u8; 64]> for Signature {
|
2020-01-22 16:58:18 -08:00
|
|
|
#[allow(non_snake_case)]
|
2020-01-22 14:57:26 -08:00
|
|
|
fn from(bytes: [u8; 64]) -> Signature {
|
2020-01-22 16:58:18 -08:00
|
|
|
let mut R_bytes = [0; 32];
|
|
|
|
R_bytes.copy_from_slice(&bytes[0..32]);
|
2020-01-22 14:57:26 -08:00
|
|
|
let mut s_bytes = [0; 32];
|
|
|
|
s_bytes.copy_from_slice(&bytes[32..64]);
|
2020-01-22 16:58:18 -08:00
|
|
|
Signature { R_bytes, s_bytes }
|
2020-01-22 14:57:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Signature> for [u8; 64] {
|
|
|
|
fn from(sig: Signature) -> [u8; 64] {
|
|
|
|
let mut bytes = [0; 64];
|
2020-01-22 16:58:18 -08:00
|
|
|
bytes[0..32].copy_from_slice(&sig.R_bytes[..]);
|
2020-01-22 14:57:26 -08:00
|
|
|
bytes[32..64].copy_from_slice(&sig.s_bytes[..]);
|
|
|
|
bytes
|
|
|
|
}
|
|
|
|
}
|