'Create a string representation of this key.  If the key is a private
key and you want the representation of its public key, use
C{key.public().toString()}.  type maps to a _toString_* method.
@param type: The type of string to emit.  Currently supported values
are C{\'OPENSSH\'}, C{\'LSH\'}, and C{\'AGENTV3\'}.
@type type: L{str}
@param extra: Any extra data supported by the selected format which
is not part of the key itself.  For public OpenSSH keys, this is
a comment.  For private OpenSSH keys, this is a passphrase to
encrypt with.
@type extra: L{bytes} or L{unicode} or L{None}
@rtype: L{bytes}'

def toString(self, type, extra=None):

    if isinstance(extra, unicode):
        extra = extra.encode('utf-8')
    method = getattr(self, ('_toString_%s' % (type.upper(),)), None)
    if (method is None):
        raise BadKeyError(('unknown    key    type:    %s' % (type,)))
    if (method.__code__.co_argcount == 2):
        return method(extra)
    else:
        return method()
