@@ -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