*/ class LSformRule_gpg_pub_key extends LSformRule { /** * Validate SSH public key value * * @param string $value The value to validate * @param array $options Validation options * @param LSformElement &$formElement The related formElement object * * @return boolean true if the value is valide, false if not */ public static function validate($value, $options, &$formElement) { if (!class_exists('gnupg')) { LSerror :: addErrorCode('LSformRule_gpg_pub_key_01'); return false; } // The home_dir parameter passed to gnupg_init() is not correctly handled in PHP 7.3, also set // the GNUPGHOME environment variable. putenv('GNUPGHOME='.LS_TMP_DIR_PATH); $gpg = new gnupg(["home_dir" => LS_TMP_DIR_PATH]); // Don't warn about (GNUPG_ERROR_SILENT is currently the default but ensure it) $gpg -> seterrormode(GNUPG_ERROR_SILENT); $info = $gpg -> import($value); // @phpstan-ignore-next-line return is_array($info) && ($info['imported'] + $info['unchanged']) == 1 && $info['fingerprint']; } } /* * Error Codes */ LSerror :: defineError('LSformRule_gpg_pub_key_01', ___("LSformRule_gpg_pub_key: PHP GnuPG extension is missing, can't validate value.") );