RSA icon indicating copy to clipboard operation
RSA copied to clipboard

Parsing `rsa::pkcs1v15::Signature` from DER bit string

Open zhengyao-lin opened this issue 1 year ago • 3 comments

Hello! I'm trying to use this crate for verifying RSA PKCS1 signatures in X.509 certificates.

What's the best way to parse a DER BitString and get a rsa::pkcs1v15::Signature out of it? I see that there is impl SignatureBitStringEncoding for Signature to output bit string, but there doesn't seem to be anything for the inverse.

Thank you!

zhengyao-lin avatar Sep 30 '24 17:09 zhengyao-lin

What type is the BIT STRING represented as? Do you need to parse it first? Does it have a DER header?

tarcieri avatar Sep 30 '24 17:09 tarcieri

Right now it’s a DER BIT STRING (with tag and length), but I can tweak it if needed.

zhengyao-lin avatar Sep 30 '24 18:09 zhengyao-lin

You can use der::asn1::BitStringRef to parse it, and as_bytes() to obtain &[u8].

In the next release we can add a TryFrom<BitStringRef<'_>> impl.

tarcieri avatar Sep 30 '24 18:09 tarcieri