Add is_hexstring to Pcd trait

This commit is contained in:
Sosthene 2024-11-30 20:05:47 +01:00
parent a786eb8fe0
commit 72a3230952

View File

@ -276,6 +276,27 @@ pub trait Pcd<'a>: Serialize + Deserialize<'a> {
Err(Error::msg("No \"roles\" key in this pcd"))
}
}
fn is_hex_string(&self) -> bool {
let value = match serde_json::to_value(self) {
Ok(v) => v,
Err(_) => return false
};
match value {
Value::String(s) => {
let vec = Vec::from_hex(&s);
if vec.is_err() {
return false;
} else if vec.unwrap().len() != 32 {
return false;
} else {
return true;
}
}
_ => false
}
}
}
impl Pcd<'_> for Value {}