diff --git a/Admin/Install/db.json b/Admin/Install/db.json index 99ce29a..f658ecf 100644 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -52,6 +52,12 @@ "type": "TINYINT", "null": false }, + "media_encryptionhash": { + "name": "media_encryptionhash", + "type": "VARCHAR(255)", + "null": true, + "default": null + }, "media_extension": { "name": "media_extension", "type": "VARCHAR(50)", diff --git a/Models/Media.php b/Models/Media.php index 71c63f4..d5e0dcf 100644 --- a/Models/Media.php +++ b/Models/Media.php @@ -112,7 +112,22 @@ class Media implements \JsonSerializable * @since 1.0.0 */ protected string $description = ''; - protected $descriptionRaw = ''; + + /** + * Media Description. + * + * @var string + * @since 1.0.0 + */ + protected string $descriptionRaw = ''; + + /** + * Media encryption hash. + * + * @var null|string + * @since 1.0.0 + */ + protected ?string $encryptionHash = null; /** * Constructor. @@ -134,6 +149,58 @@ class Media implements \JsonSerializable return $this->id; } + public function encrypt(string $password, string $outputPath) : void + { + // todo: implement; + } + + public function decrypt(string $password, string $outputPath) : string + { + // todo: implement; + + return ''; + } + + /** + * Set encryption hash + * + * @param null|string $encryptionHash Hash from encryption password + * + * @return void + * + * @since 1.0.0 + */ + public function setEncryptionHash(?string $encryptionHash) : void + { + $this->encryptionHash = $encryptionHash; + } + + /** + * Is media file encrypted? + * + * @return bool + * + * @since 1.0.0 + */ + public function isEncrypted() : bool + { + return $this->encryptionHash !== null; + } + + /** + * Compare hash with encryption hash of the media file + * + * @param string $hash User hash + * + * @return bool + * + * @since 1.0.0 + */ + public function compareEncryptionHash(string $hash) : bool + { + return \hash_equals($this->encryptionHash, $hash); + } + /** * @return bool * diff --git a/Models/MediaMapper.php b/Models/MediaMapper.php index ec08f35..ca2d4a7 100644 --- a/Models/MediaMapper.php +++ b/Models/MediaMapper.php @@ -44,6 +44,7 @@ class MediaMapper extends DataMapperAbstract 'media_file' => ['name' => 'media_file', 'type' => 'string', 'internal' => 'path', 'autocomplete' => true], 'media_virtual' => ['name' => 'media_virtual', 'type' => 'string', 'internal' => 'virtualPath', 'autocomplete' => true], 'media_absolute' => ['name' => 'media_absolute', 'type' => 'bool', 'internal' => 'isAbsolute'], + 'media_encryptionhash' => ['name' => 'media_encryptionhash', 'type' => 'string', 'internal' => 'encryptionHash'], 'media_extension' => ['name' => 'media_extension', 'type' => 'string', 'internal' => 'extension'], 'media_size' => ['name' => 'media_size', 'type' => 'int', 'internal' => 'size'], 'media_created_by' => ['name' => 'media_created_by', 'type' => 'int', 'internal' => 'createdBy'],