Extract 4 bytes from a hash value

Uses the method defined in RFC 4226, § 5.4.

@static
@param  string  $hash Hash value.
@return integer Returns the truncated hash value.
330908
protected static function truncateHash($hash)
    {
        $offset = ord($hash[19]) & 0xf;
        $value  = (ord($hash[$offset + 0]) & 0x7f) << 24;
        $value |= (ord($hash[$offset + 1]) & 0xff) << 16;
        $value |= (ord($hash[$offset + 2]) & 0xff) << 8;
        $value |= (ord($hash[$offset + 3]) & 0xff);

        return $value;
    }
1009011
public function path($hash) {
		return $this->convEncOut($this->_path($this->convEncIn($this->decode($hash))));
	}
1209937
protected function volume($hash) {
		foreach ($this->volumes as $id => $v) {
			if (strpos(''.$hash, $id) === 0) {
				return $this->volumes[$id];
			} 
		}
		return false;
	}
187482
public function findByHash($hash)
    {
        return $this->hashWorkingRecord->get()->filter($this->hashDbField, $hash)->first();
    }
1094924
public static String hashToString(byte[] hash) {
        StringBuilder buf = new StringBuilder();
        for (byte b : hash) {
            buf.append(HEX_CHARS[(b >> 4) & 0xF]);
            buf.append(HEX_CHARS[b & 0xF]);
        }
        return buf.toString();
    }
1073768
public static function getDir(string $hash = ''): string
    {
        static::init();
        $fileDir = \str_replace(
            [static::normalizePath(static::$documentRoot), DIRECTORY_SEPARATOR],
            ['', '/'],
            static::getPath($hash)
        );

        return $fileDir;
    }
449257
private function _returnHash(string $hash, int $length)
    {
        try {
            return substr($hash, 0, $length);
        } catch (\Exception $e) { }

        return false;
    }
1222370
public function selectObjectByHash($hash)
       {
            $index = array_search($hash, $this->map, true);
            return (false !== $index) ? $this->selectObjectByKey($index) : false;
       }
796810
public function fromHash($hash)
    {
        if ($hash === null) {
            return $this->getEmptyValue();
        }

        if (isset($hash['text'])) {
            return new Value($hash['link'], $hash['text']);
        }

        return new Value($hash['link']);
    }
670752
public function getKeyStr($hash = true)
    {
        $key =  $this->key . self::$INDEX_SEPERATOR . $this->groupId . self::$TAG_SEPERATOR . implode(self::$TAG_SEPERATOR, $this->gatherTags());
        if($hash) {
             $key = md5($key);
        }
        return $key;
    }
512212
public function file($hash) {
		$path = $this->decode($hash);
		
		return ($file = $this->stat($path)) ? $file : $this->setError(elFinder::ERROR_FILE_NOT_FOUND);
		
		if (($file = $this->stat($path)) != false) {
			if ($realpath) {
				$file['realpath'] = $path;
			}
			return $file;
		}
		return $this->setError(elFinder::ERROR_FILE_NOT_FOUND);
	}
980052
public function realpath($hash) {
		$path = $this->decode($hash);
		return $this->stat($path) ? $path : false;
	}
374592
protected function getFromHash($hash, $version)
    {
        return sprintf('%08s-%04s-%04x-%04x-%12s',
    		// 32 bits for "time_low"
    		substr($hash, 0, 8),
    		// 16 bits for "time_mid"
    		substr($hash, 8, 4),
    		// 16 bits for "time_hi_and_version",
    		// four most significant bits holds version number 4
    		(hexdec(substr($hash, 12, 4)) & 0x0fff) | $version << 12,
    		// 16 bits, 8 bits for "clk_seq_hi_res",
    		// 8 bits for "clk_seq_low",
    		// two most significant bits holds zero and one for variant DCE1.1
    		(hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
    		// 48 bits for "node"
    		substr($hash, 20, 12)
		);
    }
1197277
public static int hash(int hash, String s) {
    if (s == null) {
      return hash;
    }
    // similar to Arrays.hashCode
    return s.indexOf('%') < 0 ? 31 * hash + s.hashCode() : normalizedHash(hash, s);
  }
637394
public function getKeyByHash($hash)
       {
            $index = array_search($hash, $this->map, true);
            return (false === $index) ? null : $index;
       }
1177982
public function fromHash( $hash )
    {
        if ( !is_array( $hash ) )
        {
            return new Value( [] );
        }
        $metas = [];
        foreach ( $hash as $hashItem )
        {
            if ( !is_array( $hashItem ) )
            {
                continue;
            }
            $meta = new Meta();
            $meta->setName( $hashItem["meta_name"] );
            $meta->setContent( $hashItem["meta_content"] );
            $metas[] = $meta;
        }

        return new Value( $metas );
    }
176742
public function scandir($hash) {
		if (($dir = $this->dir($hash)) == false) {
			return false;
		}
		
		return $dir['read']
			? $this->getScandir($this->decode($hash))
			: $this->setError(elFinder::ERROR_PERM_DENIED);
	}