Hey 👋🏻
I'm trying to use a dynamic signer when using RequestBuilder, but I'm running into this:
the size for values of type dyn Signer<_> cannot be known at compilation time
the trait Sized is not implemented for dyn Signer<_>
Here's a distillation of what I'm attempting:
use p256::pkcs8::LineEnding;
use rand_core::OsRng;
use std::error::Error;
use std::str::FromStr;
use x509_cert::{builder::RequestBuilder, name::Name};
fn main() -> Result<(), Box<dyn Error>> {
let req_signer: Box<dyn p256::ecdsa::signature::Signer<_>>;
if true {
req_signer = Box::new(p256::ecdsa::SigningKey::random(&mut OsRng));
} else {
req_signer = Box::new(p384::ecdsa::SigningKey::random(&mut OsRng));
}
let subject = Name::from_str("CN=Test")?;
let csr_builder = RequestBuilder::new(subject, req_signer.as_ref())?; // <--- Error
let csr = csr_builder.build::<p256::ecdsa::DerSignature>()?; // <--- p256 or p384 would need to be used here
let csr_pem = csr.to_pem(LineEnding::LF)?;
println!("{}", csr_pem);
Ok(())
}
Does that make sense? Am I just making a stupid mistake, or approaching this in the wrong way?
Thanks for any help!
Hey 👋🏻
I'm trying to use a dynamic signer when using
RequestBuilder, but I'm running into this:Here's a distillation of what I'm attempting:
Does that make sense? Am I just making a stupid mistake, or approaching this in the wrong way?
Thanks for any help!