Compute a deterministic SHA-256 hash of a `SandboxPolicy`.
(policy: &ProtoSandboxPolicy)
| 3095 | |
| 3096 | /// Compute a deterministic SHA-256 hash of a `SandboxPolicy`. |
| 3097 | fn 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. |
| 3119 | fn compute_config_revision( |
no test coverage detected