Skip to content

Commit

Permalink
readme, smal tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Kerin committed May 3, 2018
1 parent 3b681e5 commit c9c3cd2
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 26 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 7 additions & 0 deletions examples/getpid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
require "vendor/autoload.php";
use BitWasp\PinEntry\PinEntry;

$pinEntry = new PinEntry("/usr/bin/pinentry");
$pin = $pinEntry->getInfo("pid");
echo "got pin {$pin}\n";
8 changes: 8 additions & 0 deletions examples/getversion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
require "vendor/autoload.php";
use BitWasp\PinEntry\PinEntry;
use BitWasp\PinEntry\PinRequest;

$pinEntry = new PinEntry("/usr/bin/pinentry");
$pin = $pinEntry->getInfo("version");
echo "got pin {$pin}\n";
19 changes: 0 additions & 19 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
5 changes: 2 additions & 3 deletions src/PinEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/Request.php → src/PinRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace BitWasp\PinEntry;

class Request
class PinRequest
{
/**
* @var string[]|int[]
Expand Down
6 changes: 3 additions & 3 deletions test/unit/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c9c3cd2

Please sign in to comment.