1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//! Information-flow types (§14.10.1, SECRET-XXX).
//!
//! `Secret<T>` carries a value that came from a credential/key/password; the
//! static analyzer (future sprint) will forbid branching, matching, logging,
//! or indexing on it. `Public<T>` marks values that are safe to leak.
//!
//! Today these are newtype wrappers; in a future sprint a dedicated lint
//! pass will enforce the compile-time rules from §14.10.1.
//!
//! Reference: HACL*/F* `Lib.IntTypes.secret` pattern.
use PhantomData;
/// A value classified as secret (credential / key / password / PII).
///
/// The runtime type is a pure wrapper today; the compile-time enforcement
/// (no branching, no matching, no logging, no secret-indexed access) is
/// delivered by the SECRET-002 lint pass in a future sprint.
///
/// # Example
///
/// ```
/// use ruchy::provability::{Secret, declassify};
/// let key: Secret<u64> = Secret::new(0xDEADBEEF);
/// // Future sprint: `if key == ... { ... }` will be a compile error.
/// let leaked: u64 = declassify(key, "test-vector");
/// assert_eq!(leaked, 0xDEADBEEF);
/// ```
/// A value explicitly classified as public.
///
/// `Public<T>` is the dual of `Secret<T>` — it's the type of values that
/// are safe to log, branch on, index arrays with, and return to callers.
/// Every `declassify` result is `Public<T>` by definition.
/// The single canonical escape hatch from `Secret<T>` to `Public<T>`.
///
/// Per §14.10.1 the call site must be marked `#[contract_exempt]` with a
/// reason string; that enforcement is delivered by SECRET-002. For now
/// `declassify` is an ordinary function that takes a `reason: &'static str`
/// to force authors to justify the declassification in code.
///
/// # Example
///
/// ```
/// use ruchy::provability::{Secret, declassify};
/// let s = Secret::new(42u32);
/// let p = declassify(s, "unit-test: no leak of real credentials");
/// assert_eq!(p, 42);
/// ```