1<?php
2
3/**
4 * ReadBytes trait
5 *
6 * PHP version 5
7 *
8 * @category  System
9 * @package   SSH
10 * @author    Jim Wigginton <terrafrost@php.net>
11 * @copyright 2015 Jim Wigginton
12 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
13 * @link      http://phpseclib.sourceforge.net
14 */
15
16namespace phpseclib3\System\SSH\Common\Traits;
17
18/**
19 * ReadBytes trait
20 *
21 * @package SSH
22 * @author  Jim Wigginton <terrafrost@php.net>
23 * @access  public
24 */
25trait ReadBytes
26{
27    /**
28     * Read data
29     *
30     * @param int $length
31     * @throws \RuntimeException on connection errors
32     * @access public
33     */
34    public function readBytes($length)
35    {
36        $temp = fread($this->fsock, $length);
37        if (strlen($temp) != $length) {
38            throw new \RuntimeException("Expected $length bytes; got " . strlen($temp));
39        }
40        return $temp;
41    }
42}
43