public function testCanParseValues() { $path = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Data' . DIRECTORY_SEPARATOR . 'sampleOptions.php'; $aop = new TCrypto\Tools\ArrayOptionParser($path); $expected1 = 3; $expected2 = '/path/to/Keystore/default'; $expected3 = 0600; $option1 = $aop->getOption('bytes_in_key_name'); $option2 = $aop->getOption('keyfile_location'); $option3 = $aop->getOption('keyfile_permissions'); $this->assertEquals($expected1, $option1); $this->assertEquals($expected2, $option2); $this->assertEquals($expected3, $option3); }
<?php $error_level = E_ALL & E_STRICT; ini_set('error_reporting', $error_level); ini_set('display_errors', 1); $tcryptoLocation = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR . 'TCrypto'; require $tcryptoLocation . DIRECTORY_SEPARATOR . 'Loader.php'; require 'apps.php'; $loader = new TCrypto\Loader(); $loader->register(); $settings = new TCrypto\Tools\SettingStore(); $cli = new TCrypto\Tools\Cli\Horde\Cli(); if (file_exists('keytool.config.php')) { $optionParser = new TCrypto\Tools\ArrayOptionParser('keytool.config.php'); } else { $optionParser = new TCrypto\Tools\ArrayOptionParser('keytool.config.dist.php'); } $helper = new TCrypto\Tools\Keytool\Filesystem(); $keyParser = new TCrypto\Tools\Keytool\KeyParser(); if (!$cli->runningFromCLI()) { $cli->fatal('This script must be run from the command line.'); } $keyfilePermissions = $optionParser->getOption('keyfile_permissions'); $bytesInKeyName = (int) $optionParser->getOption('bytes_in_key_name') < 1 ? 3 : (int) $optionParser->getOption('bytes_in_key_name'); $keyMaxLifetime = (int) $optionParser->getOption('key_max_lifetime') < 1 ? 3600 : (int) $optionParser->getOption('key_max_lifetime'); $keyfileLocationTmp = $optionParser->getOption('keyfile_location'); if ($keyfileLocationTmp === null) { $keyfileLocation = realpath($tcryptoLocation) . DIRECTORY_SEPARATOR . 'Keystore' . DIRECTORY_SEPARATOR . 'default'; } else { $keyfileLocation = $keyfileLocationTmp; }