@@ -85,23 +85,13 @@ public function __construct(string $binary, array $allowedFormats)
8585 throw new WebauthnException ('Invalid attestation format provided (attStmt not available) ' );
8686 }
8787
88- if (! array_key_exists ('authData ' , $ enc ) || ! $ enc ['authData ' ] instanceof ByteBuffer) {
89- throw new WebauthnException ('Invalid attestation format provided (authData not available) ' );
90- }
91-
9288 $ this ->formatName = $ enc ['fmt ' ];
93- $ this ->authenticatorData = new AuthenticatorData ($ enc ['authData ' ]->getBinaryString ());
9489
95- if (! in_array ($ this ->formatName , $ allowedFormats )) {
96- throw new WebauthnException (sprintf (
97- 'Invalid attestation format [%s], allowed [%s] ' ,
98- $ this ->formatName ,
99- implode (', ' , $ allowedFormats )
100- ));
101- }
90+ // Set attestation data
91+ $ this ->setAuthenticatorData ($ enc );
10292
10393 // Create attestation format based on the provided format name
104- $ this ->createAttestationFormat ($ enc );
94+ $ this ->createAttestationFormat ($ enc, $ allowedFormats );
10595 }
10696
10797 /**
@@ -238,13 +228,36 @@ protected function getCertificateInfo(string $type): string
238228 return $ result ;
239229 }
240230
231+ /**
232+ * Set the authenticator data
233+ * @param array<string|int, mixed> $enc
234+ * @return void
235+ */
236+ protected function setAuthenticatorData (array $ enc ): void
237+ {
238+ if (! array_key_exists ('authData ' , $ enc ) || ! $ enc ['authData ' ] instanceof ByteBuffer) {
239+ throw new WebauthnException ('Invalid attestation format provided (authData not available) ' );
240+ }
241+
242+ $ this ->authenticatorData = new AuthenticatorData ($ enc ['authData ' ]->getBinaryString ());
243+ }
244+
241245 /**
242246 * Create the attestation format
243- * @param array<string, mixed> $enc the encoded data
247+ * @param array<string|int, mixed> $enc the encoded data
248+ * @param array<string> $allowedFormats the allowed format
244249 * @return void
245250 */
246- protected function createAttestationFormat (array $ enc ): void
251+ protected function createAttestationFormat (array $ enc, array $ allowedFormats ): void
247252 {
253+ if (! in_array ($ this ->formatName , $ allowedFormats )) {
254+ throw new WebauthnException (sprintf (
255+ 'Invalid attestation format [%s], allowed [%s] ' ,
256+ $ this ->formatName ,
257+ implode (', ' , $ allowedFormats )
258+ ));
259+ }
260+
248261 switch ($ this ->formatName ) {
249262 case KeyFormat::FIDO_U2FA :
250263 $ this ->format = new FidoU2F ($ enc , $ this ->authenticatorData );
0 commit comments