@@ 36,16 36,11 @@ pub fn send(
// Send recipient ID.
stream.send(&recipient.0)?;
// Read recipient's keys.
- let keys_length = stream.receive(4)?.try_into().unwrap();
- let keys_length = u32::from_be_bytes(keys_length) as usize;
- if keys_length == 0 {
+ let num_keys = stream.receive(1)?[0];
+ if num_keys == 0 {
return Err(ServerError::RecipientNotFound);
}
- // If we got an evil length, return error so we don't panic trying to convert the chunks to keys.
- if keys_length % PUBLICKEYBYTES != 0 {
- return Err(ServerError::BadServer("invalid recipient keys"));
- }
- let keys_buf = stream.receive(keys_length)?;
+ let keys_buf = stream.receive(num_keys as usize * PUBLICKEYBYTES)?;
let keys = keys_buf.chunks(PUBLICKEYBYTES).map(|k| PublicKey::from_slice(k).unwrap());
for (i, key) in keys.enumerate() {
let copy = encrypt_message(account, &recipient, &key, &message);