From d02c6668b249b145cf9caed3aada560b140e8c19 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 15 Dec 2022 22:29:34 +0000 Subject: [PATCH] ResourcePackManager: added setPackEncryptionKey() this allows plugins to install their own encrypted resource packs --- src/resourcepacks/ResourcePackManager.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/resourcepacks/ResourcePackManager.php b/src/resourcepacks/ResourcePackManager.php index cd5d3a2f7..6d71a1f9f 100644 --- a/src/resourcepacks/ResourcePackManager.php +++ b/src/resourcepacks/ResourcePackManager.php @@ -38,6 +38,7 @@ use function is_float; use function is_int; use function is_string; use function mkdir; +use function strlen; use function strtolower; use const DIRECTORY_SEPARATOR; @@ -202,4 +203,23 @@ class ResourcePackManager{ public function getPackEncryptionKey(string $id) : ?string{ return $this->encryptionKeys[strtolower($id)] ?? null; } + + /** + * Sets the encryption key to use for decrypting the specified resource pack. The pack will **NOT** be decrypted by + * PocketMine-MP; the key is simply passed to the client to allow it to decrypt the pack after downloading it. + */ + public function setPackEncryptionKey(string $id, ?string $key) : void{ + $id = strtolower($id); + if($key === null){ + //allow deprovisioning keys for resource packs that have been removed + unset($this->encryptionKeys[$id]); + }elseif(isset($this->uuidList[$id])){ + if(strlen($key) !== 32){ + throw new \InvalidArgumentException("Encryption key must be exactly 32 bytes long"); + } + $this->encryptionKeys[$id] = $key; + }else{ + throw new \InvalidArgumentException("Unknown pack ID $id"); + } + } }