mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-11-25 00:26:44 +00:00
4abed1d7c7
Done by phpcbf over composer fix Change-Id: I9b7419e025ef499ff68be79789d76ad4b886d256
45 lines
940 B
PHP
45 lines
940 B
PHP
<?php
|
|
|
|
// @codingStandardsIgnoreLine Squiz.Classes.ValidClassName.NotCamelCaps
|
|
class Scribunto_LuaHashLibrary extends Scribunto_LuaLibraryBase {
|
|
|
|
public function register() {
|
|
$lib = [
|
|
'listAlgorithms' => [ $this, 'listAlgorithms' ],
|
|
'hashValue' => [ $this, 'hashValue' ],
|
|
];
|
|
|
|
return $this->getEngine()->registerInterface( 'mw.hash.lua', $lib );
|
|
}
|
|
|
|
/**
|
|
* Returns a list of known/ supported hash algorithms
|
|
*
|
|
* @return string[][]
|
|
*/
|
|
public function listAlgorithms() {
|
|
$algos = hash_algos();
|
|
$algos = array_combine( range( 1, count( $algos ) ), $algos );
|
|
|
|
return [ $algos ];
|
|
}
|
|
|
|
/**
|
|
* Hash a given value.
|
|
*
|
|
* @param string $algo
|
|
* @param string $value
|
|
* @return string[]
|
|
*/
|
|
public function hashValue( $algo, $value ) {
|
|
if ( !in_array( $algo, hash_algos() ) ) {
|
|
throw new Scribunto_LuaError( "Unknown hashing algorithm: $algo" );
|
|
}
|
|
|
|
$hash = hash( $algo, $value );
|
|
|
|
return [ $hash ];
|
|
}
|
|
|
|
}
|