Skip to content

Commit c50efaf

Browse files
committed
Fix encoding of KeyConstraint::Extension
Unlike an `Extension` message's `Unparsed` bytes, the `Unparsed` field of a `KeyConstraint::Extension` is tagged with its `u32` length. This commit fixes up `impl Encode for KeyConstraint` so that it calls `encoded_len_prefixed()` and `encode_prefixed()` to get the correct, length-tagged `bytes[]` on the wire. Signed-off-by: Ross Williams <ross@ross-williams.net>
1 parent 5c29767 commit c50efaf

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/proto/message.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ impl Encode for KeyConstraint {
446446
Self::Extension(extension) => [
447447
base,
448448
extension.name.encoded_len()?,
449-
extension.details.encoded_len()?,
449+
extension.details.encoded_len_prefixed()?,
450450
]
451451
.checked_sum(),
452452
}
@@ -462,7 +462,7 @@ impl Encode for KeyConstraint {
462462
Self::Extension(extension) => {
463463
255u8.encode(writer)?;
464464
extension.name.encode(writer)?;
465-
extension.details.encode(writer)
465+
extension.details.encode_prefixed(writer)
466466
}
467467
}
468468
}
@@ -984,6 +984,7 @@ mod tests {
984984

985985
let mut buf = vec![];
986986
expected.encode(&mut buf).expect("serialize message");
987+
assert_eq!(expected.encoded_len().expect("len message"), buf.len());
987988
assert_eq!(buf, msg);
988989

989990
let msg: &[u8] = &hex!(
@@ -1108,6 +1109,7 @@ mod tests {
11081109

11091110
let mut buf = vec![];
11101111
expected.encode(&mut buf).expect("serialize message");
1112+
assert_eq!(expected.encoded_len().expect("len message"), buf.len());
11111113
assert_eq!(buf, msg);
11121114
}
11131115

0 commit comments

Comments
 (0)