- Implemented interface BytecodeObjectInterface into \ncc\Objects > ExecutionPointers

- Implemented interface `BytecodeObjectInterface` into `\ncc\Objects > DefinedRemoteSource`
 - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\Vault > Entry`
 - Corrected code-smell and code style issues in `\ncc\Objects\Vault\Password > AccessToken`
 - Corrected code-smell and code style issues in `\ncc\Objects\Vault\Password > UsernamePassword`
 - Extended `PasswordInterface` with `BytecodeObjectInterface`
 - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\SymlinkDictionary > SymlinkEntry`
This commit is contained in:
Netkas 2023-08-19 08:38:13 -04:00
parent 8df38191c6
commit 7138913ef3
No known key found for this signature in database
GPG key ID: 5DAF58535614062B
15 changed files with 378 additions and 356 deletions

View file

@ -84,6 +84,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Implemented interface `BytecodeObjectInterface` into `\ncc\Objects > Vault` - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects > Vault`
- Corrected code-smell and code style issues in `\ncc\Objects > Vault` - Corrected code-smell and code style issues in `\ncc\Objects > Vault`
- Implemented interface `BytecodeObjectInterface` into `\ncc\Objects > ProjectConfiguration` - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects > ProjectConfiguration`
- Implemented interface `BytecodeObjectInterface` into `\ncc\Objects > ExecutionPointers`
- Implemented interface `BytecodeObjectInterface` into `\ncc\Objects > DefinedRemoteSource`
- Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\Vault > Entry`
- Corrected code-smell and code style issues in `\ncc\Objects\Vault\Password > AccessToken`
- Corrected code-smell and code style issues in `\ncc\Objects\Vault\Password > UsernamePassword`
- Extended `PasswordInterface` with `BytecodeObjectInterface`
- Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\SymlinkDictionary > SymlinkEntry`
## Removed ## Removed
- Removed `FileNotFoundException` and `DirectoryNotFoundException` from `\ncc\Exceptions` - Removed `FileNotFoundException` and `DirectoryNotFoundException` from `\ncc\Exceptions`

View file

@ -866,7 +866,7 @@
try try
{ {
$definedEntry = DefinedRemoteSource::fromArray(Functions::loadJsonFile($repo_path, Functions::FORCE_ARRAY)); $definedEntry = DefinedRemoteSource::fromArray(Functions::loadJsonFile($repo_path, Functions::FORCE_ARRAY));
if(!$source_manager->getRemoteSource($definedEntry->Name)) if(!$source_manager->getRemoteSource($definedEntry->name))
$source_manager->addRemoteSource($definedEntry); $source_manager->addRemoteSource($definedEntry);
} }
catch(Exception $e) catch(Exception $e)

View file

