trait OptFieldCrypt

Trait for storage classes that store a optionally-encrypted credential fields

The encryption uses the owner account's secret-key crypto (only accessible by them)

Traits

Trait allowing objects to store fields encrypted with an account's crypto

Properties

private $crypto_cache

Stores fields decrypted in memory

from  FieldCrypt

Methods

static array
getEncryptedFields()

Returns the list of fields encrypted in this object

Account|null
GetAccount()

Returns the account that owns this object

static array
LoadByAccount(ObjectDatabase $database, Account $account)

Returns all objects owned by the given account

static array
GetFieldCryptFieldTemplate()

Gets the extra DB fields required for this trait

bool
isFieldEncrypted($field)

Returns true if the given DB field is encrypted

bool
isCryptoAvailable()

Returns true if field crypto is unlockable

string
GetEncryptedScalar(string $field)

Decrypts and returns the value of the given field

RequireCrypto()

Unlocks account crypto for usage and returns it

string|null
TryGetEncryptedScalar(string $field)

Decrypts and returns the value of the given field

SetEncryptedScalar(string $field, string|null $value, bool|null $fieldcrypt = null)

Sets the value of the given field

SetEncrypted(bool $crypt)

Sets the crypto state of all stored fields

static void
DecryptAccount(ObjectDatabase $database, Account $account)

Loads any objects for the given account and decrypts their fields

static string
GetFieldCryptCreateUsage()

Returns the command usage for Create()

FieldCryptCreate(Input $input)

Performs cred-crypt level initialization on a new storage

static string
GetFieldCryptEditUsage()

Returns the command usage for Edit()

FieldCryptEdit(Input $input)

Performs cred-crypt level edit on an existing storage

array
GetFieldCryptClientObject()

Returns the printable client object of this trait

Details

in FieldCrypt at line 19
abstract static protected array getEncryptedFields()

Returns the list of fields encrypted in this object

Return Value

array

in FieldCrypt at line 22
abstract protected Account|null GetAccount()

Returns the account that owns this object

Return Value

Account|null

in FieldCrypt at line 25
abstract static array LoadByAccount(ObjectDatabase $database, Account $account)

Returns all objects owned by the given account

Parameters

ObjectDatabase $database
Account $account

Return Value

array

in FieldCrypt at line 28
static array GetFieldCryptFieldTemplate()

Gets the extra DB fields required for this trait

Return Value

array

in FieldCrypt at line 35
protected bool isFieldEncrypted($field)

Returns true if the given DB field is encrypted

Parameters

$field

Return Value

bool

in FieldCrypt at line 39
protected bool isCryptoAvailable()

Returns true if field crypto is unlockable

Return Value

bool

in FieldCrypt at line 55
protected string GetEncryptedScalar(string $field)

Decrypts and returns the value of the given field

Parameters

string $field

field name

Return Value

string

decrypted value

Exceptions

KeyNotFoundException

if the value is null

See also

FieldCrypt::TryGetEncryptedScalar

in FieldCrypt at line 63
protected Account RequireCrypto()

Unlocks account crypto for usage and returns it

Return Value

Account

in FieldCrypt at line 78
protected string|null TryGetEncryptedScalar(string $field)

Decrypts and returns the value of the given field

Parameters

string $field

field name

Return Value

string|null

decrypted value

in FieldCrypt at line 103
protected FieldCrypt SetEncryptedScalar(string $field, string|null $value, bool|null $fieldcrypt = null)

Sets the value of the given field

Parameters

string $field

field to set

string|null $value

value to set

bool|null $fieldcrypt

if true, encrypt - default current state

Return Value

FieldCrypt

in FieldCrypt at line 129
protected FieldCrypt SetEncrypted(bool $crypt)

Sets the crypto state of all stored fields

Parameters

bool $crypt

true to encrypted, false if not

Return Value

FieldCrypt

in FieldCrypt at line 145
static void DecryptAccount(ObjectDatabase $database, Account $account)

Loads any objects for the given account and decrypts their fields

Parameters

ObjectDatabase $database

database reference

Account $account

account to load by

Return Value

void

at line 161
static string GetFieldCryptCreateUsage()

Returns the command usage for Create()

Return Value

string

at line 164
OptFieldCrypt FieldCryptCreate(Input $input)

Performs cred-crypt level initialization on a new storage

Parameters

Input $input

Return Value

OptFieldCrypt

at line 172
static string GetFieldCryptEditUsage()

Returns the command usage for Edit()

Return Value

string

at line 175
OptFieldCrypt FieldCryptEdit(Input $input)

Performs cred-crypt level edit on an existing storage

Parameters

Input $input

Return Value

OptFieldCrypt

at line 185
array GetFieldCryptClientObject()

Returns the printable client object of this trait

Return Value

array

fields mapped to {field_iscrypt:bool}