Crypt_GPG
[ class tree: Crypt_GPG ] [ index: Crypt_GPG ] [ all elements ]

Class: Crypt_GPG_Engine

Source Location: /Crypt_GPG-1.4.0b4/Crypt/GPG/Engine.php

Class Overview


Native PHP Crypt_GPG I/O engine


Author(s):

Copyright:

  • 2005-2013 silverorange

Methods


Inherited Variables

Inherited Methods


Class Details

[line 88]
Native PHP Crypt_GPG I/O engine

This class is used internally by Crypt_GPG and does not need be used directly. See the Crypt_GPG class for end-user API.

This engine uses PHP's native process control functions to directly control the GPG process. The GPG executable is required to be on the system.

All data is passed to the GPG subprocess using file descriptors. This is the most secure method of passing data to the GPG subprocess.



[ Top ]


Method Detail

__construct (Constructor)   [line 505]

Crypt_GPG_Engine __construct( [ $options = array()])

Creates a new GPG engine

Available options are:

  • string homedir - the directory where the GPG keyring files are stored. If not specified, Crypt_GPG uses the default of ~/.gnupg.
  • string publicKeyring - the file path of the public keyring. Use this if the public keyring is not in the homedir, or if the keyring is in a directory not writable by the process invoking GPG (like Apache). Then you can specify the path to the keyring with this option (/foo/bar/pubring.gpg), and specify a writable directory (like /tmp) using the homedir option.
  • string privateKeyring - the file path of the private keyring. Use this if the private keyring is not in the homedir, or if the keyring is in a directory not writable by the process invoking GPG (like Apache). Then you can specify the path to the keyring with this option (/foo/bar/secring.gpg), and specify a writable directory (like /tmp) using the homedir option.
  • string trustDb - the file path of the web-of-trust database. Use this if the trust database is not in the homedir, or if the database is in a directory not writable by the process invoking GPG (like Apache). Then you can specify the path to the trust database with this option (/foo/bar/trustdb.gpg), and specify a writable directory (like /tmp) using the homedir option.
  • string binary - the location of the GPG binary. If not specified, the driver attempts to auto-detect the GPG binary location using a list of known default locations for the current operating system. The option gpgBinary is a deprecated alias for this option.
  • string agent - the location of the GnuPG agent binary. The gpg-agent is only used for GnuPG 2.x. If not specified, the engine attempts to auto-detect the gpg-agent binary location using a list of know default locations for the current operating system.
  • boolean debug - whether or not to use debug mode. When debug mode is on, all communication to and from the GPG subprocess is logged. This can be useful to diagnose errors when using Crypt_GPG.

  • Throws: Crypt_GPG_FileException if the homedir does not exist and cannot be created. This can happen if homedir is not specified, Crypt_GPG is run as the web user, and the web user has no home directory. This exception is also thrown if any of the options publicKeyring, privateKeyring or trustDb options are specified but the files do not exist or are are not readable. This can happen if the user running the Crypt_GPG process (for example, the Apache user) does not have permission to read the files.
  • Throws: PEAR_Exception if the provided binary is invalid, or if no binary is provided and no suitable binary could be found.
  • Throws: PEAR_Exception if the provided agent is invalid, or if no agent is provided and no suitable gpg-agent cound be found.
  • Access: public

Parameters:

array   $options     optional. An array of options used to create the GPG object. All options are optional and are represented as key-value pairs.

[ Top ]

__destruct (Destructor)   [line 668]

void __destruct( )

Closes open GPG subprocesses when this object is destroyed

Subprocesses should never be left open by this class unless there is an unknown error and unexpected script termination occurs.

  • Access: public

[ Top ]

addErrorHandler   [line 689]

void addErrorHandler( callback $callback, [ $args = array()])

Adds an error handler method

The method is run every time a new error line is received from the GPG subprocess. The handler method must accept the error line to be handled as its first parameter.

  • Access: public

Parameters:

callback   $callback     the callback method to use.
array   $args     optional. Additional arguments to pass as parameters to the callback method.

[ Top ]

addStatusHandler   [line 713]

void addStatusHandler( callback $callback, [ $args = array()])

Adds a status handler method

The method is run every time a new status line is received from the GPG subprocess. The handler method must accept the status line to be handled as its first parameter.

  • Access: public

Parameters:

callback   $callback     the callback method to use.
array   $args     optional. Additional arguments to pass as parameters to the callback method.

[ Top ]

getErrorCode   [line 817]

integer getErrorCode( )

Gets the error code of the last executed operation

This value is only meaningful after Crypt_GPG_Engine::run() has been executed.

  • Return: the error code of the last executed operation.
  • Access: public

[ Top ]

getErrorFilename   [line 835]

string getErrorFilename( )

Gets the file related to the error code of the last executed operation

This value is only meaningful after Crypt_GPG_Engine::run() has been executed. If there is no file related to the error, an empty string is returned.

  • Return: the file related to the error code of the last executed operation.
  • Access: public

[ Top ]

getErrorKeyId   [line 853]

string getErrorKeyId( )

Gets the key id related to the error code of the last executed operation

This value is only meaningful after Crypt_GPG_Engine::run() has been executed. If there is no key id related to the error, an empty string is returned.

  • Return: the key id related to the error code of the last executed operation.
  • Access: public

[ Top ]

getVersion   [line 956]

string getVersion( )

Gets the version of the GnuPG binary
  • Return: a version number string containing the version of GnuPG being used. This value is suitable to use with PHP's version_compare() function.
  • Throws: Crypt_GPG_UnsupportedException if the provided binary is not GnuPG or if the GnuPG version is less than 1.0.2.
  • Throws: Crypt_GPG_Exception if an unknown or unexpected error occurs. Use the debug option and file a bug report if these exceptions occur.
  • Access: public

[ Top ]

reset   [line 752]

void reset( )

Resets the GPG engine, preparing it for a new operation

[ Top ]

run   [line 793]

void run( )

Runs the current GPG operation

This creates and manages the GPG subprocess.

The operation must be set with Crypt_GPG_Engine::setOperation() before this method is called.


[ Top ]

sendCommand   [line 734]

void sendCommand( string $command)

Sends a command to the GPG subprocess over the command file-descriptor pipe
  • Access: public

Parameters:

string   $command     the command to send.

[ Top ]

setInput   [line 871]

void setInput( string|resource &$input)

Sets the input source for the current GPG operation
  • Access: public

Parameters:

string|resource   &$input     either a reference to the string containing the input data or an open stream resource containing the input data.

[ Top ]

setMessage   [line 891]

void setMessage( string|resource &$message)

Sets the message source for the current GPG operation

Detached signature data should be specified here.

  • Access: public

Parameters:

string|resource   &$message     either a reference to the string containing the message data or an open stream resource containing the message data.

[ Top ]

setOperation   [line 933]

void setOperation( string $operation, [ $arguments = array()])

Sets the operation to perform

Parameters:

string   $operation     the operation to perform. This should be one of GPG's operations. For example, --encrypt, --decrypt, --sign, etc.
array   $arguments     optional. Additional arguments for the GPG subprocess. See the GPG manual for specific values.

[ Top ]

setOutput   [line 909]

void setOutput( string|resource &$output)

Sets the output destination for the current GPG operation
  • Access: public

Parameters:

string|resource   &$output     either a reference to the string in which to store GPG output or an open stream resource to which the output data should be written.

[ Top ]


Documentation generated on Wed, 13 Mar 2013 18:30:07 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.