@param int $purpose X509_PURPOSE_*
@param array $cainfo
@param string $untrusted

@return bool
973041
public function checkPurpose(int $purpose, array $cainfo = [], string $untrusted = NULL): bool {
        if($untrusted === NULL) {
            $status = openssl_x509_checkpurpose($this->getHandle(), $purpose, $cainfo);
        }
        else {
            $status = openssl_x509_checkpurpose($this->getHandle(), $purpose, $cainfo, $untrusted);
        }
        if(!is_bool($status)) {
            throw new RuntimeException('Failed to check purpose');
        }
        return $status;
    }
1136826
protected function checkKeyUsage(JWKInterface $key, $usage)
    {
        if ($key->has('use')) {
            return $this->checkUsage($key, $usage);
        }
        if ($key->has('key_ops')) {
            return $this->checkOperation($key, $usage);
        }

        return true;
    }
231231
function useNonce($server_url, $timestamp, $salt)
    {
        global $Auth_OpenID_SKEW;

        // save one request to memcache when nonce obviously expired
        if (abs($timestamp - time()) > $Auth_OpenID_SKEW) {
            return false;
        }

        // returns false when nonce already exists
        // otherwise adds nonce
        return $this->connection->add(
            'openid_nonce_' . sha1($server_url) . '_' . sha1($salt),
            1, // any value here
            $this->compress,
            $Auth_OpenID_SKEW);
    }
1045809
public function isValid($value, $context = null)
    {
        if (! $this->useContext) {
            $context = (array) $value;
        }

        $cleanedValue = $this->cleanSearchValue($value);
        $match        = $this->objectRepository->findOneBy($cleanedValue);

        if (! is_object($match)) {
            return true;
        }

        $expectedIdentifiers = $this->getExpectedIdentifiers($context);
        $foundIdentifiers    = $this->getFoundIdentifiers($match);

        if (count(array_diff_assoc($expectedIdentifiers, $foundIdentifiers)) == 0) {
            return true;
        }

        $this->error(self::ERROR_OBJECT_NOT_UNIQUE, $value);
        return false;
    }
805667
function hasUnusableRecordIdentifier(recState) {
  const md5s = recState.md5s;
  return isNotBlank(recState.eventID) || // isNotBlank(recState.eventSeqNo) || isNotBlank(recState.eventSubSeqNo) ||
    (md5s && (isNotBlank(md5s.userRec) || isNotBlank(md5s.rec) || isNotBlank(md5s.data)));
}
550151
public function isTrustedPHPDir($filepath)
    {
        if (empty($this->trusted_dir)) {
            throw new SmartyException("directory '{$filepath}' not allowed by security setting (no trusted_dir specified)");
        }

        // check if index is outdated
        if (!$this->_trusted_dir || $this->_trusted_dir !== $this->trusted_dir) {
            $this->_php_resource_dir = array();

            $this->_trusted_dir = $this->trusted_dir;
            foreach ((array) $this->trusted_dir as $directory) {
                $directory = realpath($directory);
                $this->_php_resource_dir[$directory] = true;
            }
        }

        $_filepath = realpath($filepath);
        $directory = dirname($_filepath);
        $_directory = array();
        while (true) {
            // remember the directory to add it to _resource_dir in case we're successful
            $_directory[] = $directory;
            // test if the directory is trusted
            if (isset($this->_php_resource_dir[$directory])) {
                // merge sub directories of current $directory into _resource_dir to speed up subsequent lookup
                $this->_php_resource_dir = array_merge($this->_php_resource_dir, $_directory);

                return true;
            }
            // abort if we've reached root
            if (($pos = strrpos($directory, DS)) === false || !isset($directory[2])) {
                break;
            }
            // bubble up one level
            $directory = substr($directory, 0, $pos);
        }

        throw new SmartyException("directory '{$_filepath}' not allowed by security setting");
    }
935781
protected function checkUseStatement(File $phpcsFile, array $useStatement, string $applicationLayer): void
    {
        $className = $useStatement['fullName'];

        $pairsToCheck = static::INVALID_PAIRS;
        foreach ($pairsToCheck as $pair) {
            if ($pair['from'] !== $applicationLayer) {
                continue;
            }

            if (!preg_match('#^\w+\\\\' . $pair['to'] . '\\\\#', $className, $matches)) {
                continue;
            }

            $phpcsFile->addError(
                sprintf(
                    'No %s namespace allowed in %s files.',
                    $pair['to'],
                    $pair['from']
                ),
                $useStatement['start'],
                'InvalidCrossNamespace'
            );
        }
    }
