Skip to content

Commit

Permalink
chore: update get
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Apr 4, 2024
1 parent 135e0a1 commit 2dcc7a8
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,11 @@ impl<K: EnrKey> Enr<K> {
#[allow(clippy::missing_panics_doc)]
pub fn get(&self, key: impl AsRef<[u8]>) -> Option<Bytes> {
// It's ok to decode any valid RLP value as data
self.get_raw_rlp(key)
.map(|mut rlp_data| Bytes::decode(&mut rlp_data).expect("All data is sanitized"))
self.get_raw_rlp(key).map(|mut rlp_data| {
let mut raw_data = &mut rlp_data;
let header = Header::decode(&mut raw_data).expect("All data is sanitized");
raw_data[..header.payload_length].to_vec().into()
})
}

/// Reads a custom key from the record if it exists, decoded as `T`.
Expand Down Expand Up @@ -1513,7 +1516,6 @@ mod tests {
.unwrap();

let decoded_proto = enr.get_decodable::<Proto>("proto").unwrap().unwrap();

assert_eq!(decoded_proto, proto);
}

Expand Down

0 comments on commit 2dcc7a8

Please sign in to comment.