<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def from_pubkey_line(cls, line):
 """Generate Key instance from a a string. Raise ValueError if string is malformed"""

        options, key_without_options = cls._extract_options(line)
        if key_without_options == '':
            raise ValueError("Empty key")
        # the key (with options stripped out) should consist of the fields
        # "type", "data", and optionally "comment", separated by a space.
        # The comment field may contain additional spaces
        fields = key_without_options.strip().split(None, 2)  # maxsplit=2
        if len(fields) == 3:
            type_str, data64, comment = fields
        elif len(fields) == 2:
            type_str, data64 = fields
            comment = None
        else:  # len(fields) <= 1
            raise ValueError("Key has insufficient number of fields")

        try:
            data = b64decode(data64)
        except (binascii.Error, TypeError):
            raise ValueError("Key contains invalid data")

        key_type = next(iter_prefixed(data))

        if key_type == b'ssh-rsa':
            key_class = RSAKey
        elif key_type == b'ssh-dss':
            key_class = DSAKey
        elif key_type.startswith(b'ecdsa-'):
            key_class = ECDSAKey
        else:
            raise ValueError('Unknown key type {}'.format(key_type))

        return key_class(b64decode(data64), comment, options=options)