From c9c3cd2793d1888ad665b246e41fbb29ff4c2a95 Mon Sep 17 00:00:00 2001 From: Thomas Kerin Date: Thu, 3 May 2018 03:29:00 +0200 Subject: [PATCH] readme, smal tweaks --- README.md | 11 +++++++++++ examples/getpid.php | 7 +++++++ examples/getversion.php | 8 ++++++++ src/Command.php | 19 ------------------- src/PinEntry.php | 5 ++--- src/{Request.php => PinRequest.php} | 2 +- test/unit/RequestTest.php | 6 +++--- 7 files changed, 32 insertions(+), 26 deletions(-) create mode 100644 README.md create mode 100644 examples/getpid.php create mode 100644 examples/getversion.php rename src/{Request.php => PinRequest.php} (99%) diff --git a/README.md b/README.md new file mode 100644 index 0000000..c7c6ad0 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +pinentry +======== + +This package allows PHP command line applications to prompt +users for a passphrase / pin using the gpgtools `pinentry` program. + +https://www.gnupg.org/related_software/pinentry/index.html + +The PinRequest class allows passphrase requests to be parameterized +(messages, titles, button text), or to request a confirmation password +also. diff --git a/examples/getpid.php b/examples/getpid.php new file mode 100644 index 0000000..90f7711 --- /dev/null +++ b/examples/getpid.php @@ -0,0 +1,7 @@ +getInfo("pid"); +echo "got pin {$pin}\n"; diff --git a/examples/getversion.php b/examples/getversion.php new file mode 100644 index 0000000..523df8d --- /dev/null +++ b/examples/getversion.php @@ -0,0 +1,8 @@ +getInfo("version"); +echo "got pin {$pin}\n"; diff --git a/src/Command.php b/src/Command.php index cc4544e..60b2e1a 100644 --- a/src/Command.php +++ b/src/Command.php @@ -19,23 +19,4 @@ class Command const SETTIMEOUT = 'SETTIMEOUT'; const SETQUALITYBAR = 'SETQUALITYBAR'; const SETQUALITYBAR_TT = 'SETQUALITYBAR_TT'; - - private $cmd; - private $param; - - public function __construct(string $command, $param) - { - $this->cmd = $command; - $this->param = $param; - } - - public function getCommand(): string - { - return $this->cmd; - } - - public function getParam() - { - return $this->param; - } } diff --git a/src/PinEntry.php b/src/PinEntry.php index 531da1e..a7570f5 100644 --- a/src/PinEntry.php +++ b/src/PinEntry.php @@ -18,9 +18,8 @@ public function __construct( ProcessInterface $process ) { $msg = $process->waitFor("OK"); - if ($msg !== "OK Pleased to meet you\n") { - throw new PinEntryException("Unexpected start of pinnetry protocol"); + throw new PinEntryException("First message from pinentry did not match expected value"); } $this->process = $process; } @@ -32,7 +31,7 @@ public function getInfo(string $type): string return $msg; } - public function getPin(Request $request): string + public function getPin(PinRequest $request): string { foreach ($request->getCommands() as $command => $param) { $this->process->send("{$command} {$param}\n"); diff --git a/src/Request.php b/src/PinRequest.php similarity index 99% rename from src/Request.php rename to src/PinRequest.php index e7842fd..ae54a1b 100644 --- a/src/Request.php +++ b/src/PinRequest.php @@ -4,7 +4,7 @@ namespace BitWasp\PinEntry; -class Request +class PinRequest { /** * @var string[]|int[] diff --git a/test/unit/RequestTest.php b/test/unit/RequestTest.php index 7bd7320..0f2914c 100644 --- a/test/unit/RequestTest.php +++ b/test/unit/RequestTest.php @@ -4,19 +4,19 @@ namespace BitWasp\Test\PinEntry; -use BitWasp\PinEntry\Request; +use BitWasp\PinEntry\PinRequest; class RequestTest extends TestCase { /** - * @var Request + * @var PinRequest */ private $request; public function setUp() { parent::setUp(); // TODO: Change the autogenerated stub - $this->request = new Request(); + $this->request = new PinRequest(); } public function testSetDesc()