Minor bug fixes when parsing Vault

https://git.n64.cc/nosial/ncc/-/issues/27
This commit is contained in:
Netkas 2022-12-07 18:08:15 -05:00
parent f1e7aeccfa
commit 5a83a7f6fe
3 changed files with 7 additions and 8 deletions

View file

@ -96,8 +96,7 @@
}
$VaultArray = ZiProto::decode(IO::fread($this->CredentialsPath));
$VaultObject = new Vault();
$VaultObject->fromArray($VaultArray);
$VaultObject = Vault::fromArray($VaultArray);
if($VaultObject->Version !== Versions::CredentialsStoreVersion)
throw new RuntimeException('Credentials store version mismatch');

View file

@ -5,6 +5,7 @@
namespace ncc\Objects;
use ncc\Abstracts\AuthenticationType;
use ncc\Abstracts\Versions;
use ncc\Exceptions\RuntimeException;
use ncc\Interfaces\PasswordInterface;
use ncc\Objects\Vault\Entry;
@ -31,6 +32,7 @@
*/
public function __construct()
{
$this->Version = Versions::CredentialsStoreVersion;
$this->Entries = [];
}
@ -180,12 +182,10 @@
$vault = new Vault();
$vault->Version = Functions::array_bc($array, 'version');
$entries = Functions::array_bc($array, 'entries');
$vault->Entries = [];
foreach($entries as $entry)
{
$entry = Entry::fromArray($entry);
$vault->Entries[] = $entry;
}
$vault->Entries[] = Entry::fromArray($entry);
return $vault;
}

View file

@ -261,8 +261,8 @@
$self->Name = Functions::array_bc($data, 'name');
$self->Encrypted = Functions::array_bc($data, 'encrypted');
$password = Functions::array_bc($data, 'password');
if($password !== null)
{
if($self->Encrypted)
@ -272,7 +272,7 @@
}
elseif(gettype($password) == 'array')
{
$self->Password = match (Functions::array_bc($data, 'authentication_type'))
$self->Password = match (Functions::array_bc($password, 'authentication_type'))
{
AuthenticationType::UsernamePassword => UsernamePassword::fromArray($password),
AuthenticationType::AccessToken => AccessToken::fromArray($password)