feat(controller/utils): add bunch of zeroizers

This commit is contained in:
spushk 2026-05-16 10:29:55 +05:00 • committed by spushk
commit e357f87b43
Signed by: spushk
GPG key ID: 7797B761E105E8AA
2 changed files with 32 additions and 1 deletions

View file

@ -1 +1 @@
pub mod zeroizers;

View file

@ -0,0 +1,31 @@
use zeroize::Zeroize;
#[inline]
pub fn zeroize_bytestring(this: &mut k8s_openapi::ByteString) {
this.0.zeroize();
}
#[inline]
pub fn zeroize_btree<K, T: Zeroize>(this: &mut std::collections::BTreeMap<K, T>) {
this.values_mut().for_each(|v| v.zeroize());
}
#[inline]
pub fn zeroize_btree_of_bytestring<K>(this: &mut std::collections::BTreeMap<K, k8s_openapi::ByteString>) {
this.values_mut().for_each(zeroize_bytestring);
}
#[inline]
pub fn zeroize_hashmap<K, T: Zeroize>(this: &mut std::collections::HashMap<K, T>) {
this.values_mut().for_each(|v| v.zeroize());
}
#[inline]
pub fn zeroize_k8s_secret(this: &mut k8s_openapi::api::core::v1::Secret) {
if let Some(data) = this.data.as_mut() {
zeroize_btree_of_bytestring(data);
}
if let Some(data) = this.string_data.as_mut() {
zeroize_btree(data);
}
}