Skip to content

x509-cert: How to use dynamic signer with Builder? #1160

@jstayton

Description

@jstayton

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions