示例#1
0
def show_simple_packet(p):
    p_string = ['%s:' % TXT.pkt_msg(p.tag.type)]

    if p.tag.type in [
            PKT_PUBLICKEY, PKT_PRIVATEKEY, PKT_PUBLICSUBKEY, PKT_PRIVATESUBKEY
    ]:
        p_string.append(p.body.id)
        p_string.append(TXT.alg_pubkey_msg(p.body.alg))

    elif PKT_USERID == p.tag.type:
        p_string.append(p.body.value)

    elif PKT_SIGNATURE == p.tag.type:
        p_string.append(TXT.sig_msg(p.body.type))
        p_string.append("from %s" % p.body.keyid)

    elif PKT_PUBKEYSESKEY == p.tag.type:
        p_string.append(TXT.alg_pubkey_msg(p.body.alg_pubkey))
        p_string.append(p.body.keyid)

    elif PKT_LITERAL == p.tag.type:
        p_string.append(' '.join(
            [p.body.filename, p.body.format,
             "%s bytes" % len(p.body.data)]))

    return ' '.join(p_string)
示例#2
0
def show_pkts(d):
    """Show OpenPGP packet information.

    :Parameters:
        - `d`: variable OpenPGP data - may be a string containing
          OpenPGP packets (native or armored), a list of OpenPGP packets, or a
          single OpenPGP packet instance

    :Returns: string of packet information found in `d`

    :note: Data `d` can either be an unbroken string of native OpenPGP data
        or normal text with one or more ASCII-armored blocks (but not both).
    """
    if isinstance(d, str):
        if looks_armored(d):
            armored = list_armored(d)
            d = ''.join([a.data for a in armored
                         ])  # we may have many armored instances
        pkts = list_pkts(d)

    elif isinstance(d, list):
        pkts = d

    elif isinstance(d, PKT.Packet):
        pkts = [d]

    r = []
    for p in pkts:
        r.append(TXT.pkt_msg(p.tag.type))
        l = p.length.size
        if l == 'UNDEFINED':
            l = "Undefined (found %s octets)" % len(p.body.rawstr())
        r.append(" version: %s type: %s bodylength: %s" %
                 (p.tag.version, p.tag.type, l))
        r.append(report_body(p))
        ### packet byte string
        #import OpenPGP.util.strnum as STN
        #r.append("Packet body byte string:")
        #r.append(STN.str2pyhex(p.rawstr()))
        ###
        ### packet body byte string
        #r.append("Packet body byte string:")
        #r.append(STN.str2pyhex(p.body._d))
        ###
    r.append("Pau.")
    return linesep.join(r)
示例#3
0
文件: tool.py 项目: Ando02/wubiuefi
def show_pkts(d):
    """Show OpenPGP packet information.

    :Parameters:
        - `d`: variable OpenPGP data - may be a string containing
          OpenPGP packets (native or armored), a list of OpenPGP packets, or a
          single OpenPGP packet instance

    :Returns: string of packet information found in `d`

    :note: Data `d` can either be an unbroken string of native OpenPGP data
        or normal text with one or more ASCII-armored blocks (but not both).
    """
    if isinstance(d, str):
        if looks_armored(d):
            armored = list_armored(d)
            d = ''.join([a.data for a in armored]) # we may have many armored instances
        pkts = list_pkts(d)

    elif isinstance(d, list):
        pkts = d

    elif isinstance(d, PKT.Packet):
        pkts = [d]

    r = []
    for p in pkts:
        r.append(TXT.pkt_msg(p.tag.type))
        l = p.length.size
        if l == 'UNDEFINED':
            l = "Undefined (found %s octets)" % len(p.body.rawstr())
        r.append(" version: %s type: %s bodylength: %s" % (p.tag.version, p.tag.type, l))
        r.append(report_body(p))
        ### packet byte string
        #import OpenPGP.util.strnum as STN
        #r.append("Packet body byte string:")
        #r.append(STN.str2pyhex(p.rawstr()))
        ###
        ### packet body byte string
        #r.append("Packet body byte string:")
        #r.append(STN.str2pyhex(p.body._d))
        ###
    r.append("Pau.")
    return linesep.join(r)
示例#4
0
文件: tool.py 项目: Ando02/wubiuefi
def show_simple_packet(p):
    p_string = ['%s:' % TXT.pkt_msg(p.tag.type)]

    if p.tag.type in [PKT_PUBLICKEY, PKT_PRIVATEKEY, PKT_PUBLICSUBKEY,
                      PKT_PRIVATESUBKEY]:
        p_string.append(p.body.id)
        p_string.append(TXT.alg_pubkey_msg(p.body.alg))

    elif PKT_USERID == p.tag.type:
        p_string.append(p.body.value)

    elif PKT_SIGNATURE == p.tag.type:
        p_string.append(TXT.sig_msg(p.body.type))
        p_string.append("from %s" % p.body.keyid)

    elif PKT_PUBKEYSESKEY == p.tag.type:
        p_string.append(TXT.alg_pubkey_msg(p.body.alg_pubkey))
        p_string.append(p.body.keyid)

    elif PKT_LITERAL == p.tag.type:
        p_string.append(' '.join([p.body.filename, p.body.format, "%s bytes" % len(p.body.data)]))

    return ' '.join(p_string)