Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade prost to 0.8 #335

Merged
merged 1 commit into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions rust/protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ arrayref = "0.3.6"
async-trait = "0.1.41"
block-modes = "0.8"
hmac = "0.9.0"
prost = "0.7"
prost = "0.8"
rand = "0.7.3"
sha2 = "0.9"
subtle = "2.2.3"
Expand Down Expand Up @@ -46,7 +46,7 @@ criterion = "0.3"
futures-util = "0.3.7"

[build-dependencies]
prost-build = "0.7"
prost-build = "0.8"

[[bench]]
name = "session"
Expand Down
4 changes: 1 addition & 3 deletions rust/protocol/src/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ impl ScannableFingerprint {
}),
};

let mut buf = Vec::new();
combined_fingerprints.encode(&mut buf)?;
Ok(buf)
Ok(combined_fingerprints.encode_to_vec())
}

pub fn compare(&self, combined: &[u8]) -> Result<bool> {
Expand Down
5 changes: 1 addition & 4 deletions rust/protocol/src/identity_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,8 @@ impl IdentityKeyPair {
public_key: self.identity_key.serialize().to_vec(),
private_key: self.private_key.serialize().to_vec(),
};
let mut result = Vec::new();

// prost documents the only possible encoding error is if there is insufficient
// space, which is not a problem when it is allowed to encode into a Vec
structure.encode(&mut result).expect("No encoding error");
let result = structure.encode_to_vec();
result.into_boxed_slice()
}
}
Expand Down
29 changes: 11 additions & 18 deletions rust/protocol/src/sealed_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,15 @@ impl ServerCertificate {
key: Some(key.serialize().to_vec()),
};

let mut certificate = vec![];
certificate_pb.encode(&mut certificate)?;
let certificate = certificate_pb.encode_to_vec();

let signature = trust_root.calculate_signature(&certificate, rng)?.to_vec();

let mut serialized = vec![];
let pb = proto::sealed_sender::ServerCertificate {
let serialized = proto::sealed_sender::ServerCertificate {
certificate: Some(certificate.clone()),
signature: Some(signature.clone()),
};
pb.encode(&mut serialized)?;
}
.encode_to_vec();

Ok(Self {
serialized,
Expand Down Expand Up @@ -192,8 +190,7 @@ impl SenderCertificate {
.ok_or(SignalProtocolError::InvalidProtobufEncoding)?[..],
)?;

let mut signer_bits = vec![];
signer_pb.encode(&mut signer_bits)?;
let signer_bits = signer_pb.encode_to_vec();
let signer = ServerCertificate::deserialize(&signer_bits)?;

Ok(Self {
Expand Down Expand Up @@ -228,17 +225,15 @@ impl SenderCertificate {
signer: Some(signer.to_protobuf()?),
};

let mut certificate = vec![];
certificate_pb.encode(&mut certificate)?;
let certificate = certificate_pb.encode_to_vec();

let signature = signer_key.calculate_signature(&certificate, rng)?.to_vec();

let pb = proto::sealed_sender::SenderCertificate {
let serialized = proto::sealed_sender::SenderCertificate {
certificate: Some(certificate.clone()),
signature: Some(signature.clone()),
};
let mut serialized = vec![];
pb.encode(&mut serialized)?;
}
.encode_to_vec();

Ok(Self {
signer,
Expand Down Expand Up @@ -477,8 +472,7 @@ impl UnidentifiedSenderMessageContent {
}),
};

let mut serialized = vec![];
msg.encode(&mut serialized)?;
let serialized = msg.encode_to_vec();

Ok(Self {
serialized,
Expand Down Expand Up @@ -1273,8 +1267,7 @@ fn test_lossless_round_trip() -> Result<()> {
// };
//
// eprintln!("<SNIP>");
// let mut serialized_certificate_data = vec![];
// sender_cert.encode(&mut serialized_certificate_data).expect("can't fail encoding to Vec");
// let serialized_certificate_data = sender_cert.encode_to_vec();
// let certificate_data_encoded = hex::encode(&serialized_certificate_data);
// eprintln!("let certificate_data_encoded = \"{}\";", certificate_data_encoded);
//
Expand Down
8 changes: 2 additions & 6 deletions rust/protocol/src/sender_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ impl SenderKeyState {
}

pub fn serialize(&self) -> Result<Vec<u8>> {
let mut buf = vec![];
self.state.encode(&mut buf)?;
Ok(buf)
Ok(self.state.encode_to_vec())
}

pub fn message_version(&self) -> Result<u32> {
Expand Down Expand Up @@ -359,8 +357,6 @@ impl SenderKeyRecord {
}

pub fn serialize(&self) -> Result<Vec<u8>> {
let mut buf = vec![];
self.as_protobuf()?.encode(&mut buf)?;
Ok(buf)
Ok(self.as_protobuf()?.encode_to_vec())
}
}
4 changes: 1 addition & 3 deletions rust/protocol/src/state/prekey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ impl PreKeyRecord {
}

pub fn serialize(&self) -> Result<Vec<u8>> {
let mut buf = vec![];
self.pre_key.encode(&mut buf)?;
Ok(buf)
Ok(self.pre_key.encode_to_vec())
}
}
5 changes: 1 addition & 4 deletions rust/protocol/src/state/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,14 +585,11 @@ impl SessionRecord {
}

pub fn serialize(&self) -> Result<Vec<u8>> {
let mut buf = vec![];

let record = RecordStructure {
current_session: self.current_session.as_ref().map(|s| s.into()),
previous_sessions: self.previous_sessions.iter().map(|s| s.into()).collect(),
};
record.encode(&mut buf)?;
Ok(buf)
Ok(record.encode_to_vec())
}

pub fn remote_registration_id(&self) -> Result<u32> {
Expand Down
4 changes: 1 addition & 3 deletions rust/protocol/src/state/signed_prekey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ impl SignedPreKeyRecord {
}

pub fn serialize(&self) -> Result<Vec<u8>> {
let mut buf = vec![];
self.signed_pre_key.encode(&mut buf)?;
Ok(buf)
Ok(self.signed_pre_key.encode_to_vec())
}
}