438577
public function generateKeyPairCommand(bool $usedForPasswords = false)
    {
        $fingerprint = $this->rsaWalletService->generateNewKeypair($usedForPasswords);

        $this->outputLine('The key pair has been successfully generated. Use the following fingerprint to refer to it in the RSAWalletService: ' . PHP_EOL . PHP_EOL . $fingerprint . PHP_EOL);
    }
418813
private function isTrusted($identity, $trustRoot) {
		assert('is_string($identity)');
		assert('is_string($trustRoot)');

		$trs = $this->getTrustRoots($identity);
		return in_array($trustRoot, $trs, TRUE);
	}
787847
public static function get_effective_contextlevel_purpose($contextlevel, $forcedvalue=false) {
        if (!data_registry::defaults_set()) {
            return false;
        }

        return data_registry::get_effective_contextlevel_value($contextlevel, 'purpose', $forcedvalue);
    }
964548
public void checkClientTrusted(X509Certificate[] chain, String authType)
                 throws CertificateException {
         try {
             pkixTrustManager.checkClientTrusted(chain, authType);
         } catch (CertificateException excep) {
             // do any special handling here, or rethrow exception.
         }
     }
725356
public static function isHttps($trustProxyHeaders = false): bool
    {
        // Check standard HTTPS header
        if (Arr::key('HTTPS', $_SERVER)) {
            return !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off';
        }

        if ($trustProxyHeaders && Arr::key('X-FORWARDED-PROTO', $_SERVER)) {
            return $_SERVER['X-FORWARDED-PROTO'] === 'https';
        }

        // Default is not SSL
        return false;
    }
1184683
public static function unassign_roles($unassignments) {
         global $DB;

        // Do basic automatic PARAM checks on incoming data, using params description
        // If any problems are found then exceptions are thrown with helpful error messages
        $params = self::validate_parameters(self::unassign_roles_parameters(), array('unassignments'=>$unassignments));

        $transaction = $DB->start_delegated_transaction();

        foreach ($params['unassignments'] as $unassignment) {
            // Ensure the current user is allowed to run this function in the unassignment context
            $context = self::get_context_from_params($unassignment);
            self::validate_context($context);
            require_capability('moodle/role:assign', $context);

            // throw an exception if user is not able to unassign the role in this context
            $roles = get_assignable_roles($context, ROLENAME_SHORT);
            if (!array_key_exists($unassignment['roleid'], $roles)) {
                throw new invalid_parameter_exception('Can not unassign roleid='.$unassignment['roleid'].' in contextid='.$unassignment['contextid']);
            }

            role_unassign($unassignment['roleid'], $unassignment['userid'], $context->id);
        }

        $transaction->allow_commit();
    }
593639
private static function isValidAuthUser(?string $userinfo): bool
    {
        if ($userinfo === null) {
            return true;
        }

        // http://tools.ietf.org/html/rfc3986#section-3.2.1
        // userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
        $pattern = sprintf(
            '/\A(?:[%s%s:]|(?:%s))*\z/i',
            'a-z0-9\-._~',
            '!$&\'()*+,;=',
            '%[a-f0-9]{2}'
        );

        return !!preg_match($pattern, $userinfo);
    }
1181843
private function validateCsrfTokenInternal($clientSuppliedToken, $trueToken)
    {
        if (!is_string($clientSuppliedToken)) {
            return false;
        }

        $security = $this->app->security;

        return $security->unmaskToken($clientSuppliedToken) === $security->unmaskToken($trueToken);
    }
1106005
private X509TrustManager defaultTrustManager() throws GeneralSecurityException {
    TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(
        TrustManagerFactory.getDefaultAlgorithm());
    trustManagerFactory.init((KeyStore) null);
    TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
    if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) {
      throw new IllegalStateException("Unexpected default trust managers:"
          + Arrays.toString(trustManagers));
    }
    return (X509TrustManager) trustManagers[0];
  }
992872
public function applySecurityRules(bool $secure = false, bool $httponly = false)
    {
        $nb_engine = CNabuEngine::getEngine();

        $attrs = session_get_cookie_params();
        session_set_cookie_params(
            $attrs['lifetime'],
            $attrs['path'],
            $attrs['domain'],
            $secure || $attrs['secure'],
            $httponly || (array_key_exists('httponly', $attrs) && $attrs['httponly'])
        );

        session_start();
        $nb_engine->traceLog("Session ID", session_id());

        $this->purgeNonce();

        if (isset($_SESSION) && count($_SESSION) > 0) {
            foreach ($_SESSION as $value) {
                if ($value instanceof INabuDBObject && !$value->isBuiltIn()) {
                    $value->relinkDB();
                }
            }
        }
    }