@ -105,7 +105,7 @@ namespace ncc\CLI\Management;
Console::out('Remote sources:', 1); Console::out('Remote sources:', 1);
foreach($sources as $source) foreach($sources as $source)
{ {
Console::out(' - ' . $source->Name . ' (' . $source->Host . ')', 1); Console::out(' - ' . $source->name . ' (' . $source->host . ')', 1);
} }
Console::out('Total: ' . count($sources), 1); Console::out('Total: ' . count($sources), 1);
@ -153,10 +153,10 @@ namespace ncc\CLI\Management;
$source_manager = new RemoteSourcesManager(); $source_manager = new RemoteSourcesManager();
$source = new DefinedRemoteSource(); $source = new DefinedRemoteSource();
$source->Name = $name; $source->name = $name;
$source->Type = $type; $source->type = $type;
$source->Host = $host; $source->host = $host;
$source->SSL = $ssl; $source->ssl = $ssl;
if(!$source_manager->addRemoteSource($source)) if(!$source_manager->addRemoteSource($source))
{ {

View file

@ -58,11 +58,11 @@ namespace ncc\Classes\GithubExtension;
public static function getGitRepository(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry = null): RepositoryQueryResults public static function getGitRepository(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry = null): RepositoryQueryResults
{ {
$httpRequest = new HttpRequest(); $httpRequest = new HttpRequest();
$protocol = ($definedRemoteSource->SSL ? "https" : "http"); $protocol = ($definedRemoteSource->ssl ? "https" : "http");
$owner_f = str_ireplace("/", "%2F", $packageInput->vendor); $owner_f = str_ireplace("/", "%2F", $packageInput->vendor);
$owner_f = str_ireplace(".", "%2F", $owner_f); $owner_f = str_ireplace(".", "%2F", $owner_f);
$repository = urlencode($packageInput->package); $repository = urlencode($packageInput->package);
$httpRequest->Url = $protocol . '://' . $definedRemoteSource->Host . "/repos/$owner_f/$repository"; $httpRequest->Url = $protocol . '://' . $definedRemoteSource->host . "/repos/$owner_f/$repository";
$response_decoded = self::getJsonResponse($httpRequest, $entry); $response_decoded = self::getJsonResponse($httpRequest, $entry);
$query = new RepositoryQueryResults(); $query = new RepositoryQueryResults();
@ -127,11 +127,11 @@ namespace ncc\Classes\GithubExtension;
private static function getReleases(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry = null): array private static function getReleases(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry = null): array
{ {
$httpRequest = new HttpRequest(); $httpRequest = new HttpRequest();
$protocol = ($definedRemoteSource->SSL ? "https" : "http"); $protocol = ($definedRemoteSource->ssl ? "https" : "http");
$owner_f = str_ireplace("/", "%2F", $packageInput->vendor); $owner_f = str_ireplace("/", "%2F", $packageInput->vendor);
$owner_f = str_ireplace(".", "%2F", $owner_f); $owner_f = str_ireplace(".", "%2F", $owner_f);
$repository = urlencode($packageInput->package); $repository = urlencode($packageInput->package);
$httpRequest->Url = $protocol . '://' . $definedRemoteSource->Host . "/repos/$owner_f/$repository/releases"; $httpRequest->Url = $protocol . '://' . $definedRemoteSource->host . "/repos/$owner_f/$repository/releases";
$response_decoded = self::getJsonResponse($httpRequest, $entry); $response_decoded = self::getJsonResponse($httpRequest, $entry);
if(count($response_decoded) === 0) if(count($response_decoded) === 0)

View file

@ -57,12 +57,12 @@
public static function getGitRepository(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry=null): RepositoryQueryResults public static function getGitRepository(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry=null): RepositoryQueryResults
{ {
$httpRequest = new HttpRequest(); $httpRequest = new HttpRequest();
$protocol = ($definedRemoteSource->SSL ? "https" : "http"); $protocol = ($definedRemoteSource->ssl ? "https" : "http");
$owner_f = str_ireplace("/", "%2F", $packageInput->vendor); $owner_f = str_ireplace("/", "%2F", $packageInput->vendor);
$owner_f = str_ireplace(".", "%2F", $owner_f); $owner_f = str_ireplace(".", "%2F", $owner_f);
$project_f = str_ireplace("/", "%2F", $packageInput->package); $project_f = str_ireplace("/", "%2F", $packageInput->package);
$project_f = str_ireplace(".", "%2F", $project_f); $project_f = str_ireplace(".", "%2F", $project_f);
$httpRequest->Url = $protocol . '://' . $definedRemoteSource->Host . "/api/v4/projects/$owner_f%2F$project_f"; $httpRequest->Url = $protocol . '://' . $definedRemoteSource->host . "/api/v4/projects/$owner_f%2F$project_f";
$httpRequest = Functions::prepareGitServiceRequest($httpRequest, $entry); $httpRequest = Functions::prepareGitServiceRequest($httpRequest, $entry);
$response = HttpClient::request($httpRequest, true); $response = HttpClient::request($httpRequest, true);
@ -175,7 +175,7 @@
*/ */
public static function getNccPackage(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry = null): RepositoryQueryResults public static function getNccPackage(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry = null): RepositoryQueryResults
{ {
throw new NotSupportedException(sprintf('The given repository source "%s" does not support ncc packages.', $definedRemoteSource->Host)); throw new NotSupportedException(sprintf('The given repository source "%s" does not support ncc packages.', $definedRemoteSource->host));
} }
/** /**
@ -194,13 +194,13 @@
private static function getReleases(string $owner, string $repository, DefinedRemoteSource $definedRemoteSource, ?Entry $entry): array private static function getReleases(string $owner, string $repository, DefinedRemoteSource $definedRemoteSource, ?Entry $entry): array
{ {
$httpRequest = new HttpRequest(); $httpRequest = new HttpRequest();
$protocol = ($definedRemoteSource->SSL ? "https" : "http"); $protocol = ($definedRemoteSource->ssl ? "https" : "http");
$owner_f = str_ireplace("/", "%2F", $owner); $owner_f = str_ireplace("/", "%2F", $owner);
$owner_f = str_ireplace(".", "%2F", $owner_f); $owner_f = str_ireplace(".", "%2F", $owner_f);
$repository_f = str_ireplace("/", "%2F", $repository); $repository_f = str_ireplace("/", "%2F", $repository);
$repository_f = str_ireplace(".", "%2F", $repository_f); $repository_f = str_ireplace(".", "%2F", $repository_f);
$httpRequest->Url = $protocol . '://' . $definedRemoteSource->Host . "/api/v4/projects/$owner_f%2F$repository_f/releases"; $httpRequest->Url = $protocol . '://' . $definedRemoteSource->host . "/api/v4/projects/$owner_f%2F$repository_f/releases";
$httpRequest = Functions::prepareGitServiceRequest($httpRequest, $entry); $httpRequest = Functions::prepareGitServiceRequest($httpRequest, $entry);
$response = HttpClient::request($httpRequest, true); $response = HttpClient::request($httpRequest, true);

View file

@ -1,41 +1,29 @@
<?php <?php
/* /*
* Copyright (c) Nosial 2022-2023, all rights reserved. * 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 * 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 * 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 * 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 * Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions: * conditions:
* *
* The above copyright notice and this permission notice shall be included in all copies or substantial portions * The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software. * of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * 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 * 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 * 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 * 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 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
* *
*/ */
namespace ncc\Interfaces; namespace ncc\Interfaces;
interface PasswordInterface interface PasswordInterface extends BytecodeObjectInterface
{ {
/**
* @param bool $bytecode
* @return array
*/
public function toArray(bool $bytecode=false): array;
/**
* @param array $data
* @return static
*/
public static function fromArray(array $data): self;
/** /**
* @return string * @return string
*/ */

View file

@ -441,10 +441,10 @@
{ {
Console::outVerbose('Adding remote source ' . $package->header->UpdateSource->Repository->Name); Console::outVerbose('Adding remote source ' . $package->header->UpdateSource->Repository->Name);
$defined_remote_source = new DefinedRemoteSource(); $defined_remote_source = new DefinedRemoteSource();
$defined_remote_source->Name = $package->header->UpdateSource->Repository->Name; $defined_remote_source->name = $package->header->UpdateSource->Repository->Name;
$defined_remote_source->Host = $package->header->UpdateSource->Repository->Host; $defined_remote_source->host = $package->header->UpdateSource->Repository->Host;
$defined_remote_source->Type = $package->header->UpdateSource->Repository->Type; $defined_remote_source->type = $package->header->UpdateSource->Repository->Type;
$defined_remote_source->SSL = $package->header->UpdateSource->Repository->SSL; $defined_remote_source->ssl = $package->header->UpdateSource->Repository->SSL;
$sources_manager->addRemoteSource($defined_remote_source); $sources_manager->addRemoteSource($defined_remote_source);
} }

View file

@ -112,7 +112,7 @@
{ {
foreach($this->Sources as $existingSource) foreach($this->Sources as $existingSource)
{ {
if($existingSource->Name === $source->Name) if($existingSource->name === $source->name)
return false; return false;
} }
@ -130,7 +130,7 @@
{ {
foreach($this->Sources as $source) foreach($this->Sources as $source)
{ {
if($source->Name === $name) if($source->name === $name)
{ {
return $source; return $source;
} }
@ -149,7 +149,7 @@
{ {
foreach($this->Sources as $index => $source) foreach($this->Sources as $index => $source)
{ {
if($source->Name === $name) if($source->name === $name)
{ {
unset($this->Sources[$index]); unset($this->Sources[$index]);
return true; return true;

View file

@ -25,9 +25,10 @@
namespace ncc\Objects; namespace ncc\Objects;
use ncc\Enums\DefinedRemoteSourceType; use ncc\Enums\DefinedRemoteSourceType;
use ncc\Interfaces\BytecodeObjectInterface;
use ncc\Utilities\Functions; use ncc\Utilities\Functions;
class DefinedRemoteSource class DefinedRemoteSource implements BytecodeObjectInterface
{ {
/** /**
* The unique name of the remote source. (e.g. 'github') * The unique name of the remote source. (e.g. 'github')
@ -36,28 +37,28 @@
* *
* @var string * @var string
*/ */
public $Name; public $name;
/** /**
* The type of service NCC should use with this source (gitlab, github, etc...). * The type of service NCC should use with this source (gitlab, github, etc...).
* *
* @var string|DefinedRemoteSourceType * @var string|DefinedRemoteSourceType
*/ */
public $Type; public $type;
/** /**
* The host of the service NCC should use with this source (gitlab.com, github.com, git.example.com:8080 etc...). * The host of the service NCC should use with this source (gitlab.com, github.com, git.example.com:8080 etc...).
* *
* @var string * @var string
*/ */
public $Host; public $host;
/** /**
* If SSL should be used when connecting to the service * If SSL should be used when connecting to the service
* *
* @var bool * @var bool
*/ */
public $SSL; public $ssl;
/** /**
* Returns an array representation of the object * Returns an array representation of the object
@ -68,10 +69,10 @@
public function toArray(bool $bytecode=false): array public function toArray(bool $bytecode=false): array
{ {
return [ return [
($bytecode ? Functions::cbc('name') : 'name') => $this->Name, ($bytecode ? Functions::cbc('name') : 'name') => $this->name,
($bytecode ? Functions::cbc('type') : 'type') => $this->Type, ($bytecode ? Functions::cbc('type') : 'type') => $this->type,
($bytecode ? Functions::cbc('host') : 'host') => $this->Host, ($bytecode ? Functions::cbc('host') : 'host') => $this->host,
($bytecode ? Functions::cbc('ssl') : 'ssl') => $this->SSL ($bytecode ? Functions::cbc('ssl') : 'ssl') => $this->ssl
]; ];
} }
@ -85,10 +86,10 @@
{ {
$definedRemoteSource = new self(); $definedRemoteSource = new self();
$definedRemoteSource->Name = Functions::array_bc($data, 'name'); $definedRemoteSource->name = Functions::array_bc($data, 'name');
$definedRemoteSource->Type = Functions::array_bc($data, 'type'); $definedRemoteSource->type = Functions::array_bc($data, 'type');
$definedRemoteSource->Host = Functions::array_bc($data, 'host'); $definedRemoteSource->host = Functions::array_bc($data, 'host');
$definedRemoteSource->SSL = Functions::array_bc($data, 'ssl'); $definedRemoteSource->ssl = Functions::array_bc($data, 'ssl');
return $definedRemoteSource; return $definedRemoteSource;
} }

View file

@ -25,12 +25,13 @@
namespace ncc\Objects; namespace ncc\Objects;
use ncc\Exceptions\PathNotFoundException; use ncc\Exceptions\PathNotFoundException;
use ncc\Interfaces\BytecodeObjectInterface;
use ncc\Objects\ExecutionPointers\ExecutionPointer; use ncc\Objects\ExecutionPointers\ExecutionPointer;
use ncc\Objects\Package\ExecutionUnit; use ncc\Objects\Package\ExecutionUnit;
use ncc\Utilities\Functions; use ncc\Utilities\Functions;
use ncc\Utilities\Validate; use ncc\Utilities\Validate;
class ExecutionPointers class ExecutionPointers implements BytecodeObjectInterface
{ {
/** /**
* @var string * @var string
@ -171,10 +172,7 @@
} }
/** /**
* Returns an array representation of the object * @inheritDoc
*
* @param bool $bytecode
* @return array
*/ */
public function toArray(bool $bytecode=false): array public function toArray(bool $bytecode=false): array
{ {
@ -191,10 +189,7 @@
} }
/** /**
* Constructs object from an array representation * @inheritDoc
*
* @param array $data
* @return ExecutionPointers
*/ */
public static function fromArray(array $data): self public static function fromArray(array $data): self
{ {

View file

@ -1,32 +1,33 @@
<?php <?php
/* /*
* Copyright (c) Nosial 2022-2023, all rights reserved. * 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 * 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 * 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 * 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 * Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions: * conditions:
* *
* The above copyright notice and this permission notice shall be included in all copies or substantial portions * The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software. * of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * 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 * 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 * 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 * 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 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
* *
*/ */
/** @noinspection PhpMissingFieldTypeInspection */ /** @noinspection PhpMissingFieldTypeInspection */
namespace ncc\Objects\SymlinkDictionary; namespace ncc\Objects\SymlinkDictionary;
use ncc\Interfaces\BytecodeObjectInterface;
use ncc\Utilities\Functions; use ncc\Utilities\Functions;
class SymlinkEntry class SymlinkEntry implements BytecodeObjectInterface
{ {
/** /**
* The name of the package that the symlink is for * The name of the package that the symlink is for
@ -59,10 +60,7 @@
} }
/** /**
* Returns a string representation of the object * @inheritDoc
*
* @param bool $bytecode
* @return array
*/ */
public function toArray(bool $bytecode=false): array public function toArray(bool $bytecode=false): array
{ {
@ -74,10 +72,7 @@
} }
/** /**
* Constructs a new SymlinkEntry from an array representation * @inheritDoc
*
* @param array $data
* @return SymlinkEntry
*/ */
public static function fromArray(array $data): SymlinkEntry public static function fromArray(array $data): SymlinkEntry
{ {

View file

@ -1,24 +1,24 @@
<?php <?php
/* /*
* Copyright (c) Nosial 2022-2023, all rights reserved. * 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 * 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 * 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 * 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 * Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions: * conditions:
* *
* The above copyright notice and this permission notice shall be included in all copies or substantial portions * The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software. * of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * 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 * 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 * 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 * 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 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
* *
*/ */
/** @noinspection PhpMissingFieldTypeInspection */ /** @noinspection PhpMissingFieldTypeInspection */
@ -28,35 +28,36 @@
use ncc\Defuse\Crypto\Crypto; use ncc\Defuse\Crypto\Crypto;
use ncc\Defuse\Crypto\Exception\EnvironmentIsBrokenException; use ncc\Defuse\Crypto\Exception\EnvironmentIsBrokenException;
use ncc\Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException; use ncc\Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException;
use ncc\Exceptions\RuntimeException; use ncc\Interfaces\BytecodeObjectInterface;
use ncc\Interfaces\PasswordInterface; use ncc\Interfaces\PasswordInterface;
use ncc\Objects\Vault\Password\AccessToken; use ncc\Objects\Vault\Password\AccessToken;
use ncc\Objects\Vault\Password\UsernamePassword; use ncc\Objects\Vault\Password\UsernamePassword;
use ncc\Utilities\Functions; use ncc\Utilities\Functions;
use ncc\ZiProto\ZiProto; use ncc\ZiProto\ZiProto;
use RuntimeException;
class Entry class Entry implements BytecodeObjectInterface
{ {
/** /**
* The entry's unique identifier * The entry's unique identifier
* *
* @var string * @var string
*/ */
private $Name; private $name;
/** /**
* Whether the entry's password is encrypted * Whether the entry's password is encrypted
* *
* @var bool * @var bool
*/ */
private $Encrypted; private $encrypted;
/** /**
* The entry's password * The entry's password
* *
* @var PasswordInterface|string|null * @var PasswordInterface|string|null
*/ */
private $Password; private $password;
/** /**
* Whether the entry's password is currently decrypted in memory * Whether the entry's password is currently decrypted in memory
@ -64,7 +65,7 @@
* *
* @var bool * @var bool
*/ */
private $IsCurrentlyDecrypted; private $currently_decrypted;
/** /**
* Returns an array representation of the object * Returns an array representation of the object
@ -72,8 +73,8 @@
*/ */
public function __construct() public function __construct()
{ {
$this->Encrypted = true; $this->encrypted = true;
$this->IsCurrentlyDecrypted = true; $this->currently_decrypted = true;
} }
/** /**
@ -88,42 +89,58 @@
*/ */
public function authenticate(array $input): bool public function authenticate(array $input): bool
{ {
if(!$this->IsCurrentlyDecrypted) if(!$this->currently_decrypted)
{
return false; return false;
}
if($this->Password == null) if($this->password === null)
{
return false; return false;
}
switch($this->Password->getAuthenticationType()) switch($this->password->getAuthenticationType())
{ {
case AuthenticationType::USERNAME_PASSWORD: case AuthenticationType::USERNAME_PASSWORD:
if(!($this->Password instanceof UsernamePassword)) if(!($this->password instanceof UsernamePassword))
{
return false; return false;
}
$username = $input['username'] ?? null; $username = $input['username'] ?? null;
$password = $input['password'] ?? null; $password = $input['password'] ?? null;
if($username === null && $password === null) if($username === null && $password === null)
{
return false; return false;
}
if($username == null) if($username === null)
return $password == $this->Password->getPassword(); {
return $password === $this->password->getPassword();
}
if($password == null) if($password === null)
return $username == $this->Password->getUsername(); {
return $username === $this->password->getUsername();
}
return $username == $this->Password->getUsername() && $password == $this->Password->getPassword(); return $username === $this->password->getUsername() && $password === $this->password->getPassword();
case AuthenticationType::ACCESS_TOKEN: case AuthenticationType::ACCESS_TOKEN:
if(!($this->Password instanceof AccessToken)) if(!($this->password instanceof AccessToken))
{
return false; return false;
}
$token = $input['token'] ?? null; $token = $input['token'] ?? null;
if($token === null) if($token === null)
{
return false; return false;
}
return $token == $this->Password->AccessToken; return $token === $this->password->access_token;
default: default:
return false; return false;
@ -137,7 +154,7 @@
*/ */
public function setAuthentication(PasswordInterface $password): void public function setAuthentication(PasswordInterface $password): void
{ {
$this->Password = $password; $this->password = $password;
} }
/** /**
@ -146,7 +163,7 @@
*/ */
public function isCurrentlyDecrypted(): bool public function isCurrentlyDecrypted(): bool
{ {
return $this->IsCurrentlyDecrypted; return $this->currently_decrypted;
} }
/** /**
@ -156,19 +173,27 @@
*/ */
public function lock(): bool public function lock(): bool
{ {
if($this->Password == null) if($this->password === null)
{
return false; return false;
}
if($this->Encrypted) if($this->encrypted)
{
return false; return false;
}
if(!$this->IsCurrentlyDecrypted) if(!$this->currently_decrypted)
{
return false; return false;
}
if(!($this->Password instanceof PasswordInterface)) if(!($this->password instanceof PasswordInterface))
{
return false; return false;
}
$this->Password = $this->encrypt(); $this->password = $this->encrypt();
return true; return true;
} }
@ -177,30 +202,37 @@
* *
* @param string $password * @param string $password
* @return bool * @return bool
* @throws RuntimeException
* @noinspection PhpUnused * @noinspection PhpUnused
*/ */
public function unlock(string $password): bool public function unlock(string $password): bool
{ {
if($this->Password == null) if($this->password === null)
{
return false; return false;
}
if(!$this->Encrypted) if(!$this->encrypted)
{
return false; return false;
}
if($this->IsCurrentlyDecrypted) if($this->currently_decrypted)
{
return false; return false;
}
if(!is_string($this->Password)) if(!is_string($this->password))
{
return false; return false;
}
try try
{ {
$password = Crypto::decryptWithPassword($this->Password, $password, true); $password = Crypto::decryptWithPassword($this->password, $password, true);
} }
catch (EnvironmentIsBrokenException $e) catch (EnvironmentIsBrokenException $e)
{ {
throw new RuntimeException('Cannot decrypt password', $e); throw new RuntimeException(sprintf('Cannot decrypt password: %s', $e->getMessage()), $e->getCode(), $e);
} }
catch (WrongKeyOrModifiedCiphertextException $e) catch (WrongKeyOrModifiedCiphertextException $e)
{ {
@ -208,8 +240,8 @@
return false; return false;
} }
$this->Password = ZiProto::decode($password); $this->password = ZiProto::decode($password);
$this->IsCurrentlyDecrypted = true; $this->currently_decrypted = true;
return true; return true;
} }
@ -221,17 +253,85 @@
*/ */
private function encrypt(): ?string private function encrypt(): ?string
{ {
if(!$this->IsCurrentlyDecrypted) if(!$this->currently_decrypted)
{
return false; return false;
}
if($this->Password == null) if($this->password === null)
{
return false; return false;
}
if(!($this->Password instanceof PasswordInterface)) if(!($this->password instanceof PasswordInterface))
{
return null; return null;
}
$data = ZiProto::encode($this->Password->toArray(true)); $data = ZiProto::encode($this->password->toArray(true));
return Crypto::encryptWithPassword($data, (string)$this->Password, true);
try
{
return Crypto::encryptWithPassword($data, (string)$this->password, true);
}
catch(EnvironmentIsBrokenException $e)
{
throw new RuntimeException(sprintf('Cannot encrypt password: %s', $e->getMessage()), $e->getCode(), $e);
}
}
/**
* @return bool
*/
public function isEncrypted(): bool
{
return $this->encrypted;
}
/**
* Returns false if the entry needs to be decrypted first
*
* @param bool $encrypted
* @return bool
*/
public function setEncrypted(bool $encrypted): bool
{
if(!$this->currently_decrypted)
{
return false;
}
$this->encrypted = $encrypted;
return true;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name): void
{
$this->name = $name;
}
/**
* @return PasswordInterface|null
*/
public function getPassword(): ?PasswordInterface
{
if(!$this->currently_decrypted)
{
return null;
}
return $this->password;
} }
/** /**
@ -242,29 +342,29 @@
*/ */
public function toArray(bool $bytecode=false): array public function toArray(bool $bytecode=false): array
{ {
if($this->Password !== null) if($this->password !== null)
{ {
if($this->Encrypted && $this->IsCurrentlyDecrypted) if($this->encrypted && $this->currently_decrypted)
{ {
$password = $this->encrypt(); $password = $this->encrypt();
} }
elseif($this->Encrypted) elseif($this->encrypted)
{ {
$password = $this->Password; $password = $this->password;
} }
else else
{ {
$password = $this->Password->toArray(true); $password = $this->password->toArray(true);
} }
} }
else else
{ {
$password = $this->Password; $password = $this->password;
} }
return [ return [
($bytecode ? Functions::cbc('name') : 'name') => $this->Name, ($bytecode ? Functions::cbc('name') : 'name') => $this->name,
($bytecode ? Functions::cbc('encrypted') : 'encrypted') => $this->Encrypted, ($bytecode ? Functions::cbc('encrypted') : 'encrypted') => $this->encrypted,
($bytecode ? Functions::cbc('password') : 'password') => $password, ($bytecode ? Functions::cbc('password') : 'password') => $password,
]; ];
} }
@ -279,20 +379,20 @@
{ {
$self = new self(); $self = new self();
$self->Name = Functions::array_bc($data, 'name'); $self->name = Functions::array_bc($data, 'name');
$self->Encrypted = Functions::array_bc($data, 'encrypted'); $self->encrypted = Functions::array_bc($data, 'encrypted');
$password = Functions::array_bc($data, 'password'); $password = Functions::array_bc($data, 'password');
if($password !== null) if($password !== null)
{ {
if($self->Encrypted) if($self->encrypted)
{ {
$self->Password = $password; $self->password = $password;
$self->IsCurrentlyDecrypted = false; $self->currently_decrypted = false;
} }
elseif(gettype($password) == 'array') elseif(is_array($password))
{ {
$self->Password = match (Functions::array_bc($password, 'authentication_type')) $self->password = match (Functions::array_bc($password, 'authentication_type'))
{ {
AuthenticationType::USERNAME_PASSWORD => UsernamePassword::fromArray($password), AuthenticationType::USERNAME_PASSWORD => UsernamePassword::fromArray($password),
AuthenticationType::ACCESS_TOKEN => AccessToken::fromArray($password) AuthenticationType::ACCESS_TOKEN => AccessToken::fromArray($password)
@ -302,54 +402,4 @@
return $self; return $self;
} }
/**
* @return bool
*/
public function isEncrypted(): bool
{
return $this->Encrypted;
}
/**
* Returns false if the entry needs to be decrypted first
*
* @param bool $Encrypted
* @return bool
*/
public function setEncrypted(bool $Encrypted): bool
{
if(!$this->IsCurrentlyDecrypted)
return false;
$this->Encrypted = $Encrypted;
return true;
}
/**
* @return string
*/
public function getName(): string
{
return $this->Name;
}
/**
* @param string $Name
*/
public function setName(string $Name): void
{
$this->Name = $Name;
}
/**
* @return PasswordInterface|null
*/
public function getPassword(): ?PasswordInterface
{
if(!$this->IsCurrentlyDecrypted)
return null;
return $this->Password;
}
} }

View file

@ -1,24 +1,24 @@
<?php <?php
/* /*
* Copyright (c) Nosial 2022-2023, all rights reserved. * 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 * 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 * 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 * 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 * Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions: * conditions:
* *
* The above copyright notice and this permission notice shall be included in all copies or substantial portions * The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software. * of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * 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 * 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 * 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 * 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 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
* *
*/ */
/** @noinspection PhpMissingFieldTypeInspection */ /** @noinspection PhpMissingFieldTypeInspection */
@ -35,44 +35,7 @@
* *
* @var string * @var string
*/ */
public $AccessToken; public $access_token;
/**
* Returns an array representation of the object
*
* @param bool $bytecode
* @return array
*/
public function toArray(bool $bytecode=false): array
{
return [
($bytecode ? Functions::cbc('authentication_type') : 'authentication_type') => AuthenticationType::ACCESS_TOKEN,
($bytecode ? Functions::cbc('access_token') : 'access_token') => $this->AccessToken,
];
}
/**
* Constructs an object from an array representation
*
* @param array $data
* @return static
*/
public static function fromArray(array $data): self
{
$object = new self();
$object->AccessToken = Functions::array_bc($data, 'access_token');
return $object;
}
/**
* @return string
*/
public function getAccessToken(): string
{
return $this->AccessToken;
}
/** /**
* @inheritDoc * @inheritDoc
@ -89,7 +52,7 @@
*/ */
public function __toString(): string public function __toString(): string
{ {
return $this->AccessToken; return $this->access_token;
} }
/** /**
@ -97,6 +60,35 @@
*/ */
public function setAccessToken(string $AccessToken): void public function setAccessToken(string $AccessToken): void
{ {
$this->AccessToken = $AccessToken; $this->access_token = $AccessToken;
}
/**
* Returns an array representation of the object
*
* @param bool $bytecode
* @return array
*/
public function toArray(bool $bytecode=false): array
{
return [
($bytecode ? Functions::cbc('authentication_type') : 'authentication_type') => AuthenticationType::ACCESS_TOKEN,
($bytecode ? Functions::cbc('access_token') : 'access_token') => $this->access_token,
];
}
/**
* Constructs an object from an array representation
*
* @param array $data
* @return static
*/
public static function fromArray(array $data): AccessToken
{
$object = new self();
$object->access_token = Functions::array_bc($data, 'access_token');
return $object;
} }
} }

View file

@ -1,24 +1,24 @@
<?php <?php
/* /*
* Copyright (c) Nosial 2022-2023, all rights reserved. * 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 * 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 * 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 * 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 * Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions: * conditions:
* *
* The above copyright notice and this permission notice shall be included in all copies or substantial portions * The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software. * of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * 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 * 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 * 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 * 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 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
* *
*/ */
/** @noinspection PhpMissingFieldTypeInspection */ /** @noinspection PhpMissingFieldTypeInspection */
@ -35,45 +35,14 @@
* *
* @var string * @var string
*/ */
private $Username; private $username;
/** /**
* The entry's password * The entry's password
* *
* @var string * @var string
*/ */
private $Password; private $password;
/**
* Returns an array representation of the object
*
* @param bool $bytecode
* @return array
*/
public function toArray(bool $bytecode=false): array
{
return [
($bytecode ? Functions::cbc('authentication_type') : 'authentication_type') => AuthenticationType::USERNAME_PASSWORD,
($bytecode ? Functions::cbc('username') : 'username') => $this->Username,
($bytecode ? Functions::cbc('password') : 'password') => $this->Password,
];
}
/**
* Constructs an object from an array representation
*
* @param array $data
* @return static
*/
public static function fromArray(array $data): self
{
$instance = new self();
$instance->Username = Functions::array_bc($data, 'username');
$instance->Password = Functions::array_bc($data, 'password');
return $instance;
}
/** /**
* @return string * @return string
@ -81,7 +50,7 @@
*/ */
public function getUsername(): string public function getUsername(): string
{ {
return $this->Username; return $this->username;
} }
/** /**
@ -90,7 +59,7 @@
*/ */
public function getPassword(): string public function getPassword(): string
{ {
return $this->Password; return $this->password;
} }
/** /**
@ -108,22 +77,47 @@
*/ */
public function __toString(): string public function __toString(): string
{ {
return $this->Password; return $this->password;
} }
/** /**
* @param string $Username * @param string $username
*/ */
public function setUsername(string $Username): void public function setUsername(string $username): void
{ {
$this->Username = $Username; $this->username = $username;
} }
/** /**
* @param string $Password * @param string $password
*/ */
public function setPassword(string $Password): void public function setPassword(string $password): void
{ {
$this->Password = $Password; $this->password = $password;
}
/**
* @inheritDoc
*/
public function toArray(bool $bytecode=false): array
{
return [
($bytecode ? Functions::cbc('authentication_type') : 'authentication_type') => AuthenticationType::USERNAME_PASSWORD,
($bytecode ? Functions::cbc('username') : 'username') => $this->username,
($bytecode ? Functions::cbc('password') : 'password') => $this->password,
];
}
/**
* @inheritDoc
*/
public static function fromArray(array $data): self
{
$instance = new self();
$instance->username = Functions::array_bc($data, 'username');
$instance->password = Functions::array_bc($data, 'password');
return $instance;
} }
} }

View file

@ -802,7 +802,7 @@
{ {
$results = new RepositoryQueryResults(); $results = new RepositoryQueryResults();
switch($definedRemoteSource->Type) switch($definedRemoteSource->type)
{ {
case DefinedRemoteSourceType::GITHUB: case DefinedRemoteSourceType::GITHUB:
$source = GithubService::class; $source = GithubService::class;
@ -819,7 +819,7 @@
// Check if the specified version is a release // Check if the specified version is a release
try try
{ {
Console::outVerbose(sprintf('Attempting to fetch source code from %s', $definedRemoteSource->Host)); Console::outVerbose(sprintf('Attempting to fetch source code from %s', $definedRemoteSource->host));
$release_results = $source::getRelease($packageInput, $definedRemoteSource, $entry); $release_results = $source::getRelease($packageInput, $definedRemoteSource, $entry);
} }
catch(Exception $e) catch(Exception $e)