/** * @covers ::__construct * @covers ::reveal */ public function testMaskingStringLongerThanNoiseLength() { $noise = SecretKey::getKey(); $noise_length = mb_strlen($noise, '8bit'); $string = str_repeat('asdf', $noise_length); $secret = new Secret($string); $this->assertSame($string, $secret->reveal(), 'Secret was destroyed'); }
/** * @param string $keyMaterial - The actual key data * @param bool $signing - Is this a signing key? */ public function __construct($keyMaterial = '', ...$args) { parent::__construct($keyMaterial, true); }
/** * @covers ::getKey */ public function testGetKey() { $this->assertInternalType('string', SecretKey::getKey()); }
/** * 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; }
/** * @return string The original secret */ public function reveal() : string { return $this->mask($this->value, SecretKey::getKey()); }