| 1: | <?php | 
| 2: | /* | 
| 3: | You may not change or alter any portion of this comment or credits | 
| 4: | of supporting developers from this source code or any supporting source code | 
| 5: | which is considered copyrighted (c) material of the original comment or credit authors. | 
| 6: | |
| 7: | This program is distributed in the hope that it will be useful, | 
| 8: | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 9: | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 
| 10: | */ | 
| 11: | |
| 12: | namespace Xmf\Key; | 
| 13: | |
| 14: | use Xmf\Random; | 
| 15: | |
| 16: | /** | 
| 17: | * Xmf\Key\Basic | 
| 18: | * | 
| 19: | * a basic general purpose key | 
| 20: | * | 
| 21: | * @category Xmf\Key\Basic | 
| 22: | * @package Xmf | 
| 23: | * @author Richard Griffith <richard@geekwright.com> | 
| 24: | * @copyright 2018-2023 XOOPS Project (https://xoops.org) | 
| 25: | * @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) | 
| 26: | * @link https://xoops.org | 
| 27: | */ | 
| 28: | class Basic extends KeyAbstract | 
| 29: | { | 
| 30: | /** | 
| 31: | * get key for use in signing | 
| 32: | * | 
| 33: | * @return string verifying key, false on error | 
| 34: | */ | 
| 35: | public function getSigning() | 
| 36: | { | 
| 37: | return (string) $this->storage->fetch($this->name); | 
| 38: | } | 
| 39: | |
| 40: | /** | 
| 41: | * get key for use in verifying | 
| 42: | * | 
| 43: | * @return string verifying key, false on error | 
| 44: | */ | 
| 45: | public function getVerifying() | 
| 46: | { | 
| 47: | return (string) $this->storage->fetch($this->name); | 
| 48: | } | 
| 49: | |
| 50: | /** | 
| 51: | * create the key and store it for use | 
| 52: | * | 
| 53: | * @return boolean true if key was created and stored, otherwise false | 
| 54: | */ | 
| 55: | public function create() | 
| 56: | { | 
| 57: | if (!$this->storage->exists($this->name)) { | 
| 58: | return $this->storage->save($this->name, Random::generateKey()); | 
| 59: | } | 
| 60: | return false; | 
| 61: | } | 
| 62: | |
| 63: | /** | 
| 64: | * delete the key | 
| 65: | * | 
| 66: | * @return boolean true if key was deleted, otherwise false | 
| 67: | */ | 
| 68: | public function kill() | 
| 69: | { | 
| 70: | return $this->storage->delete($this->name); | 
| 71: | } | 
| 72: | } | 
| 73: |