Skip to content

Public Key crypto: add support for encoding/decoding to/from Subject Public Key Info (SPKI) and signature #73

@bgrieder

Description

@bgrieder

Subject Public Key Info [RFC 5280 § 4.1.2.7] is the format of Public Keys found in Certificates Signing Requests and Certificates.

RSA

PKCS#1 is the format used by the BitString of Subject Public Key Infos in Certificate Signing Requests and Certificates.

This is a simple addition; the rsa crate already offers some facilities.

let rsa_public_key =
        rsa::RsaPublicKey::from_pkcs1_der(spki.subject_public_key.as_bytes().unwrap())
            .unwrap();

where spki is a spki::SubjectPublicKeyInfo

Nist Elliptic Curves

NIST EC offers direct deserialization via elliptic_curve::DecodedKey trait and this impl.

impl<T> DecodePublicKey for T
where
    T: for<'a> [TryFrom](https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html)<SubjectPublicKeyInfo<AnyRef<'a>, BitStringRef<'a>>, Error = Error>,

///Deserialize object from ASN.1 DER-encoded [SubjectPublicKeyInfo] (binary format).
fn from_public_key_der(bytes: &[u8]) -> Result<T, Error>
  let pk = p256::PublicKey::from_public_key_der(csr.info.public_key.to_der().unwrap().as_slice())
        .unwrap();

Curve25519

? (TODO)

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