Merge rust-bitcoin/rust-bitcoin#809: Use write_all instead of write
22aeaef52b
Use write_all instead of write (Riccardo Casatta) Pull request description: write() could write only a part of the given buffer, the caller should check the numbers of byte written (which is what write_all does) ACKs for top commit: apoelstra: ACK22aeaef52b
Kixunil: ACK22aeaef52b
dr-orlovsky: utACK22aeaef52b
Tree-SHA512: e4bf3c757e1d369f9bb737e970b93ec29a487419eb478b41c36da033eafea3f0a96faa1e5c6f9397febba309ce4330b29a9e5369bb547645e5f72ba935d2cafe
This commit is contained in:
commit
97cc70073b
|
@ -770,7 +770,7 @@ impl ExtendedPubKey {
|
||||||
/// Returns the HASH160 of the chaincode
|
/// Returns the HASH160 of the chaincode
|
||||||
pub fn identifier(&self) -> XpubIdentifier {
|
pub fn identifier(&self) -> XpubIdentifier {
|
||||||
let mut engine = XpubIdentifier::engine();
|
let mut engine = XpubIdentifier::engine();
|
||||||
engine.write(&self.public_key.serialize()).expect("engines don't error");
|
engine.write_all(&self.public_key.serialize()).expect("engines don't error");
|
||||||
XpubIdentifier::from_engine(engine)
|
XpubIdentifier::from_engine(engine)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -147,7 +147,8 @@ impl<Subtype> Encodable for ProprietaryKey<Subtype> where Subtype: Copy + From<u
|
||||||
fn consensus_encode<W: io::Write>(&self, mut e: W) -> Result<usize, io::Error> {
|
fn consensus_encode<W: io::Write>(&self, mut e: W) -> Result<usize, io::Error> {
|
||||||
let mut len = self.prefix.consensus_encode(&mut e)? + 1;
|
let mut len = self.prefix.consensus_encode(&mut e)? + 1;
|
||||||
e.emit_u8(self.subtype.into())?;
|
e.emit_u8(self.subtype.into())?;
|
||||||
len += e.write(&self.key)?;
|
e.write_all(&self.key)?;
|
||||||
|
len += self.key.len();
|
||||||
Ok(len)
|
Ok(len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -615,11 +615,10 @@ impl TaprootMerkleBranch {
|
||||||
|
|
||||||
/// Serialize to a writer. Returns the number of bytes written
|
/// Serialize to a writer. Returns the number of bytes written
|
||||||
pub fn encode<Write: io::Write>(&self, mut writer: Write) -> io::Result<usize> {
|
pub fn encode<Write: io::Write>(&self, mut writer: Write) -> io::Result<usize> {
|
||||||
let mut written = 0;
|
|
||||||
for hash in self.0.iter() {
|
for hash in self.0.iter() {
|
||||||
written += writer.write(hash)?;
|
writer.write_all(hash)?;
|
||||||
}
|
}
|
||||||
Ok(written)
|
Ok(self.0.len() * sha256::Hash::LEN)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Serialize self as bytes
|
/// Serialize self as bytes
|
||||||
|
@ -704,11 +703,10 @@ impl ControlBlock {
|
||||||
/// Serialize to a writer. Returns the number of bytes written
|
/// Serialize to a writer. Returns the number of bytes written
|
||||||
pub fn encode<Write: io::Write>(&self, mut writer: Write) -> io::Result<usize> {
|
pub fn encode<Write: io::Write>(&self, mut writer: Write) -> io::Result<usize> {
|
||||||
let first_byte: u8 = i32::from(self.output_key_parity) as u8 | self.leaf_version.to_consensus();
|
let first_byte: u8 = i32::from(self.output_key_parity) as u8 | self.leaf_version.to_consensus();
|
||||||
let mut bytes_written = 0;
|
writer.write_all(&[first_byte])?;
|
||||||
bytes_written += writer.write(&[first_byte])?;
|
writer.write_all(&self.internal_key.serialize())?;
|
||||||
bytes_written += writer.write(&self.internal_key.serialize())?;
|
self.merkle_branch.encode(&mut writer)?;
|
||||||
bytes_written += self.merkle_branch.encode(&mut writer)?;
|
Ok(self.size())
|
||||||
Ok(bytes_written)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Serialize the control block. This would be required when
|
/// Serialize the control block. This would be required when
|
||||||
|
|
Loading…
Reference in New Issue