minCount( 1, 'pubKeyCredParams should have at least %d elements, but has %d elements.' ); Assert::thatAll( $pubKeyCredParams )->isInstanceOf( PublicKeyCredentialParameters::class ); Assert::thatAll( $excludeCredentials )->isInstanceOf( PublicKeyCredentialDescriptor::class ); Assert::that( $attestation )->choice( AttestationConveyancePreference::ALL, 'attestation "%s" is not an element of the valid values: %s' ); $this->rp = $rp; $this->user = $user; $this->challenge = $challenge; $this->pubKeyCredParams = $pubKeyCredParams; $this->excludeCredentials = $excludeCredentials; $this->authenticatorSelection = $authenticatorSelection; $this->attestation = $attestation; } public static function hydrate( array $data ): self { Assert::that( $data, 'PublicKeyCredentialCreationOptions hydration does not contain "%s".' ) ->keyExists( 'rp' ) ->keyExists( 'user' ) ->keyExists( 'challenge' ) ->keyExists( 'pubKeyCredParams' ) ->keyExists( 'excludeCredentials' ); Assert::that( $data['pubKeyCredParams'] ) ->isArray( 'pubKeyCredParams "%s" is not an array.' ); Assert::thatAll( $data['pubKeyCredParams'] ) ->isArray( 'pubKeyCredParams item "%s" is not an array.' ); Assert::that( $data['excludeCredentials'] ) ->isArray( 'excludeCredentials "%s" is not an array.' ); Assert::thatAll( $data['excludeCredentials'] ) ->isArray( 'excludeCredentials item "%s" is not an array.' ); Assert::thatNullOr( $data['authenticatorSelection'] ?? null ) ->isArray( 'authenticatorSelection "%s" is not an array.' ); return new self( PublicKeyCredentialRpEntity::hydrate( $data['rp'] ), PublicKeyCredentialUserEntity::hydrate( $data['user'] ), BinaryString::from_ascii( $data['challenge'] ), array_map( [ PublicKeyCredentialParameters::class, 'hydrate' ], $data['pubKeyCredParams'] ), array_map( [ PublicKeyCredentialDescriptor::class, 'hydrate' ], $data['excludeCredentials'] ), isset( $data['authenticatorSelection'] ) ? AuthenticatorSelectionCriteria::hydrate( $data['authenticatorSelection'] ) : null, $data['attestation'] ); } public function get_rp(): PublicKeyCredentialRpEntity { return $this->rp; } public function get_user(): PublicKeyCredentialUserEntity { return $this->user; } public function get_challenge(): BinaryString { return $this->challenge; } /** @return PublicKeyCredentialParameters[] */ public function get_pub_key_cred_params(): array { return $this->pubKeyCredParams; } public function get_excluded_credentials(): array { return $this->excludeCredentials; } public function get_authenticator_selection(): ?AuthenticatorSelectionCriteria { return $this->authenticatorSelection; } public function get_attestation(): string { return $this->attestation; } public function jsonSerialize(): array { return array_filter( \ITSEC_Lib::recursively_json_serialize( get_object_vars( $this ) ), function ( $value ) { return ! is_null( $value ); } ); } }