Skip to main content

verifyos_cli/rules/
private_api.rs

1use crate::parsers::macho_scanner::scan_private_api_from_app_bundle;
2use crate::rules::core::{
3    AppStoreRule, ArtifactContext, RuleCategory, RuleError, RuleReport, RuleStatus, Severity,
4};
5
6pub struct PrivateApiRule;
7
8impl AppStoreRule for PrivateApiRule {
9    fn id(&self) -> &'static str {
10        "RULE_PRIVATE_API"
11    }
12
13    fn name(&self) -> &'static str {
14        "Private API Usage Detected"
15    }
16
17    fn category(&self) -> RuleCategory {
18        RuleCategory::ThirdParty
19    }
20
21    fn severity(&self) -> Severity {
22        Severity::Warning
23    }
24
25    fn recommendation(&self) -> &'static str {
26        "Remove private API usage or replace with public alternatives."
27    }
28
29    fn evaluate(&self, artifact: &ArtifactContext) -> Result<RuleReport, RuleError> {
30        let scan = match scan_private_api_from_app_bundle(artifact.app_bundle_path) {
31            Ok(scan) => scan,
32            Err(err) => {
33                return Ok(RuleReport {
34                    status: RuleStatus::Skip,
35                    message: Some(format!("Private API scan skipped: {err}")),
36                    evidence: None,
37                });
38            }
39        };
40
41        if scan.hits.is_empty() {
42            return Ok(RuleReport {
43                status: RuleStatus::Pass,
44                message: None,
45                evidence: None,
46            });
47        }
48
49        Ok(RuleReport {
50            status: RuleStatus::Fail,
51            message: Some("Private API signatures found".to_string()),
52            evidence: Some(scan.hits.join(", ")),
53        })
54    }
55}