MediaWiki  1.34.4
HashLibrary.php
Go to the documentation of this file.
1 <?php
2 
4 
5  public function register() {
6  $lib = [
7  'listAlgorithms' => [ $this, 'listAlgorithms' ],
8  'hashValue' => [ $this, 'hashValue' ],
9  ];
10 
11  return $this->getEngine()->registerInterface( 'mw.hash.lua', $lib );
12  }
13 
20  public function listAlgorithms() {
21  $algos = hash_algos();
22  $algos = array_combine( range( 1, count( $algos ) ), $algos );
23 
24  return [ $algos ];
25  }
26 
35  public function hashValue( $algo, $value ) {
36  if ( !in_array( $algo, hash_algos() ) ) {
37  throw new Scribunto_LuaError( "Unknown hashing algorithm: $algo" );
38  }
39 
40  $hash = hash( $algo, $value );
41 
42  return [ $hash ];
43  }
44 
45 }
Scribunto_LuaHashLibrary\hashValue
hashValue( $algo, $value)
Hash a given value.
Definition: HashLibrary.php:35
Scribunto_LuaError
Definition: LuaCommon.php:992
Scribunto_LuaHashLibrary\listAlgorithms
listAlgorithms()
Returns a list of known/ supported hash algorithms.
Definition: HashLibrary.php:20
Scribunto_LuaHashLibrary
Definition: HashLibrary.php:3
Scribunto_LuaLibraryBase\getEngine
getEngine()
Get the engine.
Definition: LibraryBase.php:56
Scribunto_LuaLibraryBase
This class provides some basic services that Lua libraries will probably need.
Definition: LibraryBase.php:27