Skip to content

Commit

Permalink
Fix sha256.
Browse files Browse the repository at this point in the history
  • Loading branch information
csev committed Jan 17, 2024
1 parent 43302c4 commit 4e2bd8a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Util/U.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public static function safe_href($string) {

// Convienence method to wrap sha256
public static function lti_sha256($val) {
return hash('sha256', $val);
if ( is_string($val) ) return hash('sha256', $val);
return null;
}

// Convienence method to get the local path if we are doing
Expand Down
7 changes: 7 additions & 0 deletions tests/Util/UTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,11 @@ public function testServerPrefix() {
$this->assertEquals($CFG->serverPrefix(), "227b19f82bca5eb23f9cd02cfe34dbbe");
}

public function testSha256() {
$out = lti_sha256("hello world");
$this->assertEquals($out, "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9");
$out = lti_sha256(null);
$this->assertEquals($out, null);
}

}

0 comments on commit 4e2bd8a

Please sign in to comment.