'Return a public or private LSH key.  See _fromString_PUBLIC_LSH and
_fromString_PRIVATE_LSH for the key formats.
@rtype: L{bytes}'

def _toString_LSH(self):

    data = self.data()
    type = self.type()
    if self.isPublic():
        if (type == 'RSA'):
            keyData = sexpy.pack([['public-key', ['rsa-pkcs1-sha1', ['n', common.MP(data['n'])[4:]], ['e', common.MP(data['e'])[4:]]]]])
        elif (type == 'DSA'):
            keyData = sexpy.pack([['public-key', ['dsa', ['p', common.MP(data['p'])[4:]], ['q', common.MP(data['q'])[4:]], ['g', common.MP(data['g'])[4:]], ['y', common.MP(data['y'])[4:]]]]])
        else:
            raise BadKeyError(('unknown    key    type    %s' % (type,)))
        return (('{' + encodebytes(keyData).replace('\n', '')) + '}')
    elif (type == 'RSA'):
        (p, q) = (data['p'], data['q'])
        return sexpy.pack([['private-key', ['rsa-pkcs1', ['n', common.MP(data['n'])[4:]], ['e', common.MP(data['e'])[4:]], ['d', common.MP(data['d'])[4:]], ['p', common.MP(q)[4:]], ['q', common.MP(p)[4:]], ['a', common.MP((data['d'] % (q - 1)))[4:]], ['b', common.MP((data['d'] % (p - 1)))[4:]], ['c', common.MP(data['u'])[4:]]]]])
    elif (type == 'DSA'):
        return sexpy.pack([['private-key', ['dsa', ['p', common.MP(data['p'])[4:]], ['q', common.MP(data['q'])[4:]], ['g', common.MP(data['g'])[4:]], ['y', common.MP(data['y'])[4:]], ['x', common.MP(data['x'])[4:]]]]])
    else:
        raise BadKeyError(("unknown    key    type    %s'" % (type,)))
