\Drupal\strata\Crypto StaticKeyProvider

Holds a key in memory.

Used by the test lanes and by a CLI run that is handed a key directly. A site uses the key module instead, so that the key is not in configuration a database dump would carry.

Summary

Methods
Properties
Constants
__construct
generate
fromStored
fromHex
key
hasKey
fingerprint
No public properties found
No public constants found
No protected methods found
No protected properties found
No protected constants found
No private methods found
key
FINGERPRINT_CONTEXT
FINGERPRINT_LENGTH

Constant

FINGERPRINT_CONTEXT

FINGERPRINT_CONTEXT = 'strata-key-fingerprint-v1'

Personalisation for the fingerprint, so it can never collide with another use of the key.

FINGERPRINT_LENGTH

FINGERPRINT_LENGTH = 16

Hex characters a fingerprint carries.

Properties

$key

$key : string

Type

string

Methods

__construct()

__construct(string  $key) : mixed

Constructs a provider around raw key bytes.

Parameters

string $key

Exactly KeyProviderInterface::KEY_BYTES bytes.

Throws

\InvalidArgumentException

When the key is the wrong length. Refused rather than stretched or truncated, because either would give a false impression of the strength in use.

Returns

mixed —

generate()

generate() : self

Builds a provider around a fresh random key.

Returns

self —

A provider holding a newly generated key.

fromStored()

fromStored(string  $value) : self

Builds a provider from whatever a key entity holds.

A stored key is raw bytes or the hex of them, and which one it is has to be decided by looking at it. This is the one place that decides, because the same ternary was written out in Engine::keyProviderFor(), in strata_key_value_requirement() and on the storage form, and three copies of an acceptance rule are how the form comes to accept a key the engine refuses.

Parameters

string $value

The stored value.

Throws

\InvalidArgumentException

When the value is neither the right number of raw bytes nor the hex of them.

Returns

self —

A provider holding the key.

fromHex()

fromHex(string  $hex) : self

Builds a provider from a hex-encoded key.

Parameters

string $hex

Exactly 64 hex characters.

Throws

\InvalidArgumentException

When the string is not valid hex of the right length.

Returns

self —

A provider holding the decoded key.

key()

key() : string

The key material.

Returns

string —

Exactly KeyProviderInterface::KEY_BYTES bytes.

hasKey()

hasKey() : bool

Whether a usable key is configured right now.

Returns

bool —

TRUE when KeyProviderInterface::key() would succeed.

fingerprint()

fingerprint() : string

A stable, non-secret identifier for the key currently in use.

Returns

string —

A short hex fingerprint.