Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(pii): widen visibility of PII validation and normalization helpers

Steven Enamakel24fb17281cd5
diff --git a/crates/openhuman-core/src/memory/safety/pii/checksums.rs b/crates/openhuman-core/src/memory/safety/pii/checksums.rs
index a5512d7461..5f0cf046e5 100644
--- a/crates/openhuman-core/src/memory/safety/pii/checksums.rs
+++ b/crates/openhuman-core/src/memory/safety/pii/checksums.rs
@@ -8,14 +8,14 @@
// ---------- Checksum and structural validators for PII candidates ----------
-pub(super) fn digits(s: &str) -> Vec<u32> {
+pub(crate) fn digits(s: &str) -> Vec<u32> {
s.chars()
.filter(|c| c.is_ascii_digit())
.map(|c| c.to_digit(10).expect("ascii digit"))
.collect()
}
-pub(super) fn valid_cpf(d: &[u32]) -> bool {
+pub(crate) fn valid_cpf(d: &[u32]) -> bool {
if d.len() != 11 || d.iter().all(|x| *x == d[0]) {
return false;
}
@@ -29,7 +29,7 @@ pub(super) fn valid_cpf(d: &[u32]) -> bool {
dv2 == d[10]
}
-pub(super) fn valid_cnpj(d: &[u32]) -> bool {
+pub(crate) fn valid_cnpj(d: &[u32]) -> bool {
if d.len() != 14 || d.iter().all(|x| *x == d[0]) {
return false;
}
@@ -47,7 +47,7 @@ pub(super) fn valid_cnpj(d: &[u32]) -> bool {
dv2 == d[13]
}
-pub(super) fn valid_cuit(d: &[u32]) -> bool {
+pub(crate) fn valid_cuit(d: &[u32]) -> bool {
if d.len() != 11 {
return false;
}
@@ -63,7 +63,7 @@ pub(super) fn valid_cuit(d: &[u32]) -> bool {
}
// Luhn — used for credit-card validation.
-pub(super) fn valid_luhn(s: &str) -> bool {
+pub(crate) fn valid_luhn(s: &str) -> bool {
let d = digits(s);
if d.len() < 13 || d.len() > 19 {
return false;
@@ -89,7 +89,7 @@ pub(super) fn valid_luhn(s: &str) -> bool {
// IBAN mod-97. Steps: strip spaces, move first 4 chars to end, expand letters
// (A=10..Z=35), divide as a big-integer mod 97, require remainder == 1.
-pub(super) fn valid_iban(s: &str) -> bool {
+pub(crate) fn valid_iban(s: &str) -> bool {
let cleaned: String = s.chars().filter(|c| !c.is_whitespace()).collect();
if cleaned.len() < 15 || cleaned.len() > 34 {
return false;
@@ -145,7 +145,7 @@ const VERHOEFF_P: [[u8; 10]; 8] = [
[7, 0, 4, 6, 9, 1, 3, 2, 5, 8],
];
-pub(super) fn valid_verhoeff(d: &[u32]) -> bool {
+pub(crate) fn valid_verhoeff(d: &[u32]) -> bool {
if d.len() != 12 {
return false;
}
@@ -161,7 +161,7 @@ pub(super) fn valid_verhoeff(d: &[u32]) -> bool {
}
// US SSN reserved/invalid ranges per SSA.
-pub(super) fn valid_ssn(s: &str) -> bool {
+pub(crate) fn valid_ssn(s: &str) -> bool {
let d = digits(s);
if d.len() != 9 {
return false;
@@ -181,7 +181,7 @@ pub(super) fn valid_ssn(s: &str) -> bool {
// Spain DNI check letter — 8 digits mod 23 indexes into a fixed letter table.
const DNI_LETTERS: &[u8; 23] = b"TRWAGMYFPDXBNJZSQVHLCKE";
-pub(super) fn valid_dni_es(s: &str) -> bool {
+pub(crate) fn valid_dni_es(s: &str) -> bool {
let upper = s.to_ascii_uppercase();
let bytes = upper.as_bytes();
if bytes.len() != 9 {
@@ -195,7 +195,7 @@ pub(super) fn valid_dni_es(s: &str) -> bool {
DNI_LETTERS[(num % 23) as usize] == letter
}
-pub(super) fn valid_nie_es(s: &str) -> bool {
+pub(crate) fn valid_nie_es(s: &str) -> bool {
let upper = s.to_ascii_uppercase();
let bytes = upper.as_bytes();
if bytes.len() != 9 {
@@ -218,7 +218,7 @@ pub(super) fn valid_nie_es(s: &str) -> bool {
}
// UK NINO reserved-prefix blacklist.
-pub(super) fn valid_nino(s: &str) -> bool {
+pub(crate) fn valid_nino(s: &str) -> bool {
let upper = s.to_ascii_uppercase();
let bytes = upper.as_bytes();
if bytes.len() != 9 {
diff --git a/crates/openhuman-core/src/memory/safety/pii/normalize.rs b/crates/openhuman-core/src/memory/safety/pii/normalize.rs
index ff50e8a833..4941364cd9 100644
--- a/crates/openhuman-core/src/memory/safety/pii/normalize.rs
+++ b/crates/openhuman-core/src/memory/safety/pii/normalize.rs
@@ -13,7 +13,7 @@
// keeping a byte map back to the original string, so matches found on the
// normalized view can be spliced onto the exact original bytes.
-pub(super) struct NormalizedView {
+pub(crate) struct NormalizedView {
pub(super) normalized: String,
// For each byte offset i in `normalized`, `byte_map[i]` is the byte offset
// in the original string where the corresponding char *starts*.
@@ -192,7 +192,7 @@ const MYNUMBER_JP_KEYWORDS: &[&[u8]] = &["マイナンバー".as_bytes(), "個
/// continuation bytes are all `>= 0x80`, so scanning `as_bytes()` for ASCII
/// digits/punctuation/letters is boundary-safe. Keyword probes run over the
/// same byte slice so the non-Latin needles match verbatim.
-pub(super) fn scan_candidates(text: &str) -> Candidates {
+pub(crate) fn scan_candidates(text: &str) -> Candidates {
let bytes = text.as_bytes();
let mut total_digits: usize = 0;