Add is_hexstring to Pcd trait
This commit is contained in:
parent
a786eb8fe0
commit
72a3230952
21
src/pcd.rs
21
src/pcd.rs
@ -276,6 +276,27 @@ pub trait Pcd<'a>: Serialize + Deserialize<'a> {
|
|||||||
Err(Error::msg("No \"roles\" key in this pcd"))
|
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 {}
|
impl Pcd<'_> for Value {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user