Updated Index Serialiser usage.
This commit is contained in:
parent
9962bbc5df
commit
e369038609
4 changed files with 8 additions and 9 deletions
4
composer.lock
generated
4
composer.lock
generated
|
@ -348,7 +348,7 @@
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://git.flash.moe/flash/index.git",
|
"url": "https://git.flash.moe/flash/index.git",
|
||||||
"reference": "fc55b73ba177bdec96fdd5d494c2c990475a4cc5"
|
"reference": "4aae77900be26fccb23a7508744ef17d6b217e5f"
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"ext-mbstring": "*",
|
"ext-mbstring": "*",
|
||||||
|
@ -386,7 +386,7 @@
|
||||||
],
|
],
|
||||||
"description": "Composer package for the common library for my projects.",
|
"description": "Composer package for the common library for my projects.",
|
||||||
"homepage": "https://railgun.sh/index",
|
"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",
|
"name": "matomo/device-detector",
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Misuzu;
|
namespace Misuzu;
|
||||||
|
|
||||||
use Index\Autoloader;
|
|
||||||
use Index\Environment;
|
use Index\Environment;
|
||||||
use Index\Data\DbTools;
|
use Index\Data\DbTools;
|
||||||
use Misuzu\Config\DbConfig;
|
use Misuzu\Config\DbConfig;
|
||||||
|
|
|
@ -4,7 +4,7 @@ namespace Misuzu;
|
||||||
use Misuzu\Users\User;
|
use Misuzu\Users\User;
|
||||||
use Misuzu\Users\UserSession;
|
use Misuzu\Users\UserSession;
|
||||||
use Index\IO\MemoryStream;
|
use Index\IO\MemoryStream;
|
||||||
use Index\Serialisation\Serialiser;
|
use Index\Serialisation\UriBase64;
|
||||||
|
|
||||||
class AuthToken {
|
class AuthToken {
|
||||||
private const EPOCH = 1682985600;
|
private const EPOCH = 1682985600;
|
||||||
|
@ -97,7 +97,7 @@ class AuthToken {
|
||||||
$prefix = pack('CN', 2, $this->getTimestamp());
|
$prefix = pack('CN', 2, $this->getTimestamp());
|
||||||
$data = $prefix . hash_hmac('sha3-256', $prefix . $data, self::$secretKey, true) . $data;
|
$data = $prefix . hash_hmac('sha3-256', $prefix . $data, self::$secretKey, true) . $data;
|
||||||
if($base64)
|
if($base64)
|
||||||
$data = Serialiser::uriBase64()->serialise($data);
|
$data = UriBase64::encode($data);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ class AuthToken {
|
||||||
if(empty($data))
|
if(empty($data))
|
||||||
return $obj;
|
return $obj;
|
||||||
if($base64)
|
if($base64)
|
||||||
$data = Serialiser::uriBase64()->deserialise($data);
|
$data = UriBase64::decode($data);
|
||||||
if(empty($data))
|
if(empty($data))
|
||||||
return $obj;
|
return $obj;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Misuzu;
|
namespace Misuzu;
|
||||||
|
|
||||||
use Index\Serialisation\Serialiser;
|
use Index\Serialisation\Base32;
|
||||||
|
|
||||||
class TOTP {
|
class TOTP {
|
||||||
public const DIGITS = 6;
|
public const DIGITS = 6;
|
||||||
|
@ -15,7 +15,7 @@ class TOTP {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function generateKey(): string {
|
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 {
|
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 {
|
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;
|
$offset = ord($hash[strlen($hash) - 1]) & 0x0F;
|
||||||
|
|
||||||
$bin = 0;
|
$bin = 0;
|
||||||
|
|
Loading…
Reference in a new issue