MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / deterministic_policy_hash

Function deterministic_policy_hash

crates/openshell-server/src/grpc/policy.rs:3097–3116  ·  view source on GitHub ↗

Compute a deterministic SHA-256 hash of a `SandboxPolicy`.

(policy: &ProtoSandboxPolicy)

Source from the content-addressed store, hash-verified

3095
3096/// Compute a deterministic SHA-256 hash of a `SandboxPolicy`.
3097fn deterministic_policy_hash(policy: &ProtoSandboxPolicy) -> String {
3098 let mut hasher = Sha256::new();
3099 hasher.update(policy.version.to_le_bytes());
3100 if let Some(fs) = &policy.filesystem {
3101 hasher.update(fs.encode_to_vec());
3102 }
3103 if let Some(ll) = &policy.landlock {
3104 hasher.update(ll.encode_to_vec());
3105 }
3106 if let Some(p) = &policy.process {
3107 hasher.update(p.encode_to_vec());
3108 }
3109 let mut entries: Vec<_> = policy.network_policies.iter().collect();
3110 entries.sort_by_key(|(k, _)| k.as_str());
3111 for (key, value) in entries {
3112 hasher.update(key.as_bytes());
3113 hasher.update(value.encode_to_vec());
3114 }
3115 hex::encode(hasher.finalize())
3116}
3117
3118/// Compute a fingerprint for the effective sandbox configuration.
3119fn compute_config_revision(

Callers 4

compute_config_revisionFunction · 0.85

Calls 1

as_strMethod · 0.45

Tested by

no test coverage detected