From 0128100995751f2b825d22877ee4351aa99c77b3 Mon Sep 17 00:00:00 2001 From: Stricted Date: Sat, 7 Dec 2013 19:06:22 +0100 Subject: [PATCH] update hash class --- git.class.php | 7 +++++ hash.class.php | 79 ++++++++++++++++++-------------------------------- 2 files changed, 35 insertions(+), 51 deletions(-) diff --git a/git.class.php b/git.class.php index 96fbf5c..22a8e0b 100644 --- a/git.class.php +++ b/git.class.php @@ -177,5 +177,12 @@ class git { public function pull () { shell_exec("git --git-dir=".$this->repo." pull"); } + + /* + * clone repo + */ + public function clone () { + shell_exec("git clone --bare ".$this->repo); + } } ?> \ No newline at end of file diff --git a/hash.class.php b/hash.class.php index aaf77c2..749b013 100644 --- a/hash.class.php +++ b/hash.class.php @@ -17,16 +17,25 @@ * along with this program. If not, see . */ class hash { + protected $raw; + protected $hmac; + protected $key; protected $algo; /** * constructor to validate algorithm * - * @param string $algo + * @param string $algo + * @param optional $raw + * @param optional $hmac + * @param optional $key */ - public function __construct ($algo) { + public function __construct ($algo, $raw = Null, $hmac = Null, $key = Null) { + $this->raw = $raw; + $this->hmac = $hmac; + $this->key = $key; if (in_array($algo, hash_algos())) { - $this-algo = $algo; + $this->algo = $algo; } else { die("algorithm ".$algo." not supported"); } @@ -36,46 +45,28 @@ class hash { * hash given data with given algorithm * * @param mixed $data - * @param optional $raw - * @return hash - */ - public function hash ($data, $raw = NULL) { - return hash($this-algo, $data, $raw); - } - - /** - * hash given file with given algorithm - * - * @param mixed $file - * @param optional $raw - * @return hash - */ - public function hash_file ($file, $raw = Null) { - return hash_file($this-algo, $data, $raw); - } - - /** - * hash given data with given algorithm - * - * @param mixed $data - * @param mixed $key - * @param optional $raw * @return hash */ - public function hash_hmac ($data, $key, $raw = Null) { - return hash_hmac($this-algo, $data, $key, $raw); + public function hash ($data) { + if (!empty($this->hmac)) { + return hash_hmac($this->algo, $data, $this->key, $this->raw); + } else { + return hash($this->algo, $data, $this->raw); + } } /** * hash given file with given algorithm * * @param mixed $file - * @param mixed $key - * @param optional $raw * @return hash */ - public function hash_hmac_file ($file, $key, $raw = Null) { - return hash_hmac_file($this-algo, $file, $key, $raw); + public function hash_file ($file) { + if (!empty($this->hmac)) { + return hash_hmac_file($this->algo, $file, $this->key, $this->raw); + } else { + return hash_file($this->algo, $file, $this->raw); + } } /** @@ -83,17 +74,10 @@ class hash { * * @param hash $hash * @param mixed $data - * @param optional $raw - * @param optional $hmac * @return boolean */ - public function compare ($hash, $data, $raw = NULL, $hmac = NULL) { - $newhash = ""; - if (!empty($hmac)) { - $newhash = $this->hash_hmac($data, $key, $raw); - } else { - $newhash = $this->hash($data, $raw); - } + public function compare ($hash, $data) { + $newhash = $this->hash($data); if ($newhash == $hash) { return true; } @@ -105,17 +89,10 @@ class hash { * * @param hash $hash * @param mixed $file - * @param optional $raw - * @param optional $hmac * @return boolean */ - public function compare_file ($hash, $file, $raw = NULL, $hmac = NULL) { - $newhash = ""; - if (!empty($hmac)) { - $newhash = $this->hash_hmac_file($file, $key, $raw); - } else { - $newhash = $this->hash_file($file, $raw); - } + public function compare_file ($hash, $file) { + $newhash = $this->hash_file($file); if ($newhash == $hash) { return true; } -- 2.20.1