Exemple #1
0
    def __format__(self, formatstr):
        """Advanced formatting for messages."""
        hexify = False
        verbose = False
        digest = False
        if "h" in formatstr:
            hexify = True
        if "v" in formatstr:
            verbose = True
        if "m" in formatstr:
            digest = True

        if self.certChain is None:
            cert_list = None
        else:
            if isinstance(self.certChain, X509CertChain):
                cert_list = [cert.bytes for cert in self.certChain.x509List]
            else:
                cert_list = self.certChain

            if digest:
                cert_list = "[" + ", ".join(b2a_hex(secureHash(cert, "sha256")) for cert in cert_list) + "]"
            else:
                cert_list = [repr(cert) for cert in cert_list]

        return "Certificate({0})".format(cert_list)
Exemple #2
0
def printExporter(connection, expLabel, expLength):
    if expLabel is None:
        return
    expLabel = bytearray(expLabel, "utf-8")
    exp = connection.keyingMaterialExporter(expLabel, expLength)
    exp = b2a_hex(exp).upper()
    print("  Exporter label: {0}".format(expLabel))
    print("  Exporter length: {0}".format(expLength))
    print("  Keying material: {0}".format(exp))
Exemple #3
0
    def __format__(self, formatstr):
        """Advanced formatting for messages."""
        hexify = False
        verbose = ""
        if "h" in formatstr:
            hexify = True
        if "v" in formatstr:
            verbose = "ContentType."

        if hexify:
            data = b2a_hex(self.data)
        else:
            data = repr(self.data)

        return "Message(contentType={0}{1}, data={2})".format(verbose, ContentType.toStr(self.contentType), data)
Exemple #4
0
    def __format__(self, formatstr):
        """Formattable representation of extension."""
        if self.client_shares is None:
            return "KeyShareExtension(None)"

        verbose = ""
        hexlify = False
        if 'v' in formatstr:
            verbose = "GroupName."
        if 'h' in formatstr:
            hexlify = True

        shares = []
        for group_id, share in self.client_shares:
            if hexlify:
                share = b2a_hex(share)
            else:
                share = repr(share)
            shares += ["({0}{1}, {2})".format(verbose,
                                              GroupName.toStr(group_id),
                                              share)]
        return "KeyShareExtension([" + ",".join(shares) + "])"
Exemple #5
0
def format_bytearray(byte_array, formatstr):
    """Format method for bytearrays."""
    if "x" in formatstr:
        return b2a_hex(byte_array)
    else:
        return repr(byte_array)