Skip to content

Commit f6815b5

Browse files
Merge pull request rpgp#393 from wiktor-k/wiktor/make-hash-sig-more-flexible
feat: Make `SignatureConfig::hash_signature_data` more flexible
2 parents f72dd65 + c6d6b2c commit f6815b5

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/packet/signature/config.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl SignatureConfig {
182182
}
183183

184184
self.hash_data_to_sign(&mut *hasher, data)?;
185-
let len = self.hash_signature_data(&mut *hasher)?;
185+
let len = self.hash_signature_data(&mut hasher)?;
186186
hasher.update(&self.trailer(len)?);
187187

188188
let hash = &hasher.finish()[..];
@@ -272,7 +272,7 @@ impl SignatureConfig {
272272
// the packet content
273273
hasher.update(&packet_buf);
274274

275-
let len = self.hash_signature_data(&mut *hasher)?;
275+
let len = self.hash_signature_data(&mut hasher)?;
276276
hasher.update(&self.trailer(len)?);
277277

278278
let hash = &hasher.finish()[..];
@@ -318,7 +318,7 @@ impl SignatureConfig {
318318
// Key being bound
319319
key.serialize_for_hashing(&mut hasher)?;
320320

321-
let len = self.hash_signature_data(&mut *hasher)?;
321+
let len = self.hash_signature_data(&mut hasher)?;
322322
hasher.update(&self.trailer(len)?);
323323

324324
let hash = &hasher.finish()[..];
@@ -356,7 +356,7 @@ impl SignatureConfig {
356356

357357
key.serialize_for_hashing(&mut hasher)?;
358358

359-
let len = self.hash_signature_data(&mut *hasher)?;
359+
let len = self.hash_signature_data(&mut hasher)?;
360360
hasher.update(&self.trailer(len)?);
361361

362362
let hash = &hasher.finish()[..];
@@ -372,7 +372,7 @@ impl SignatureConfig {
372372
}
373373

374374
/// Calculate the serialized version of this packet, but only the part relevant for hashing.
375-
pub fn hash_signature_data(&self, hasher: &mut dyn Hasher) -> Result<usize> {
375+
pub fn hash_signature_data(&self, hasher: &mut dyn std::io::Write) -> Result<usize> {
376376
match self.version() {
377377
SignatureVersion::V2 | SignatureVersion::V3 => {
378378
let created = {
@@ -389,7 +389,7 @@ impl SignatureConfig {
389389
buf[0] = self.typ.into();
390390
BigEndian::write_u32(&mut buf[1..], created.timestamp().try_into()?);
391391

392-
hasher.update(&buf);
392+
hasher.write_all(&buf)?;
393393

394394
// no trailer
395395
Ok(0)
@@ -424,7 +424,7 @@ impl SignatureConfig {
424424

425425
res.extend(hashed_subpackets);
426426

427-
hasher.update(&res);
427+
hasher.write_all(&res)?;
428428

429429
Ok(res.len())
430430
}

src/packet/signature/types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl Signature {
220220
} else {
221221
self.config.hash_data_to_sign(&mut *hasher, data)?;
222222
}
223-
let len = self.config.hash_signature_data(&mut *hasher)?;
223+
let len = self.config.hash_signature_data(&mut hasher)?;
224224
hasher.update(&self.config.trailer(len)?);
225225

226226
let hash = &hasher.finish()[..];
@@ -307,7 +307,7 @@ impl Signature {
307307
hasher.update(&packet_buf);
308308
}
309309

310-
let len = self.config.hash_signature_data(&mut *hasher)?;
310+
let len = self.config.hash_signature_data(&mut hasher)?;
311311
hasher.update(&self.config.trailer(len)?);
312312

313313
let hash = &hasher.finish()[..];
@@ -390,7 +390,7 @@ impl Signature {
390390
hasher.update(&key_buf);
391391
}
392392

393-
let len = self.config.hash_signature_data(&mut *hasher)?;
393+
let len = self.config.hash_signature_data(&mut hasher)?;
394394
hasher.update(&self.config.trailer(len)?);
395395

396396
let hash = &hasher.finish()[..];
@@ -426,7 +426,7 @@ impl Signature {
426426
hasher.update(&key_buf);
427427
}
428428

429-
let len = self.config.hash_signature_data(&mut *hasher)?;
429+
let len = self.config.hash_signature_data(&mut hasher)?;
430430
hasher.update(&self.config.trailer(len)?);
431431

432432
let hash = &hasher.finish()[..];

0 commit comments

Comments
 (0)