fn verify_payload(mut signed: Signed, pem_public_key: &[u8]) -> Result<Vec<u8>, ()> {
    let (_, pem) = x509_parser::pem::parse_x509_pem(pem_public_key).map_err(|_| ())?;
    let (_, spki) =
        x509_parser::prelude::SubjectPublicKeyInfo::from_der(&pem.contents).map_err(|_| ())?;
    let payload = signed.take_payload();
    let verification = ring::signature::UnparsedPublicKey::new(
        &ring::signature::RSA_PKCS1_2048_8192_SHA512,
        &spki.subject_public_key,
    )
    .verify(payload.as_slice(), signed.get_signature());

    if verification.is_ok() {
        Ok(payload)
    } else {
        Err(())
    }
}
// To quote the docs:
//
// > All resources will be signed by the repository's private key.
// > A signed resource is wrapped in a Signed message. The data under
// > the payload field is signed by the signature field.
// >
// > The signature is an (unencoded) RSA signature of the (unencoded)
// > SHA-512 digest of the payload.
//
// https://github.com/hexpm/specifications/blob/master/registry-v2.md#signing
//
To quote the docs:
> All resources will be signed by the repository's private key.
> A signed resource is wrapped in a Signed message. The data under
> the payload field is signed by the signature field.
>
> The signature is an (unencoded) RSA signature of the (unencoded)
> SHA-512 digest of the payload.


To quote the docs : > All resources will be signed by the repository ' s private key . > A signed resource is wrapped in a Signed message . The data under > the payload field is signed by the signature field . > > The signature is an ( unencoded ) RSA signature of the ( unencoded ) > SHA - 512 digest of the payload .
fn verify_payload(mut signed: Signed, pem_public_key: &[u8]) -> Result<Vec<u8>, ()> {
    let (_, pem) = x509_parser::pem::parse_x509_pem(pem_public_key).map_err(|_| ())?;
    let (_, spki) =
        x509_parser::prelude::SubjectPublicKeyInfo::from_der(&pem.contents).map_err(|_| ())?;
    let payload = signed.take_payload();
    let verification = ring::signature::UnparsedPublicKey::new(
        &ring::signature::RSA_PKCS1_2048_8192_SHA512,
        &spki.subject_public_key,
    )
    .verify(payload.as_slice(), signed.get_signature());
    if verification.is_ok() {
        Ok(payload)
    } else {
        Err(())
    }
}
fn verify_payload ( mut signed : Signed , pem_public_key : & [ u8 ] ) -> Result < Vec < u8 > , ( ) > { let ( _ , pem ) = x509_parser :: pem :: parse_x509_pem ( pem_public_key ) . map_err ( | _ | ( ) ) ? ; let ( _ , spki ) = x509_parser :: prelude :: SubjectPublicKeyInfo :: from_der ( & pem . contents ) . map_err ( | _ | ( ) ) ? ; let payload = signed . take_payload ( ) ; let verification = ring :: signature :: UnparsedPublicKey :: new ( & ring :: signature :: RSA_PKCS1_2048_8192_SHA512 , & spki . subject_public_key , ) . verify ( payload . as_slice ( ) , signed . get_signature ( ) ) ; if verification . is_ok ( ) { Ok ( payload ) } else { Err ( ( ) ) } }
To quote the docs:
> All resources will be signed by the repository's private key.
To quote the docs : > All resources will be signed by the repository ' s private key .
signed
Signed
pem_public_key
&[u8]
signed
Signed
pem_public_key
&[u8]