protected function _addKey(array &$array, $encrypt, $sign, $key,
        $passphrase = null
    ) {
        $subKeys = array();

        if (is_scalar($key)) {
            $keys = $this->getKeys($key);
            if (count($keys) == 0) {
                throw new Crypt_GPG_KeyNotFoundException(
                    'Key not found: ' . $key,
                    self::ERROR_KEY_NOT_FOUND,
                    $key
                );
            }
            $key = $keys[0];
        }

        if ($key instanceof Crypt_GPG_Key) {
            if ($encrypt && !$key->canEncrypt()) {
                throw new InvalidArgumentException(
                    'Key "' . $key . '" cannot encrypt.'
                );
            }

            if ($sign && !$key->canSign()) {
                throw new InvalidArgumentException(
                    'Key "' . $key . '" cannot sign.'
                );
            }

            foreach ($key->getSubKeys() as $subKey) {
                $canEncrypt = $subKey->canEncrypt();
                $canSign    = $subKey->canSign();
                if (($encrypt && $sign && $canEncrypt && $canSign)
                    || ($encrypt && !$sign && $canEncrypt)
                    || (!$encrypt && $sign && $canSign)
                    || (!$encrypt && !$sign)
                ) {
                    // We add all subkeys that meet the requirements because we
                    // were not told which subkey is required.
                    $subKeys[] = $subKey;
                }
            }
        } elseif ($key instanceof Crypt_GPG_SubKey) {
            $subKeys[] = $key;
        }

        if (count($subKeys) === 0) {
            throw new InvalidArgumentException(
                'Key "' . $key . '" is not in a recognized format.'
            );
        }

        foreach ($subKeys as $subKey) {
            if ($encrypt && !$subKey->canEncrypt()) {
                throw new InvalidArgumentException(
                    'Key "' . $key . '" cannot encrypt.'
                );
            }

            if ($sign && !$subKey->canSign()) {
                throw new InvalidArgumentException(
                    'Key "' . $key . '" cannot sign.'
                );
            }

            $array[$subKey->getId()] = array(
                'fingerprint' => $subKey->getFingerprint(),
                'passphrase'  => $passphrase
            );
        }
    }
protected function _addKey(array &$array, $encrypt, $sign, $key,
        $passphrase = null
    ) {
        $subKeys = array();

        if (is_scalar($key)) {
            $keys = $this->getKeys($key);
            if (count($keys) == 0) {
                throw new Crypt_GPG_KeyNotFoundException(
                    'Key not found: ' . $key,
                    self::ERROR_KEY_NOT_FOUND,
                    $key
                );
            }
            $key = $keys[0];
        }

        if ($key instanceof Crypt_GPG_Key) {
            if ($encrypt && !$key->canEncrypt()) {
                throw new InvalidArgumentException(
                    'Key "' . $key . '" cannot encrypt.'
                );
            }

            if ($sign && !$key->canSign()) {
                throw new InvalidArgumentException(
                    'Key "' . $key . '" cannot sign.'
                );
            }

            foreach ($key->getSubKeys() as $subKey) {
                $canEncrypt = $subKey->canEncrypt();
                $canSign    = $subKey->canSign();
                if (($encrypt && $sign && $canEncrypt && $canSign)
                    || ($encrypt && !$sign && $canEncrypt)
                    || (!$encrypt && $sign && $canSign)
                    || (!$encrypt && !$sign)
                ) {
                    // We add all subkeys that meet the requirements because we
                    // were not told which subkey is required.
                    $subKeys[] = $subKey;
                }
            }
        } elseif ($key instanceof Crypt_GPG_SubKey) {
            $subKeys[] = $key;
        }

        if (count($subKeys) === 0) {
            throw new InvalidArgumentException(
                'Key "' . $key . '" is not in a recognized format.'
            );
        }

        foreach ($subKeys as $subKey) {
            if ($encrypt && !$subKey->canEncrypt()) {
                throw new InvalidArgumentException(
                    'Key "' . $key . '" cannot encrypt.'
                );
            }

            if ($sign && !$subKey->canSign()) {
                throw new InvalidArgumentException(
                    'Key "' . $key . '" cannot sign.'
                );
            }

            $array[$subKey->getId()] = array(
                'fingerprint' => $subKey->getFingerprint(),
                'passphrase'  => $passphrase
            );
        }
    }
protected function _addKey ( array & $ array , $ encrypt , $ sign , $ key , $ passphrase = null ) { $ subKeys = array ( ) ; if ( is_scalar ( $ key ) ) { $ keys = $ this -> getKeys ( $ key ) ; if ( count ( $ keys ) == 0 ) { throw new Crypt_GPG_KeyNotFoundException ( 'Key not found: ' . $ key , self :: ERROR_KEY_NOT_FOUND , $ key ) ; } $ key = $ keys [ 0 ] ; } if ( $ key instanceof Crypt_GPG_Key ) { if ( $ encrypt && ! $ key -> canEncrypt ( ) ) { throw new InvalidArgumentException ( 'Key "' . $ key . '" cannot encrypt.' ) ; } if ( $ sign && ! $ key -> canSign ( ) ) { throw new InvalidArgumentException ( 'Key "' . $ key . '" cannot sign.' ) ; } foreach ( $ key -> getSubKeys ( ) as $ subKey ) { $ canEncrypt = $ subKey -> canEncrypt ( ) ; $ canSign = $ subKey -> canSign ( ) ; if ( ( $ encrypt && $ sign && $ canEncrypt && $ canSign ) || ( $ encrypt && ! $ sign && $ canEncrypt ) || ( ! $ encrypt && $ sign && $ canSign ) || ( ! $ encrypt && ! $ sign ) ) { // We add all subkeys that meet the requirements because we // were not told which subkey is required. $ subKeys [ ] = $ subKey ; } } } elseif ( $ key instanceof Crypt_GPG_SubKey ) { $ subKeys [ ] = $ key ; } if ( count ( $ subKeys ) === 0 ) { throw new InvalidArgumentException ( 'Key "' . $ key . '" is not in a recognized format.' ) ; } foreach ( $ subKeys as $ subKey ) { if ( $ encrypt && ! $ subKey -> canEncrypt ( ) ) { throw new InvalidArgumentException ( 'Key "' . $ key . '" cannot encrypt.' ) ; } if ( $ sign && ! $ subKey -> canSign ( ) ) { throw new InvalidArgumentException ( 'Key "' . $ key . '" cannot sign.' ) ; } $ array [ $ subKey -> getId ( ) ] = array ( 'fingerprint' => $ subKey -> getFingerprint ( ) , 'passphrase' => $ passphrase ) ; } }
Adds a key to one of the internal key arrays

This handles resolving full key objects from the provided
<kbd>$key</kbd> value.

@param array   &$array     the array to which the key should be added.
@param boolean $encrypt    whether or not the key must be able to
encrypt.
@param boolean $sign       whether or not the key must be able to sign.
@param mixed   $key        the key to add. This may be a key identifier,
user id, fingerprint, {@link Crypt_GPG_Key} or
{@link Crypt_GPG_SubKey}.
@param string  $passphrase optional. The passphrase associated with the
key.

@return void

@sensitive $passphrase
Adds a key to one of the internal key arrays