Skip to content

Commit

Permalink
Merge latest master
Browse files Browse the repository at this point in the history
  • Loading branch information
AgeManning committed Jun 17, 2024
2 parents 60e53e4 + 497349d commit 9675b59
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
25 changes: 24 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
# Generated by Cargo
# will have compiled files and executables
debug/
target/

# This project does not check in Cargo.lock
Cargo.lock
target

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# Generated by Intellij-based IDEs.
.idea

# Generated by MacOS
.DS_Store

# VSCode
.vscode

# Rust bug report
rustc-ice-*
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ sha3 = "0.10"
k256 = { version = "0.13", features = ["ecdsa"], optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
ed25519-dalek = { version = "2.1.1", optional = true, features = ["rand_core"] }
secp256k1 = { version = "0.28", optional = true, default-features = false, features = [
secp256k1 = { version = "0.29", optional = true, default-features = false, features = [
"global-context",
] }

[dev-dependencies]
alloy-rlp = { version = "0.3.4", features = ["derive"] }
secp256k1 = { version = "0.28", features = ["rand-std"] }
secp256k1 = { version = "0.29", features = ["rand-std"] }
serde_json = "1.0"

[features]
Expand Down
29 changes: 24 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1088,12 +1088,19 @@ impl<K: EnrKey> Decodable for Enr<K> {
_ => {
let other_header = Header::decode(payload)?;
let value = &payload[..other_header.payload_length];
// Preserve the valid encoding
payload.advance(other_header.payload_length);
let mut out = Vec::<u8>::new();
other_header.encode(&mut out);
out.extend_from_slice(value);
out

// Encode the header for list values, for non-list objects, we remove the
// header for compatibility with commonly used key entries (i.e it's the
// current convention).
if other_header.list {
let mut out = Vec::<u8>::new();
other_header.encode(&mut out);
out.extend_from_slice(value);
out
} else {
alloy_rlp::encode(value)
}
}
};
content.insert(key.to_vec(), Bytes::from(value));
Expand Down Expand Up @@ -2082,4 +2089,16 @@ mod tests {
assert_eq!(info.1, "v1.0.0");
assert_eq!(info.2, None);
}
/// Tests a common ENR which uses RLP encoded values without the header
#[test]
fn test_common_rlp_convention() {
const COMMON_VALID_ENR: &str = concat!(
"-LW4QCAyOCtqvQjd8AgpqbaCgfjy8oN8cBBRT5jtzarkGJQWZx1eN70EM0QafVCugLa-Bv493DPNzflagqfTOsWSF78Ih2F0d",
"G5ldHOIAGAAAAAAAACEZXRoMpBqlaGpBAAAAP__________gmlkgnY0hHF1aWOCIymJc2VjcDI1NmsxoQPg_HgqXzwRIK39Oy",
"lGdC30YUFwsfXvATnGUvEZ6MtBQIhzeW5jbmV0cwCDdGNwgiMo"
);

// Expect this to be able to be decoded
let _decoded: DefaultEnr = COMMON_VALID_ENR.parse().unwrap();
}
}

0 comments on commit 9675b59

Please sign in to comment.