pub fn is_cert_authorized(&self) -> Result<bool, Error> {
        if let Some(key) = self.env.cert_key.clone() {
            // search for the public key in the rad keys directory.
            let repo = Repository::open(&self.env.git_dir)?;

            // the path of the public key to verify.
            let key_path = Path::new(DEFAULT_RAD_KEYS_PATH).join(&key);

            // set the namespace for the repo equal to the git namespace env.
            repo.set_namespace(&self.env.git_namespace)?;

            let (refname, _, _) = &self.updates[0];
            let rfc = repo.find_reference(refname)?;

            if let Ok(tree) = rfc.peel_to_tree() {
                if let Ok(entry) = tree.get_path(&key_path) {
                    let obj = entry.to_object(&repo)?;
                    let blob = obj.peel_to_blob()?;
                    let content = std::str::from_utf8(blob.content())?;
                    let (pk, _) = pgp::SignedPublicKey::from_string(content)?;

                    // verify the key on file.
                    pk.verify()?;

                    let key_id = hex::encode(pk.primary_key.key_id().as_ref()).to_uppercase();

                    // check the key matches the key from the signed push certificate.
                    return Ok(key_id == key);
                }
            };
        }

        Ok(false)
    }
/// Check the local repo .rad/keys/ directory for the GPG key matching the cert key
/// used to sign the push certificate.
Check the local repo .rad/keys/ directory for the GPG key matching the cert key
used to sign the push certificate.
Check the local repo . rad / keys / directory for the GPG key matching the cert key used to sign the push certificate .
pub fn is_cert_authorized(&self) -> Result<bool, Error> {
        if let Some(key) = self.env.cert_key.clone() {
            // search for the public key in the rad keys directory.
            let repo = Repository::open(&self.env.git_dir)?;
            // the path of the public key to verify.
            let key_path = Path::new(DEFAULT_RAD_KEYS_PATH).join(&key);
            // set the namespace for the repo equal to the git namespace env.
            repo.set_namespace(&self.env.git_namespace)?;
            let (refname, _, _) = &self.updates[0];
            let rfc = repo.find_reference(refname)?;
            if let Ok(tree) = rfc.peel_to_tree() {
                if let Ok(entry) = tree.get_path(&key_path) {
                    let obj = entry.to_object(&repo)?;
                    let blob = obj.peel_to_blob()?;
                    let content = std::str::from_utf8(blob.content())?;
                    let (pk, _) = pgp::SignedPublicKey::from_string(content)?;
                    // verify the key on file.
                    pk.verify()?;
                    let key_id = hex::encode(pk.primary_key.key_id().as_ref()).to_uppercase();
                    // check the key matches the key from the signed push certificate.
                    return Ok(key_id == key);
                }
            };
        }
        Ok(false)
    }
pub fn is_cert_authorized ( & self ) -> Result < bool , Error > { if let Some ( key ) = self . env . cert_key . clone ( ) { // search for the public key in the rad keys directory. let repo = Repository :: open ( & self . env . git_dir ) ? ; // the path of the public key to verify. let key_path = Path :: new ( DEFAULT_RAD_KEYS_PATH ) . join ( & key ) ; // set the namespace for the repo equal to the git namespace env. repo . set_namespace ( & self . env . git_namespace ) ? ; let ( refname , _ , _ ) = & self . updates [ 0 ] ; let rfc = repo . find_reference ( refname ) ? ; if let Ok ( tree ) = rfc . peel_to_tree ( ) { if let Ok ( entry ) = tree . get_path ( & key_path ) { let obj = entry . to_object ( & repo ) ? ; let blob = obj . peel_to_blob ( ) ? ; let content = std :: str :: from_utf8 ( blob . content ( ) ) ? ; let ( pk , _ ) = pgp :: SignedPublicKey :: from_string ( content ) ? ; // verify the key on file. pk . verify ( ) ? ; let key_id = hex :: encode ( pk . primary_key . key_id ( ) . as_ref ( ) ) . to_uppercase ( ) ; // check the key matches the key from the signed push certificate. return Ok ( key_id == key ) ; } } ; } Ok ( false ) }
Check the local repo .rad/keys/ directory for the GPG key matching the cert key
used to sign the push certificate.
Check the local repo . rad / keys / directory for the GPG key matching the cert key used to sign the push certificate .
&self
&self