I am trying to use the pkcs8 crate to load a private key but getting compilation error that I am not sure how to fix.
My code is basically like this
fn load_private_key_from_pem(private_key_path: &str) -> PrivateKeyInfo<'static> {
let byte_slice: &[u8] = &fs::read(private_key_path).expect("Loading pem file failed");
PrivateKeyInfo::from_pem(byte_slice).expect("Decoding private key pem file failed")
}
But this fails with the compilation error
error: implementation of `pkcs8::der::Decode` is not general enough
--> src/tests/load_pem.rs:147:5
|
147 | PrivateKeyInfo::from_pem(byte_slice).expect("Decoding private key pem file failed")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `pkcs8::der::Decode` is not general enough
|
= note: `PrivateKeyInfo<'_>` must implement `pkcs8::der::Decode<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `pkcs8::der::Decode<'1>`, for some specific lifetime `'1`
What is the explanation behind this error? And how would go about fixing it?