avoid lifetimes in blob reader/writer

This commit is contained in:
Wolfgang Bumiller
2019-08-16 09:19:01 +02:00
committed by Dietmar Maurer
parent 71d08e00b7
commit 9025312aa6
10 changed files with 98 additions and 79 deletions

View File

@ -1,16 +1,30 @@
use failure::*;
use std::sync::Arc;
use std::io::Write;
pub struct ChecksumWriter<'a, W> {
use failure::*;
use super::CryptConfig;
use crate::tools::borrow::Tied;
pub struct ChecksumWriter<W> {
writer: W,
hasher: crc32fast::Hasher,
signer: Option<openssl::sign::Signer<'a>>,
signer: Option<Tied<Arc<CryptConfig>, openssl::sign::Signer<'static>>>,
}
impl <'a, W: Write> ChecksumWriter<'a, W> {
impl <W: Write> ChecksumWriter<W> {
pub fn new(writer: W, signer: Option<openssl::sign::Signer<'a>>) -> Self {
pub fn new(writer: W, config: Option<Arc<CryptConfig>>) -> Self {
let hasher = crc32fast::Hasher::new();
let signer = match config {
Some(config) => {
let tied_signer = Tied::new(config.clone(), |config| {
Box::new(unsafe { (*config).data_signer() })
});
Some(tied_signer)
}
None => None,
};
Self { writer, hasher, signer }
}
@ -27,7 +41,7 @@ impl <'a, W: Write> ChecksumWriter<'a, W> {
}
}
impl <'a, W: Write> Write for ChecksumWriter<'a, W> {
impl <W: Write> Write for ChecksumWriter<W> {
fn write(&mut self, buf: &[u8]) -> Result<usize, std::io::Error> {
self.hasher.update(buf);