mkt_ksa_geo_sec/security/secret.rs
1/******************************************************************************************
2 Arabic: طبقة تغليف للأسرار لتثبيت الواجهة داخليًا.
3 English: Secret abstraction layer to stabilize internal interface.
4
5 - الهدف: عدم ربط بقية المشروع مباشرة بأنواع crate `secrecy` حتى نتمكن من
6 ترقية الإصدار لاحقًا (مثل 0.10.x) دون تغيير المنطق في بقية الشيفرة.
7 - الهدف الأمني: الإبقاء على إخفاء Debug/Display ومسح الذاكرة عبر zeroize،
8 مع سهولة الاستبدال لاحقًا.
9******************************************************************************************/
10
11use secrecy::ExposeSecret;
12use secrecy::SecretBox;
13
14/// Arabic: مغلف لمفتاحٍ كسلسلة
15/// English: Wrapper for string-based secret
16pub struct SecureString(SecretBox<String>);
17
18impl SecureString {
19 #[must_use]
20 pub fn new(value: String) -> Self {
21 Self(SecretBox::new(Box::new(value)))
22 }
23
24 #[must_use]
25 pub fn expose(&self) -> &str {
26 self.0.expose_secret()
27 }
28}
29
30/// Arabic: مغلف لمفتاحٍ كبايتات
31/// English: Wrapper for byte-based secret
32pub struct SecureBytes(SecretBox<Vec<u8>>);
33
34impl SecureBytes {
35 #[must_use]
36 pub fn new(bytes: Vec<u8>) -> Self {
37 Self(SecretBox::new(Box::new(bytes)))
38 }
39
40 #[must_use]
41 pub fn expose(&self) -> &[u8] {
42 self.0.expose_secret()
43 }
44}
45
46// Arabic: تحويلات مساعدة للاستخدام التدريجي
47// English: Helper conversions for gradual adoption
48// no cross-version conversions exposed intentionally