Serial number of certificate as integer

def serial(self):
        """ Serial number of certificate as integer """
        asnint = libcrypto.X509_get_serialNumber(self.cert)
        bio = Membio()
        libcrypto.i2a_ASN1_INTEGER(bio.bio, asnint)
        return int(str(bio), 16)