/** * Internal function to parse output lines, (usually from gpg --recv-keys or gpg --list-keys), * into an array of valid Key and SecretKey objects. * * @param array $output * * @return array */ private function _parseOutputLines($output){ $keys = []; $k = null; // Last Key foreach($output as $line){ $type = substr($line, 0, 4); switch($type){ case 'gpg:': // This is a GPG comment, skip it. continue; break; case 'tru:': // This is a trust definition, skip it for now. continue; break; case 'pub:': if($k !== null){ // This is a new key. // Save the previous one. $keys[] = $k; } // This is a new key object. $k = new PublicKey(); $k->parseLine($line); break; case 'sec:': if($k !== null){ // This is a new key. // Save the previous one. $keys[] = $k; } // This is a new key object. $k = new SecretKey(); $k->parseLine($line); break; default: if($k !== null) { // Let the previous key handle it! $k->parseLine($line); } break; } } // End of output and there is data? if($k !== null){ $keys[] = $k; } return $keys; }