Skip to content

Commit

Permalink
more tweaks for static analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmunro committed May 19, 2017
1 parent 0d20d1e commit d9fedf6
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 19 deletions.
6 changes: 3 additions & 3 deletions lib/config.php
Expand Up @@ -12,7 +12,7 @@
abstract class Hm_Config {

/* config source */
protected $source = false;
protected $source = '';

/* config data */
protected $config = array('version' => VERSION);
Expand All @@ -21,7 +21,7 @@ abstract class Hm_Config {
public $decrypt_failed = false;

/* if decryption fails, save the encrypted payload */
public $encrypted_str = false;
public $encrypted_str;

/**
* This method must be overriden by classes extending this one
Expand Down Expand Up @@ -107,7 +107,7 @@ public function shuffle() {
/**
* Decode user settings with json_decode or unserialize depending
* on the format
* @param string $data serialized or json encoded string
* @param string|false $data serialized or json encoded string
* @return mixed array, or false on failure
*/
public function decode($data) {
Expand Down
13 changes: 10 additions & 3 deletions lib/crypt.php
Expand Up @@ -168,13 +168,23 @@ public static function hash_compare($a, $b) {
return $a === $b;
}

/**
* Key derivation wth pbkdf2: http://en.wikipedia.org/wiki/PBKDF2
* @param string $key payload
* @param string $salt random string from generate_salt
* @return string
*/
protected static function keygen($key, $salt) {
return array($salt, self::pbkdf2($key, $salt, 32, self::$encryption_rounds, self::$hmac));
}
/**
* Key derivation wth pbkdf2: http://en.wikipedia.org/wiki/PBKDF2
* @param string $key payload
* @param string $salt random string from generate_salt
* @param string $length result length
* @param string $count iterations
* @param string $algo hash algorithm to use
* @return string
*/
public static function pbkdf2($key, $salt, $length, $count, $algo) {
/* requires PHP >= 5.5 */
Expand Down Expand Up @@ -261,9 +271,6 @@ public static function random($size=128) {
try {
$res = Hm_Functions::random_bytes($size);
}
catch (Error $e) {
throw($e);
}
catch (Exception $e) {
Hm_Functions::cease('No reliable random byte source found');
}
Expand Down
4 changes: 2 additions & 2 deletions lib/crypt_sodium.php
Expand Up @@ -98,11 +98,11 @@ public static function check_password($password, $hash) {
* @param string $salt a salt to use, or create one if needed
* @return array
*/
private static function keygen($key, $salt=false) {
protected static function keygen($key, $salt=false) {
if ($salt === false) {
$salt = \Sodium\randombytes_buf(\Sodium\CRYPTO_SECRETBOX_NONCEBYTES);
}
return array($salt, parent::pbkdf2($key, $salt, 32, parent::$encryption_rounds, parent::$hmac));
return parent::keygen($key, $salt);
}

}
10 changes: 5 additions & 5 deletions lib/module.php
Expand Up @@ -191,19 +191,19 @@ abstract class Hm_Handler_Module {
use Hm_Module_Output;

/* session object */
public $session = false;
public $session;

/* request object */
public $request = false;
public $request;

/* site configuration object */
public $config = false;
public $config;

/* current request id */
protected $page = false;
protected $page = '';

/* user settings */
public $user_config = false;
public $user_config;

/**
* Assign input and state sources
Expand Down
31 changes: 25 additions & 6 deletions lib/modules_exec.php
Expand Up @@ -11,6 +11,18 @@
*/
trait Hm_Output_Module_Exec {

public $handler_response = array();
public $output_response;
public $output_data = array();
public $request;
public $site_config;

/**
* Setup a default language translation
* @return void
*/
abstract public function default_language();

/**
* Run all the handler modules for a page and merge the results
* @param Hm_Request $request details about the request
Expand Down Expand Up @@ -85,6 +97,12 @@ public function run_output_module($input, $protected, $name, $args, $active_sess
*/
trait Hm_Handler_Module_Exec {

public $handler_response = array();
public $output_response;
public $output_data = array();
public $request;
public $site_config;

/**
* Run all the handler modules for a page and merge the results
* @param Hm_Request $request details about the request
Expand Down Expand Up @@ -158,15 +176,16 @@ public function merge_response($request, $session, $page) {
*/
class Hm_Module_Exec {

public $page = false;
public $site_config = false;
public $user_config = false;
public $handler_response = array();
public $output_response = false;
public $output_response;
public $output_data = array();
public $request;
public $site_config;

public $user_config;
public $session;
public $page = '';
public $filters = array();
public $session = false;
public $request = false;
public $handlers = array();
public $outputs = array();

Expand Down

0 comments on commit d9fedf6

Please sign in to comment.