I'm running into an interesting problem that can't quite wrap my head around. I'm using the openssl crate and I'm attempting to assign one of the structs there to my own struct
pub struct HmacCtx<'a> {
signer: Signer<'a>,
}
impl <'a> HmacCtx<'a> {
pub fn new(digest: MessageDigest, key: &[u8]) -> Result<Self, HmacError> {
let pkey = PKey::hmac(key)?;
Ok(Self {
signer: Signer::new(digest.into(), &pkey)?
})
}
}
The code above gives me an error saying:
24 | impl <'a> HmacCtx<'a> {
| -- lifetime `'a` defined here
...
28 | signer: Signer::new(digest.into(), &pkey)?
| ---------------------------^^^^^--
| | |
| | borrowed value does not live long enough
| assignment requires that `pkey` is borrowed for `'a`
29 | })
30 | }
| - `pkey` dropped here while still borrowed
I can't seem to see how it is that I make something borrowed for a specific lifetime, I thought I did that by declaring the lifetime in the struct definition. Any help would-be be much appreciated