Exemplo n.º 1
0
def parse_notation(data, hashed, encode_non_readable=b64encode):
    flags = utils.long_to_int(data, 0)

    notation_name_length = utils.short_to_int(data, 4)
    notation_value_length = utils.short_to_int(data, 6)
    name_end = 8 + notation_name_length
    value_end = name_end + notation_value_length

    notation_name = data[8:name_end].decode('utf8', 'replace')
    notation_name, notation_namespace = \
        (notation_name.split('@', 1) + [None])[:2]
    notation_value = data[name_end:value_end]

    if flags & 0xffffff:
        # None of these flags are defined. They MUST be zero.
        return None

    human_readable = (flags >> 24) & 0xff == 0x80
    if human_readable:
        # human readable
        notation_value = notation_value.decode('utf8', 'replace')
    else:
        notation_value = encode_non_readable(notation_value)

    return {
        u'name': notation_name,
        u'namespace': notation_namespace,
        u'human_readable': human_readable,
        u'value': notation_value,
        u'hashed': hashed,
    }
Exemplo n.º 2
0
    def from_subpacket_content(cls, type_, critical, sub_data):
        assert len(sub_data) >= 8
        offset = 0
        flags = sub_data[:4]
        offset += 4
        assert not any(flags[1:])
        assert not flags[0] & 0x7f
        human_readable = 0x80
        name_length = utils.short_to_int(sub_data, offset)
        offset += 2
        value_length = utils.short_to_int(sub_data, offset)
        offset += 2
        raw_name = sub_data[offset:offset + name_length]
        offset += name_length
        value = sub_data[offset:offset + value_length]
        offset += value_length
        assert offset == len(sub_data)

        name_and_namespace = raw_name.decode('utf8', 'replace')
        name, namespace = (name_and_namespace.split('@', 1) + [None])[:2]

        if human_readable:
            value = value.decode('utf8', 'replace')

        return cls(critical, name, namespace, human_readable, value)
Exemplo n.º 3
0
def parse_notation(data, hashed, encode_non_readable=b64encode):
    flags = utils.long_to_int(data, 0)

    notation_name_length = utils.short_to_int(data, 4)
    notation_value_length = utils.short_to_int(data, 6)
    name_end = 8 + notation_name_length
    value_end = name_end + notation_value_length

    notation_name = data[8:name_end].decode('utf8', 'replace')
    notation_name, notation_namespace = \
        (notation_name.split('@', 1) + [None])[:2]
    notation_value = data[name_end:value_end]

    if flags & 0xffffff:
        # None of these flags are defined. They MUST be zero.
        return None

    human_readable = (flags >> 24) & 0xff == 0x80
    if human_readable:
        # human readable
        notation_value = notation_value.decode('utf8', 'replace')
    else:
        notation_value = encode_non_readable(notation_value)

    return {
            u'name': notation_name,
            u'namespace': notation_namespace,
            u'human_readable': human_readable,
            u'value': notation_value,
            u'hashed': hashed,
        }
Exemplo n.º 4
0
    def from_subpacket_content(cls, type_, critical, sub_data):
        assert len(sub_data) >= 8
        offset = 0
        flags = sub_data[:4]
        offset += 4
        assert not any(flags[1:])
        assert not flags[0] & 0x7F
        human_readable = 0x80
        name_length = utils.short_to_int(sub_data, offset)
        offset += 2
        value_length = utils.short_to_int(sub_data, offset)
        offset += 2
        raw_name = sub_data[offset : offset + name_length]
        offset += name_length
        value = sub_data[offset : offset + value_length]
        offset += value_length
        assert offset == len(sub_data)

        name_and_namespace = raw_name.decode("utf8", "replace")
        name, namespace = (name_and_namespace.split("@", 1) + [None])[:2]

        if human_readable:
            value = value.decode("utf8", "replace")

        return cls(critical, name, namespace, human_readable, value)