/**
 * Format a GPG fingerprint into pretty print!
 * 
 * This gives more options than the inline modifier provides.
 *
 * Type:     function<br>
 * Name:     gpg_fingerprint<br>
 * 
 * Options for parameters are:
 * short     = true|FALSE: Set to true to only include the last 8 characters of the fingerprint.
 * html      = TRUE|false: Set to false to return "\n" instead of "<br/>" and multiline is set to true.
 * multiline = true|FALSE: Set to true to return on two lines instead of one.
 *
 * @param array  $params  Associative (and/or indexed) array of smarty parameters passed in from the template
 * @param Smarty $smarty  Parent Smarty template object
 *
 * @return string HTML text
 */
function smarty_function_gpg_fingerprint($params, $smarty) {
	$string = $params[0];
	
	$short     = isset($params['short']) ? $params['short'] : false;
	$assign    = isset($params['assign']) ? $params['assign'] : null;
	$ashtml    = isset($params['html']) ? $params['html'] : true;
	$multiline = isset($params['multiline']) ? $params['multiline'] : false;
	
	$string = \Core\GPG\GPG::FormatFingerprint($string, $ashtml, !$multiline);
	
	if($short){
		// I just want the last 9 characters, (8 strings and one space).
		$string = substr($string, -9);
	}

	return $assign ? $smarty->assign($assign, $string) : $string;
}
Esempio n. 2
0
	/**
	 * @depends testImportShort
	 */
	public function testPrettyFormatFingerprints(){

		// Given this fingerprint:
		// 4E73 30EB 2A84 D747 9B71  9FF3 3F20 C906 B04E FAD6

		// The default output.
		$this->assertEquals("4E73 30EB 2A84 D747 9B71\n9FF3 3F20 C906 B04E FAD6", \Core\GPG\GPG::FormatFingerprint($this->fingerprint));

		// Plain text as 1 line
		$this->assertEquals("4E73 30EB 2A84 D747 9B71  9FF3 3F20 C906 B04E FAD6", \Core\GPG\GPG::FormatFingerprint($this->fingerprint, false, true));

		// HTML
		$this->assertEquals("4E73 30EB 2A84 D747 9B71<br/>9FF3 3F20 C906 B04E FAD6", \Core\GPG\GPG::FormatFingerprint($this->fingerprint, true));

		// And HTML as one line.
		$this->assertEquals("4E73 30EB 2A84 D747 9B71&nbsp;&nbsp;9FF3 3F20 C906 B04E FAD6", \Core\GPG\GPG::FormatFingerprint($this->fingerprint, true, true));
	}
Esempio n. 3
0
	/**
	 * Get an array of keys to install automatically with this repo.
	 *
	 * @return array
	 */
	public function getKeys(){
		if($this->_keys !== null){
			// Cache!
			return $this->_keys;
		}

		$gpg         = new \Core\GPG\GPG();
		$this->_keys = [];

		foreach($this->getElements('keys/key') as $k){
			$id    = $k->getAttribute('id');
			$key   = null;
			$local = true;

			// Try to find more info about this key!
			// First step is to assign the key from local data.
			// If that fails, gracefully search remote servers for it.
			if(($key = $gpg->getKey($id)) === null){
				$remoteKeys = $gpg->searchRemoteKeys($id);
				foreach($remoteKeys as $k){
					/** @var \Core\GPG\PublicKey $k */
					if($k->id == $id || $k->id_short == $id){
						$key = $k;
						$local = false;
						break;
					}
				}
			}

			if($key !== null){
				$dat = [
					'key'        => $id,
					'available'  => true,
					'installed'  => $local,
					'fingerprint' => \Core\GPG\GPG::FormatFingerprint($key->fingerprint, false, true),
					'uids'        => [],
				];

				foreach($key->uids as $uid){
					/** @var \Core\GPG\UID $uid */
					if($uid->isValid()){
						$dat['uids'][] = ['name' => $uid->fullname, 'email' => $uid->email];
					}
				}
			}
			else{
				$dat = [
					'key'        => $id,
					'available'  => false,
					'installed'  => false,
					'fingerprint' => '',
					'uids'        => [],
				];
			}

			$this->_keys[] = $dat;
		}
		return $this->_keys;
	}
/**
 * Format a GPG fingerprint into pretty print!
 *
 * Type:     modifier<br>
 * Name:     gpg_fingerprint<br>
 *
 * @param string $string input string
 *
 * @return string HTML text
 */
function smarty_modifier_gpg_fingerprint($string) {
	return \Core\GPG\GPG::FormatFingerprint($string, true, true);
}