- Implemented interface BytecodeObjectInterface into \ncc\Objects > Package

- Implemented interface `BytecodeObjectInterface` into `\ncc\Objects > Vault`
 - Corrected code-smell and code style issues in `\ncc\Objects > Vault`
 - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects > ProjectConfiguration`
 - Removed unused class `\ncc\Objects > SymlinkDictionary`
This commit is contained in:
Netkas 2023-08-19 04:48:23 -04:00
parent 57009c115f
commit b4ae29d0b3
No known key found for this signature in database
GPG key ID: 5DAF58535614062B
7 changed files with 195 additions and 182 deletions

View file

@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `LICENSE.md` & `license.md` are now detected as license files in `\ncc\Classes\ComposerExtension > ComposerSourceBuiltin > convertProject()`
- Added new exception `PathNotFoundException` and implemented it in replacement for `DirectoryNotFoundException` and
`FileNotFoundException` in `\ncc\Exceptions`
- Added a new interface class `BytecodeObjectInterface` which will be used to implement object types for compiled assets
### Fixed
- Fixed MITM attack vector in `\ncc\Classes > HttpClient > prepareCurl()`
@ -79,12 +80,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Corrected code-smell and code style issues in `\ncc\Classes\Extensions\PythonExtension > Python3Runner`
- Corrected code-smell and code style issues in `\ncc\Classes\Extensions\PythonExtension > PythonRunner`
- Corrected code-smell and code style issues in `\ncc\Interfaces > RunnerInterface`
- Implemented interface `BytecodeObjectInterface` into `\ncc\Objects > Package`
- Implemented interface `BytecodeObjectInterface` into `\ncc\Objects > Vault`
- Corrected code-smell and code style issues in `\ncc\Objects > Vault`
- Implemented interface `BytecodeObjectInterface` into `\ncc\Objects > ProjectConfiguration`
## Removed
- Removed `FileNotFoundException` and `DirectoryNotFoundException` from `\ncc\Exceptions`
- Removed the use of `InvalidScopeException` across the project
- Removed references of Win32 from the project as Windows is not going supported
- Removed unused exception `FileNotFoundException` in `\ncc\CLI > HelpMenu`
- Removed unused class `\ncc\Objects > SymlinkDictionary`

View file

@ -0,0 +1,42 @@
<?php
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\Interfaces;
interface BytecodeObjectInterface
{
/**
* Returns an array representation of the object
*
* @param bool $bytecode
* @return array
*/
public function toArray(bool $bytecode=false): array;
/**
* Constructs the object from a BytecodeInterface array representation
*
* @param array $data
* @return BytecodeObjectInterface
*/
public static function fromArray(array $data): BytecodeObjectInterface;
}

View file

@ -96,7 +96,7 @@
}
$VaultObject = new Vault();
$VaultObject->Version = Versions::CREDENTIALS_STORE_VERSION;
$VaultObject->version = Versions::CREDENTIALS_STORE_VERSION;
IO::fwrite($this->store_path, ZiProto::encode($VaultObject->toArray()), 0744);
}
@ -127,7 +127,7 @@
$VaultArray = ZiProto::decode(IO::fread($this->store_path));
$VaultObject = Vault::fromArray($VaultArray);
if($VaultObject->Version !== Versions::CREDENTIALS_STORE_VERSION)
if($VaultObject->version !== Versions::CREDENTIALS_STORE_VERSION)
{
throw new RuntimeException('Credentials store version mismatch');
}

View file

@ -32,6 +32,7 @@
use ncc\Exceptions\IOException;
use ncc\Exceptions\PackageParsingException;
use ncc\Exceptions\PathNotFoundException;
use ncc\Interfaces\BytecodeObjectInterface;
use ncc\Objects\Package\Component;
use ncc\Objects\Package\ExecutionUnit;
use ncc\Objects\Package\Header;
@ -44,7 +45,7 @@
use ncc\Utilities\IO;
use ncc\ZiProto\ZiProto;
class Package
class Package implements BytecodeObjectInterface
{
/**
* The parsed magic bytes of the package into an object representation
@ -347,10 +348,7 @@
}
/**
* Constructs an array representation of the object
*
* @param bool $bytecode
* @return array
* @inheritDoc
*/
public function toArray(bool $bytecode=false): array
{
@ -394,10 +392,9 @@
}
/**
* @param array $data
* @return Package
* @inheritDoc
*/
public static function fromArray(array $data): self
public static function fromArray(array $data): Package
{
$object = new self();

View file

@ -1,24 +1,24 @@
<?php
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
/** @noinspection PhpMissingFieldTypeInspection */
@ -40,6 +40,7 @@
use ncc\Exceptions\UndefinedExecutionPolicyException;
use ncc\Exceptions\UnsupportedCompilerExtensionException;
use ncc\Exceptions\UnsupportedExtensionVersionException;
use ncc\Interfaces\BytecodeObjectInterface;
use ncc\Objects\ProjectConfiguration\Assembly;
use ncc\Objects\ProjectConfiguration\Build;
use ncc\Objects\ProjectConfiguration\Build\BuildConfiguration;
@ -52,7 +53,7 @@
* @author Zi Xing Narrakas
* @copyright Copyright (C) 2022-2022. Nosial - All Rights Reserved.
*/
class ProjectConfiguration
class ProjectConfiguration implements BytecodeObjectInterface
{
/**
* The project configuration
@ -377,53 +378,6 @@
return $required_policies;
}
/**
* Returns an array representation of the object
*
* @param bool $bytecode
* @return array
*/
public function toArray(bool $bytecode=false): array
{
$execution_policies = null;
if($this->execution_policies !== null)
{
$execution_policies = [];
foreach($this->execution_policies as $executionPolicy)
{
$execution_policies[$executionPolicy->Name] = $executionPolicy->toArray($bytecode);
}
}
$results = [];
if($this->project !== null)
{
$results[($bytecode ? Functions::cbc('project') : 'project')] = $this->project->toArray($bytecode);
}
if($this->assembly !== null)
{
$results['assembly'] = $this->assembly->toArray($bytecode);
}
if($this->build !== null)
{
$results[($bytecode ? Functions::cbc('build') : 'build')] = $this->build->toArray($bytecode);
}
if($this->installer !== null)
{
$results[($bytecode ? Functions::cbc('installer') : 'installer')] = $this->installer->toArray($bytecode);
}
if($execution_policies !== null && count($execution_policies) > 0)
{
$results[($bytecode ? Functions::cbc('execution_policies') : 'execution_policies')] = $execution_policies;
}
return $results;
}
/**
* Writes a json representation of the object to a file
*
@ -444,48 +398,6 @@
Functions::encodeJsonFile($this->toArray($bytecode), $path, Functions::FORCE_ARRAY);
}
/**
* Constructs the object from an array representation
*
* @param array $data
* @return ProjectConfiguration
*/
public static function fromArray(array $data): ProjectConfiguration
{
$object = new self();
if(isset($data['project']))
{
$object->project = Project::fromArray($data['project']);
}
if(isset($data['assembly']))
{
$object->assembly = Assembly::fromArray($data['assembly']);
}
if(isset($data['build']))
{
$object->build = Build::fromArray($data['build']);
}
if(isset($data['installer']))
{
$object->installer = Installer::fromArray($data['installer']);
}
if(isset($data['execution_policies']))
{
$object->execution_policies = [];
foreach($data['execution_policies'] as $execution_policy)
{
$object->execution_policies[] = ExecutionPolicy::fromArray($execution_policy);
}
}
return $object;
}
/**
* Loads the object from a file representation
*
@ -539,4 +451,87 @@
return $required_policies;
}
/**
* @inheritDoc
*/
public function toArray(bool $bytecode=false): array
{
$execution_policies = null;
if($this->execution_policies !== null)
{
$execution_policies = [];
foreach($this->execution_policies as $executionPolicy)
{
$execution_policies[$executionPolicy->Name] = $executionPolicy->toArray($bytecode);
}
}
$results = [];
if($this->project !== null)
{
$results[($bytecode ? Functions::cbc('project') : 'project')] = $this->project->toArray($bytecode);
}
if($this->assembly !== null)
{
$results['assembly'] = $this->assembly->toArray($bytecode);
}
if($this->build !== null)
{
$results[($bytecode ? Functions::cbc('build') : 'build')] = $this->build->toArray($bytecode);
}
if($this->installer !== null)
{
$results[($bytecode ? Functions::cbc('installer') : 'installer')] = $this->installer->toArray($bytecode);
}
if($execution_policies !== null && count($execution_policies) > 0)
{
$results[($bytecode ? Functions::cbc('execution_policies') : 'execution_policies')] = $execution_policies;
}
return $results;
}
/**
* @inheritDoc
*/
public static function fromArray(array $data): ProjectConfiguration
{
$object = new self();
if(isset($data['project']))
{
$object->project = Project::fromArray($data['project']);
}
if(isset($data['assembly']))
{
$object->assembly = Assembly::fromArray($data['assembly']);
}
if(isset($data['build']))
{
$object->build = Build::fromArray($data['build']);
}
if(isset($data['installer']))
{
$object->installer = Installer::fromArray($data['installer']);
}
if(isset($data['execution_policies']))
{
$object->execution_policies = [];
foreach($data['execution_policies'] as $execution_policy)
{
$object->execution_policies[] = ExecutionPolicy::fromArray($execution_policy);
}
}
return $object;
}
}

View file

@ -1,28 +0,0 @@
<?php
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\Objects;
class SymlinkDictionary
{
}

View file

@ -27,33 +27,34 @@
use ncc\Enums\AuthenticationType;
use ncc\Enums\Versions;
use ncc\Exceptions\RuntimeException;
use ncc\Interfaces\BytecodeObjectInterface;
use ncc\Interfaces\PasswordInterface;
use ncc\Objects\Vault\Entry;
use ncc\Utilities\Functions;
class Vault
class Vault implements BytecodeObjectInterface
{
/**
* The vault's current version for backwards compatibility
*
* @var string
*/
public $Version;
public $version;
/**
* The vault's stored credential entries
*
* @var Entry[]
*/
public $Entries;
public $entries;
/**
* Public Constructor
*/
public function __construct()
{
$this->Version = Versions::CREDENTIALS_STORE_VERSION;
$this->Entries = [];
$this->version = Versions::CREDENTIALS_STORE_VERSION;
$this->entries = [];
}
/**
@ -68,10 +69,12 @@
public function addEntry(string $name, PasswordInterface $password, bool $encrypt=true): bool
{
// Check if the entry already exists
foreach($this->Entries as $entry)
foreach($this->entries as $entry)
{
if($entry->getName() === $name)
{
return false;
}
}
// Create the new entry
@ -81,7 +84,7 @@
$entry->setAuthentication($password);
// Add the entry to the vault
$this->Entries[] = $entry;
$this->entries[] = $entry;
return true;
}
@ -95,17 +98,17 @@
public function deleteEntry(string $name): bool
{
// Find the entry
foreach($this->Entries as $index => $entry)
foreach($this->entries as $index => $entry)
{
if($entry->getName() === $name)
{
// Remove the entry
unset($this->Entries[$index]);
unset($this->entries[$index]);
return true;
}
}
// Entry not found
// Entry isn't found
return false;
}
@ -117,7 +120,7 @@
*/
public function getEntries(): array
{
return $this->Entries;
return $this->entries;
}
/**
@ -128,10 +131,12 @@
*/
public function getEntry(string $name): ?Entry
{
foreach($this->Entries as $entry)
foreach($this->entries as $entry)
{
if($entry->getName() === $name)
{
return $entry;
}
}
return null;
@ -150,14 +155,13 @@
{
$entry = $this->getEntry($name);
if($entry === null)
return false;
if($entry->getPassword() === null)
{
if($entry->isEncrypted() && !$entry->isCurrentlyDecrypted())
{
return $entry->unlock($password);
}
return false;
}
if(($entry->getPassword() === null) && $entry->isEncrypted() && !$entry->isCurrentlyDecrypted())
{
return $entry->unlock($password);
}
$input = [];
@ -175,40 +179,37 @@
}
/**
* Returns an array representation of the object
*
* @param bool $bytecode
* @return array
* @inheritDoc
*/
public function toArray(bool $bytecode=false): array
{
$entries = [];
foreach($this->Entries as $entry)
foreach($this->entries as $entry)
{
$entries[] = $entry->toArray($bytecode);
}
return [
($bytecode ? Functions::cbc('version') : 'version') => $this->Version,
($bytecode ? Functions::cbc('version') : 'version') => $this->version,
($bytecode ? Functions::cbc('entries') : 'entries') => $entries,
];
}
/**
* Constructs a new object from an array
*
* @param array $array
* @return Vault
* @inheritDoc
*/
public static function fromArray(array $array): Vault
public static function fromArray(array $data): Vault
{
$vault = new Vault();
$vault->Version = Functions::array_bc($array, 'version');
$entries = Functions::array_bc($array, 'entries');
$vault->Entries = [];
$vault->version = Functions::array_bc($data, 'version');
$entries = Functions::array_bc($data, 'entries');
$vault->entries = [];
foreach($entries as $entry)
$vault->Entries[] = Entry::fromArray($entry);
{
$vault->entries[] = Entry::fromArray($entry);
}
return $vault;
}