OpenPGP_Packet::parse_old_format PHP Method

parse_old_format() static public method

Parses an old-format (PGP 2.6.x) OpenPGP packet.
See also: http://tools.ietf.org/html/rfc4880#section-4.2.1
static public parse_old_format ( $input )
    static function parse_old_format($input)
    {
        $len = ($tag = ord($input[0])) & 3;
        $tag = $tag >> 2 & 15;
        switch ($len) {
            case 0:
                // The packet has a one-octet length. The header is 2 octets long.
                $head_length = 2;
                $data_length = ord($input[1]);
                break;
            case 1:
                // The packet has a two-octet length. The header is 3 octets long.
                $head_length = 3;
                $data_length = unpack('n', substr($input, 1, 2));
                $data_length = $data_length[1];
                break;
            case 2:
                // The packet has a four-octet length. The header is 5 octets long.
                $head_length = 5;
                $data_length = unpack('N', substr($input, 1, 4));
                $data_length = $data_length[1];
                break;
            case 3:
                // The packet is of indeterminate length. The header is 1 octet long.
                $head_length = 1;
                $data_length = strlen($input) - $head_length;
                break;
        }
        return array($tag, $head_length, $data_length, false);
    }