/** * @param string $serverEncryptKey * @param string $serverSignKey * @throws EncryptionException */ private function init($serverEncryptKey = null, $serverSignKey = null) { $token = $this->sc->getToken(); if ($token instanceof TokenInterface && $token->getUser() instanceof GnuPGUserInterface) { $encryptKey = $token->getUser()->getPublicGnuPGKeyFingerprint() ?: $serverEncryptKey; $signKey = $token->getUser()->getPublicSignGnuPGKeyFingerprint() ?: $serverSignKey; } else { $encryptKey = $serverEncryptKey; $signKey = $serverSignKey; } $this->gpg = new \gnupg(); if (!is_null($encryptKey)) { $this->gpg->addencryptkey($encryptKey); $this->ability |= EncryptionAbility::ENCRYPT; } if (!is_null($signKey)) { $this->gpg->addsignkey($signKey); $this->ability |= EncryptionAbility::SIGN; } if (EncryptionAbility::NONE === $this->ability) { throw EncryptionException::missingConfiguration(); } }