'Sign some data with this key.
SECSH-TRANS RFC 4253 Section 6.6.
@type data: L{bytes}
@param data: The data to sign.
@rtype: L{bytes}
@return: A signature for the given data.'

def sign(self, data):

    keyType = self.type()
    if (keyType == 'RSA'):
        sig = self._keyObject.sign(data, padding.PKCS1v15(), hashes.SHA1())
        ret = common.NS(sig)
    elif (keyType == 'DSA'):
        sig = self._keyObject.sign(data, hashes.SHA1())
        (r, s) = decode_dss_signature(sig)
        ret = common.NS((int_to_bytes(r, 20) + int_to_bytes(s, 20)))
    elif (keyType == 'EC'):
        keySize = self.size()
        if (keySize <= 256):
            hashSize = hashes.SHA256()
        elif (keySize <= 384):
            hashSize = hashes.SHA384()
        else:
            hashSize = hashes.SHA512()
        signature = self._keyObject.sign(data, ec.ECDSA(hashSize))
        (r, s) = decode_dss_signature(signature)
        rb = int_to_bytes(r)
        sb = int_to_bytes(s)
        if (type(rb[0]) is str):
            rcomp = ord(rb[0])
        else:
            rcomp = rb[0]
        if (rcomp & 128):
            rb = ('\x00' + rb)
        if (type(sb[0]) is str):
            scomp = ord(sb[0])
        else:
            scomp = sb[0]
        if (scomp & 128):
            sb = ('\x00' + sb)
        ret = common.NS((common.NS(rb) + common.NS(sb)))
    return (common.NS(self.sshType()) + ret)
