summaryrefslogtreecommitdiff
path: root/lib/nextpage.php
diff options
context:
space:
mode:
authorlolcat <will@lolcat.ca>2023-11-07 08:04:56 -0500
committerlolcat <will@lolcat.ca>2023-11-07 08:04:56 -0500
commit785452873f0ee0a27fc157b482b7551560f0282d (patch)
tree4c70e240031ed3868425ca683c83ebfd378a9159 /lib/nextpage.php
parent64b090ee058953aed2246967332c7f0b6623cd8f (diff)
fix typo
Diffstat (limited to 'lib/nextpage.php')
-rw-r--r--lib/nextpage.php106
1 files changed, 0 insertions, 106 deletions
diff --git a/lib/nextpage.php b/lib/nextpage.php
deleted file mode 100644
index 7516667..0000000
--- a/lib/nextpage.php
+++ /dev/null
@@ -1,106 +0,0 @@
-<?php
-
-class nextpage{
-
- public function __construct($scraper){
-
- $this->scraper = $scraper;
- }
-
- public function store($payload, $page){
-
- $page = $page[0];
- $password = random_bytes(256); // 2048 bit
- $salt = random_bytes(16);
- $key = hash_pbkdf2("sha512", $password, $salt, 20000, 32, true);
- $iv =
- random_bytes(
- openssl_cipher_iv_length("aes-256-gcm")
- );
-
- $tag = "";
- $out = openssl_encrypt($payload, "aes-256-gcm", $key, OPENSSL_RAW_DATA, $iv, $tag, "", 16);
-
- $key = apcu_inc("key", 1);
-
- apcu_store(
- $page . "." .
- $this->scraper .
- (string)$key,
- gzdeflate($salt.$iv.$out.$tag),
- 900 // cache information for 15 minutes blaze it
- );
-
- return
- $this->scraper . $key . "." .
- rtrim(strtr(base64_encode($password), '+/', '-_'), '=');
- }
-
- public function get($npt, $page){
-
- $page = $page[0];
- $explode = explode(".", $npt, 2);
-
- if(count($explode) !== 2){
-
- throw new Exception("Malformed nextPageToken!");
- }
-
- $apcu = $page . "." . $explode[0];
- $key = $explode[1];
-
- $payload = apcu_fetch($apcu);
-
- if($payload === false){
-
- throw new Exception("The nextPageToken is invalid or has expired!");
- }
-
- $key =
- base64_decode(
- str_pad(
- strtr($key, '-_', '+/'),
- strlen($key) % 4,
- '=',
- STR_PAD_RIGHT
- )
- );
-
- $payload = gzinflate($payload);
-
- $key =
- hash_pbkdf2(
- "sha512",
- $key,
- substr($payload, 0, 16), // salt
- 20000,
- 32,
- true
- );
- $ivlen = openssl_cipher_iv_length("aes-256-gcm");
-
- $payload =
- openssl_decrypt(
- substr(
- $payload,
- 16 + $ivlen,
- -16
- ),
- "aes-256-gcm",
- $key,
- OPENSSL_RAW_DATA,
- substr($payload, 16, $ivlen),
- substr($payload, -16)
- );
-
- if($payload === false){
-
- throw new Exception("The nextPageToken is invalid or has expired!");
- }
-
- // remove the key after using
- apcu_delete($apcu);
-
- return $payload;
- }
-}