Updated Index Serialiser usage.

This commit is contained in:
flash 2023-07-21 21:56:09 +00:00
parent 9962bbc5df
commit e369038609
4 changed files with 8 additions and 9 deletions

4
composer.lock generated
View file

@ -348,7 +348,7 @@
"source": {
"type": "git",
"url": "https://git.flash.moe/flash/index.git",
"reference": "fc55b73ba177bdec96fdd5d494c2c990475a4cc5"
"reference": "4aae77900be26fccb23a7508744ef17d6b217e5f"
},
"require": {
"ext-mbstring": "*",
@ -386,7 +386,7 @@
],
"description": "Composer package for the common library for my projects.",
"homepage": "https://railgun.sh/index",
"time": "2023-07-21T18:42:55+00:00"
"time": "2023-07-21T21:47:41+00:00"
},
{
"name": "matomo/device-detector",

View file

@ -1,7 +1,6 @@
<?php
namespace Misuzu;
use Index\Autoloader;
use Index\Environment;
use Index\Data\DbTools;
use Misuzu\Config\DbConfig;

View file

@ -4,7 +4,7 @@ namespace Misuzu;
use Misuzu\Users\User;
use Misuzu\Users\UserSession;
use Index\IO\MemoryStream;
use Index\Serialisation\Serialiser;
use Index\Serialisation\UriBase64;
class AuthToken {
private const EPOCH = 1682985600;
@ -97,7 +97,7 @@ class AuthToken {
$prefix = pack('CN', 2, $this->getTimestamp());
$data = $prefix . hash_hmac('sha3-256', $prefix . $data, self::$secretKey, true) . $data;
if($base64)
$data = Serialiser::uriBase64()->serialise($data);
$data = UriBase64::encode($data);
return $data;
}
@ -108,7 +108,7 @@ class AuthToken {
if(empty($data))
return $obj;
if($base64)
$data = Serialiser::uriBase64()->deserialise($data);
$data = UriBase64::decode($data);
if(empty($data))
return $obj;

View file

@ -1,7 +1,7 @@
<?php
namespace Misuzu;
use Index\Serialisation\Serialiser;
use Index\Serialisation\Base32;
class TOTP {
public const DIGITS = 6;
@ -15,7 +15,7 @@ class TOTP {
}
public static function generateKey(): string {
return Serialiser::base32()->serialise(random_bytes(16));
return Base32::encode(random_bytes(16));
}
public static function timecode(?int $timestamp = null, int $interval = self::INTERVAL): int {
@ -24,7 +24,7 @@ class TOTP {
}
public function generate(?int $timestamp = null): string {
$hash = hash_hmac(self::HASH_ALGO, pack('J', self::timecode($timestamp)), Serialiser::base32()->deserialise($this->secretKey), true);
$hash = hash_hmac(self::HASH_ALGO, pack('J', self::timecode($timestamp)), Base32::decode($this->secretKey), true);
$offset = ord($hash[strlen($hash) - 1]) & 0x0F;
$bin = 0;