function SelfUpdateCommand::fetchKeys
Throws
\Exception
1 call to SelfUpdateCommand::fetchKeys()
- SelfUpdateCommand::execute in vendor/
composer/ composer/ src/ Composer/ Command/ SelfUpdateCommand.php
File
-
vendor/
composer/ composer/ src/ Composer/ Command/ SelfUpdateCommand.php, line 367
Class
- SelfUpdateCommand
- @author Igor Wiedler <igor@wiedler.ch> @author Kevin Ran <kran@adobe.com> @author Jordi Boggiano <j.boggiano@seld.be>
Namespace
Composer\CommandCode
protected function fetchKeys(IOInterface $io, Config $config) : void {
if (!$io->isInteractive()) {
throw new \RuntimeException('Public keys can not be fetched in non-interactive mode, please run Composer interactively');
}
$io->write('Open <info>https://composer.github.io/pubkeys.html</info> to find the latest keys');
$validator = static function ($value) : string {
$value = (string) $value;
if (!Preg::isMatch('{^-----BEGIN PUBLIC KEY-----$}', trim($value))) {
throw new \UnexpectedValueException('Invalid input');
}
return trim($value) . "\n";
};
$devKey = '';
while (!Preg::isMatch('{(-----BEGIN PUBLIC KEY-----.+?-----END PUBLIC KEY-----)}s', $devKey, $match)) {
$devKey = $io->askAndValidate('Enter Dev / Snapshot Public Key (including lines with -----): ', $validator);
while ($line = $io->ask('', '')) {
$devKey .= trim($line) . "\n";
if (trim($line) === '-----END PUBLIC KEY-----') {
break;
}
}
}
file_put_contents($keyPath = $config->get('home') . '/keys.dev.pub', $match[0]);
$io->write('Stored key with fingerprint: ' . Keys::fingerprint($keyPath));
$tagsKey = '';
while (!Preg::isMatch('{(-----BEGIN PUBLIC KEY-----.+?-----END PUBLIC KEY-----)}s', $tagsKey, $match)) {
$tagsKey = $io->askAndValidate('Enter Tags Public Key (including lines with -----): ', $validator);
while ($line = $io->ask('', '')) {
$tagsKey .= trim($line) . "\n";
if (trim($line) === '-----END PUBLIC KEY-----') {
break;
}
}
}
file_put_contents($keyPath = $config->get('home') . '/keys.tags.pub', $match[0]);
$io->write('Stored key with fingerprint: ' . Keys::fingerprint($keyPath));
$io->write('Public keys stored in ' . $config->get('home'));
}