fire_crypto/signature/
mod.rs

1//! Contains structs used for signing and verifying.
2
3mod keypair;
4pub use keypair::Keypair;
5
6mod public_key;
7pub use public_key::PublicKey;
8
9mod signature;
10pub use signature::Signature;
11
12// TESTS
13
14#[cfg(test)]
15mod tests {
16
17	use super::*;
18
19	#[cfg(feature = "b64")]
20	use std::str::FromStr;
21
22	#[cfg(feature = "b64")]
23	#[test]
24	pub fn b64() {
25		// keypair
26		let alice = Keypair::new();
27
28		let b64 = alice.to_string();
29		let alice_2 = Keypair::from_str(&b64).unwrap();
30
31		assert_eq!(b64, alice_2.to_string());
32	}
33
34	#[test]
35	pub fn signature_test() {
36		let alice = Keypair::new();
37
38		let msg = b"Hey thats my message";
39
40		let signature = alice.sign(msg);
41
42		assert!(alice.public().verify(msg, &signature));
43	}
44
45	#[cfg(feature = "b64")]
46	#[test]
47	pub fn b64_signature() {
48		let alice = Keypair::new();
49		let msg = b"Hey thats my message";
50		let signature = alice.sign(msg);
51
52		// check b64 signature
53		let b64 = signature.to_string();
54
55		let signature_2 = Signature::from_str(&b64).unwrap();
56
57		assert_eq!(signature, signature_2);
58	}
59
60	#[cfg(feature = "b64")]
61	#[test]
62	pub fn static_keypair_and_signature_test() {
63		let alice =
64			Keypair::from_str("ZMIO9cdDRvhD6QXo9mR94REWV0810FRTXCkoG3mIO8k")
65				.unwrap();
66
67		let msg = b"Hey thats my message";
68
69		let signature = alice.sign(msg);
70		assert_eq!(signature.to_string(), "f5Yg6kEyXCsJTssIlZY8msoGnIuf3tdGvpJclwArp75pA-5W0FQTj9E6Lz2345P0IekLsuK-mmDkfViPcqf_DA");
71
72		assert!(alice.public().verify(msg, &signature));
73	}
74
75	// todo: add test to make sure From<[u8; S]> can not panic
76}