encryption/asymmetric/
mod.rs1pub mod ecdh;
15pub mod ecdsa;
16pub mod ed25519;
17pub mod rsa;
18pub mod x25519;
19
20pub use rsa::{RsaOaepSha256Cipher, RsaOaepSha256Service};
21
22#[derive(Clone, PartialEq, Eq)]
27pub struct KeyPairHex {
28 pub private_key_hex: String,
29 pub public_key_hex: String,
30}
31
32impl std::fmt::Debug for KeyPairHex {
33 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34 f.debug_struct("KeyPairHex")
35 .field("private_key_hex", &"***")
36 .field("public_key_hex", &self.public_key_hex)
37 .finish()
38 }
39}
40
41impl KeyPairHex {
42 pub fn public_only(&self) -> &str {
44 &self.public_key_hex
45 }
46}
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
55 fn debug_redacts_the_private_key() {
56 let pair = KeyPairHex {
57 private_key_hex: "deadbeef".repeat(8),
58 public_key_hex: "cafebabe".repeat(8),
59 };
60 let text = format!("{pair:?}");
61 assert!(!text.contains("deadbeef"), "私钥泄漏进 Debug: {text}");
62 assert!(text.contains("cafebabe"), "公钥应照常打印: {text}");
63 assert!(text.contains("***"));
64 }
65
66 #[test]
68 fn debug_redaction_keeps_value_semantics() {
69 let pair = KeyPairHex {
70 private_key_hex: "aa".repeat(32),
71 public_key_hex: "bb".repeat(33),
72 };
73 assert_eq!(pair.clone(), pair);
74 assert_eq!(pair.public_only(), pair.public_key_hex);
75 }
76}