static function get_subpacket(&$input)
{
$len = ord($input[0]);
$length_of_length = 1;
// if($len < 192) One octet length, no furthur processing
if ($len > 190 && $len < 255) {
// Two octet length
$length_of_length = 2;
$len = ($len - 192 << 8) + ord($input[1]) + 192;
}
if ($len == 255) {
// Five octet length
$length_of_length = 5;
$unpacked = unpack('N', substr($input, 1, 4));
$len = reset($unpacked);
}
$input = substr($input, $length_of_length);
// Chop off length header
$tag = ord($input[0]);
$class = self::class_for($tag);
if ($class) {
$packet = new $class();
$packet->tag = $tag;
$packet->input = substr($input, 1, $len - 1);
$packet->length = $len - 1;
$packet->read();
unset($packet->input);
unset($packet->length);
}
$input = substr($input, $len);
// Chop off the data from this packet
return $packet;
}