1mod author;
13mod body;
14mod hasher;
15
16pub use author::Author;
17pub use body::Body;
18pub use hasher::{Hasher, InvalidSize};
19
20use crate::crypto::PrivateKey;
21
22#[repr(C)]
30#[derive(Clone, Debug, PartialEq, Eq)]
31pub struct Signature {
32 author: Author,
33 modulus: [u8; 384],
34 exponent: u32,
35 signature: [u8; 384],
36 body: Body,
37 reserved: [u8; 12],
38 q1: [u8; 384],
39 q2: [u8; 384],
40}
41
42impl Signature {
43 pub fn new<T: PrivateKey>(key: &T, author: Author, body: Body) -> Result<Self, T::Error> {
45 use core::mem::{size_of, transmute};
46
47 let a: [u8; size_of::<Author>()] = unsafe { transmute(author) };
48 let b: [u8; size_of::<Body>()] = unsafe { transmute(body) };
49 let sd = key.sign(&a, &b)?;
50
51 Ok(Self {
52 author,
53 modulus: sd.modulus,
54 exponent: sd.exponent,
55 signature: sd.signature,
56 body,
57 reserved: [0; 12],
58 q1: sd.q1,
59 q2: sd.q2,
60 })
61 }
62
63 pub fn author(&self) -> Author {
64 self.author
65 }
66
67 pub fn body(&self) -> Body {
68 self.body
69 }
70}
71
72#[cfg(test)]
73mod test {
74 use super::Signature;
75 use testaso::testaso;
76
77 testaso! {
78 struct Signature: 4, 1808 => {
79 author: 0,
80 modulus: 128,
81 exponent: 512,
82 signature: 516,
83 body: 900,
84 reserved: 1028,
85 q1: 1040,
86 q2: 1424
87 }
88 }
89}