Skip to content

Commit eab183a

Browse files
committed
PHP 8.1 fixes
1 parent 8da1c56 commit eab183a

File tree

2 files changed

+37
-37
lines changed

2 files changed

+37
-37
lines changed

_test/server.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
// read get argument and post body
4242
$fn = filter_input(INPUT_GET, 'fn');
43-
$requireResidentKey = !!$_GET['requireResidentKey'];
43+
$requireResidentKey = !!filter_input(INPUT_GET, 'requireResidentKey');
4444
$userVerification = filter_input(INPUT_GET, 'userVerification', FILTER_SANITIZE_SPECIAL_CHARS);
4545

4646
$userId = filter_input(INPUT_GET, 'userId', FILTER_SANITIZE_SPECIAL_CHARS);
@@ -60,41 +60,41 @@
6060

6161
// Formats
6262
$formats = array();
63-
if ($_GET['fmt_android-key']) {
63+
if (filter_input(INPUT_GET, 'fmt_android-key')) {
6464
$formats[] = 'android-key';
6565
}
66-
if ($_GET['fmt_android-safetynet']) {
66+
if (filter_input(INPUT_GET, 'fmt_android-safetynet')) {
6767
$formats[] = 'android-safetynet';
6868
}
69-
if ($_GET['fmt_apple']) {
69+
if (filter_input(INPUT_GET, 'fmt_apple')) {
7070
$formats[] = 'apple';
7171
}
72-
if ($_GET['fmt_fido-u2f']) {
72+
if (filter_input(INPUT_GET, 'fmt_fido-u2f')) {
7373
$formats[] = 'fido-u2f';
7474
}
75-
if ($_GET['fmt_none']) {
75+
if (filter_input(INPUT_GET, 'fmt_none')) {
7676
$formats[] = 'none';
7777
}
78-
if ($_GET['fmt_packed']) {
78+
if (filter_input(INPUT_GET, 'fmt_packed')) {
7979
$formats[] = 'packed';
8080
}
81-
if ($_GET['fmt_tpm']) {
81+
if (filter_input(INPUT_GET, 'fmt_tpm')) {
8282
$formats[] = 'tpm';
8383
}
8484

8585
$rpId = 'localhost';
86-
if ($_GET['rpId']) {
86+
if (filter_input(INPUT_GET, 'rpId')) {
8787
$rpId = filter_input(INPUT_GET, 'rpId', FILTER_VALIDATE_DOMAIN);
8888
if ($rpId === false) {
8989
throw new Exception('invalid relying party ID');
9090
}
9191
}
9292

9393
// types selected on front end
94-
$typeUsb = !!$_GET['type_usb'];
95-
$typeNfc = !!$_GET['type_nfc'];
96-
$typeBle = !!$_GET['type_ble'];
97-
$typeInt = !!$_GET['type_int'];
94+
$typeUsb = !!filter_input(INPUT_GET, 'type_usb');
95+
$typeNfc = !!filter_input(INPUT_GET, 'type_nfc');
96+
$typeBle = !!filter_input(INPUT_GET, 'type_ble');
97+
$typeInt = !!filter_input(INPUT_GET, 'type_int');
9898

9999
// cross-platform: true, if type internal is not allowed
100100
// false, if only internal is allowed
@@ -113,26 +113,26 @@
113113
$WebAuthn = new lbuchs\WebAuthn\WebAuthn('WebAuthn Library', $rpId, $formats);
114114

115115
// add root certificates to validate new registrations
116-
if ($_GET['solo']) {
116+
if (filter_input(INPUT_GET, 'solo')) {
117117
$WebAuthn->addRootCertificates('rootCertificates/solo.pem');
118118
}
119-
if ($_GET['apple']) {
119+
if (filter_input(INPUT_GET, 'apple')) {
120120
$WebAuthn->addRootCertificates('rootCertificates/apple.pem');
121121
}
122-
if ($_GET['yubico']) {
122+
if (filter_input(INPUT_GET, 'yubico')) {
123123
$WebAuthn->addRootCertificates('rootCertificates/yubico.pem');
124124
}
125-
if ($_GET['hypersecu']) {
125+
if (filter_input(INPUT_GET, 'hypersecu')) {
126126
$WebAuthn->addRootCertificates('rootCertificates/hypersecu.pem');
127127
}
128-
if ($_GET['google']) {
128+
if (filter_input(INPUT_GET, 'google')) {
129129
$WebAuthn->addRootCertificates('rootCertificates/globalSign.pem');
130130
$WebAuthn->addRootCertificates('rootCertificates/googleHardware.pem');
131131
}
132-
if ($_GET['microsoft']) {
132+
if (filter_input(INPUT_GET, 'microsoft')) {
133133
$WebAuthn->addRootCertificates('rootCertificates/microsoftTpmCollection.pem');
134134
}
135-
if ($_GET['mds']) {
135+
if (filter_input(INPUT_GET, 'mds')) {
136136
$WebAuthn->addRootCertificates('rootCertificates/mds');
137137
}
138138

src/Binary/ByteBuffer.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ByteBuffer implements \JsonSerializable, \Serializable {
2727
private $_length;
2828

2929
public function __construct($binaryData) {
30-
$this->_data = $binaryData;
30+
$this->_data = (string)$binaryData;
3131
$this->_length = \strlen($binaryData);
3232
}
3333

@@ -41,7 +41,7 @@ public function __construct($binaryData) {
4141
* @param string $base64url
4242
* @return ByteBuffer
4343
*/
44-
public static function fromBase64Url($base64url) {
44+
public static function fromBase64Url($base64url): ByteBuffer {
4545
$bin = self::_base64url_decode($base64url);
4646
if ($bin === false) {
4747
throw new WebAuthnException('ByteBuffer: Invalid base64 url string', WebAuthnException::BYTEBUFFER);
@@ -54,7 +54,7 @@ public static function fromBase64Url($base64url) {
5454
* @param string $hex
5555
* @return ByteBuffer
5656
*/
57-
public static function fromHex($hex) {
57+
public static function fromHex($hex): ByteBuffer {
5858
$bin = \hex2bin($hex);
5959
if ($bin === false) {
6060
throw new WebAuthnException('ByteBuffer: Invalid hex string', WebAuthnException::BYTEBUFFER);
@@ -67,7 +67,7 @@ public static function fromHex($hex) {
6767
* @param string $length
6868
* @return ByteBuffer
6969
*/
70-
public static function randomBuffer($length) {
70+
public static function randomBuffer($length): ByteBuffer {
7171
if (\function_exists('random_bytes')) { // >PHP 7.0
7272
return new ByteBuffer(\random_bytes($length));
7373

@@ -83,14 +83,14 @@ public static function randomBuffer($length) {
8383
// PUBLIC
8484
// -----------------------
8585

86-
public function getBytes($offset, $length) {
86+
public function getBytes($offset, $length): string {
8787
if ($offset < 0 || $length < 0 || ($offset + $length > $this->_length)) {
8888
throw new WebAuthnException('ByteBuffer: Invalid offset or length', WebAuthnException::BYTEBUFFER);
8989
}
9090
return \substr($this->_data, $offset, $length);
9191
}
9292

93-
public function getByteVal($offset) {
93+
public function getByteVal($offset): int {
9494
if ($offset < 0 || $offset >= $this->_length) {
9595
throw new WebAuthnException('ByteBuffer: Invalid offset', WebAuthnException::BYTEBUFFER);
9696
}
@@ -105,7 +105,7 @@ public function getJson($jsonFlags=0) {
105105
return $data;
106106
}
107107

108-
public function getLength() {
108+
public function getLength(): int {
109109
return $this->_length;
110110
}
111111

@@ -181,29 +181,29 @@ public function getDoubleVal($offset) {
181181
/**
182182
* @return string
183183
*/
184-
public function getBinaryString() {
184+
public function getBinaryString(): string {
185185
return $this->_data;
186186
}
187187

188188
/**
189189
* @param string $buffer
190190
* @return bool
191191
*/
192-
public function equals($buffer) {
192+
public function equals($buffer): bool {
193193
return is_string($this->_data) && $this->_data === $buffer->data;
194194
}
195195

196196
/**
197197
* @return string
198198
*/
199-
public function getHex() {
199+
public function getHex(): string {
200200
return \bin2hex($this->_data);
201201
}
202202

203203
/**
204204
* @return bool
205205
*/
206-
public function isEmpty() {
206+
public function isEmpty(): bool {
207207
return $this->_length === 0;
208208
}
209209

@@ -213,7 +213,7 @@ public function isEmpty() {
213213
* return binary data in RFC 1342-Like serialized string
214214
* @return string
215215
*/
216-
public function jsonSerialize() {
216+
public function jsonSerialize(): string {
217217
if (ByteBuffer::$useBase64UrlEncoding) {
218218
return self::_base64url_encode($this->_data);
219219

@@ -226,7 +226,7 @@ public function jsonSerialize() {
226226
* Serializable-Interface
227227
* @return string
228228
*/
229-
public function serialize() {
229+
public function serialize(): string {
230230
return \serialize($this->_data);
231231
}
232232

@@ -243,7 +243,7 @@ public function unserialize($serialized) {
243243
* (PHP 8 deprecates Serializable-Interface)
244244
* @return array
245245
*/
246-
public function __serialize() {
246+
public function __serialize(): array {
247247
return [
248248
'data' => \serialize($this->_data)
249249
];
@@ -253,7 +253,7 @@ public function __serialize() {
253253
* object to string
254254
* @return string
255255
*/
256-
public function __toString() {
256+
public function __toString(): string {
257257
return $this->getHex();
258258
}
259259

@@ -278,7 +278,7 @@ public function __unserialize($data) {
278278
* @param string $data
279279
* @return string
280280
*/
281-
protected static function _base64url_decode($data) {
281+
protected static function _base64url_decode($data): string {
282282
return \base64_decode(\strtr($data, '-_', '+/') . \str_repeat('=', 3 - (3 + \strlen($data)) % 4));
283283
}
284284

@@ -287,7 +287,7 @@ protected static function _base64url_decode($data) {
287287
* @param string $data
288288
* @return string
289289
*/
290-
protected static function _base64url_encode($data) {
290+
protected static function _base64url_encode($data): string {
291291
return \rtrim(\strtr(\base64_encode($data), '+/', '-_'), '=');
292292
}
293293
}

0 commit comments

Comments
 (0)