static function isSane($trust_root)
    {
        $parts = Auth_OpenID_TrustRoot::_parse($trust_root);
        if ($parts === false) {
            return false;
        }

        // Localhost is a special case
        if ($parts['host'] == 'localhost') {
            return true;
        }

        $host_parts = explode('.', $parts['host']);
        if ($parts['wildcard']) {
            // Remove the empty string from the beginning of the array
            array_shift($host_parts);
        }

        if ($host_parts && !$host_parts[count($host_parts) - 1]) {
            array_pop($host_parts);
        }

        if (!$host_parts) {
            return false;
        }

        // Don't allow adjacent dots
        if (in_array('', $host_parts, true)) {
            return false;
        }

        // Get the top-level domain of the host. If it is not a valid TLD,
        // it's not sane.
        preg_match(Auth_OpenID___TLDs, $parts['host'], $matches);
        if (!$matches) {
            return false;
        }
        $tld = $matches[1];

        if (count($host_parts) == 1) {
            return false;
        }

        if ($parts['wildcard']) {
            // It's a 2-letter tld with a short second to last segment
            // so there needs to be more than two segments specified
            // (e.g. *.co.uk is insane)
            $second_level = $host_parts[count($host_parts) - 2];
            if (strlen($tld) == 2 && strlen($second_level) <= 3) {
                return count($host_parts) > 2;
            }
        }

        return true;
    }
static function isSane($trust_root)
    {
        $parts = Auth_OpenID_TrustRoot::_parse($trust_root);
        if ($parts === false) {
            return false;
        }

        // Localhost is a special case
        if ($parts['host'] == 'localhost') {
            return true;
        }

        $host_parts = explode('.', $parts['host']);
        if ($parts['wildcard']) {
            // Remove the empty string from the beginning of the array
            array_shift($host_parts);
        }

        if ($host_parts && !$host_parts[count($host_parts) - 1]) {
            array_pop($host_parts);
        }

        if (!$host_parts) {
            return false;
        }

        // Don't allow adjacent dots
        if (in_array('', $host_parts, true)) {
            return false;
        }

        // Get the top-level domain of the host. If it is not a valid TLD,
        // it's not sane.
        preg_match(Auth_OpenID___TLDs, $parts['host'], $matches);
        if (!$matches) {
            return false;
        }
        $tld = $matches[1];

        if (count($host_parts) == 1) {
            return false;
        }

        if ($parts['wildcard']) {
            // It's a 2-letter tld with a short second to last segment
            // so there needs to be more than two segments specified
            // (e.g. *.co.uk is insane)
            $second_level = $host_parts[count($host_parts) - 2];
            if (strlen($tld) == 2 && strlen($second_level) <= 3) {
                return count($host_parts) > 2;
            }
        }

        return true;
    }
static function isSane ( $ trust_root ) { $ parts = Auth_OpenID_TrustRoot :: _parse ( $ trust_root ) ; if ( $ parts === false ) { return false ; } // Localhost is a special case if ( $ parts [ 'host' ] == 'localhost' ) { return true ; } $ host_parts = explode ( '.' , $ parts [ 'host' ] ) ; if ( $ parts [ 'wildcard' ] ) { // Remove the empty string from the beginning of the array array_shift ( $ host_parts ) ; } if ( $ host_parts && ! $ host_parts [ count ( $ host_parts ) - 1 ] ) { array_pop ( $ host_parts ) ; } if ( ! $ host_parts ) { return false ; } // Don't allow adjacent dots if ( in_array ( '' , $ host_parts , true ) ) { return false ; } // Get the top-level domain of the host. If it is not a valid TLD, // it's not sane. preg_match ( Auth_OpenID___TLDs , $ parts [ 'host' ] , $ matches ) ; if ( ! $ matches ) { return false ; } $ tld = $ matches [ 1 ] ; if ( count ( $ host_parts ) == 1 ) { return false ; } if ( $ parts [ 'wildcard' ] ) { // It's a 2-letter tld with a short second to last segment // so there needs to be more than two segments specified // (e.g. *.co.uk is insane) $ second_level = $ host_parts [ count ( $ host_parts ) - 2 ] ; if ( strlen ( $ tld ) == 2 && strlen ( $ second_level ) <= 3 ) { return count ( $ host_parts ) > 2 ; } } return true ; }
Is this trust root sane?

A trust root is sane if it is syntactically valid and it has a
reasonable domain name. Specifically, the domain name must be
more than one level below a standard TLD or more than two
levels below a two-letter tld.

For example, '*.com' is not a sane trust root, but '*.foo.com'
is.  '*.co.uk' is not sane, but '*.bbc.co.uk' is.

This check is not always correct, but it attempts to err on the
side of marking sane trust roots insane instead of marking
insane trust roots sane. For example, 'kink.fm' is marked as
insane even though it "should" (for some meaning of should) be
marked sane.

This function should be used when creating OpenID servers to
alert the users of the server when a consumer attempts to get
the user to accept a suspicious trust root.

@static
@param string $trust_root The trust root to check
@return bool $sanity Whether the trust root looks OK
Is this trust root sane?