Example #1
0
 def decrypt(self, passphrase):
     algo = ffi.new("uint8_t[1]")
     key = ffi.new("uint8_t[32]")
     key_len = ffi.new("size_t[1]")
     key_len[0] = len(key)
     invoke(lib.pgp_skesk_decrypt, self.ref(), ffi.from_buffer(passphrase),
            len(passphrase), algo, key, key_len)
     return (algo[0], ffi.buffer(key, key_len[0]))
Example #2
0
    def recurse(self):
        packet = ffi.new("pgp_packet_t[1]")
        old_rl = ffi.new("uint8_t[1]")
        ppr = ffi.new("pgp_packet_parser_result_t[1]")
        new_rl = ffi.new("uint8_t[1]")

        invoke(lib.pgp_packet_parser_recurse, self.ref_consume(), packet, ppr)

        return (Packet(packet[0]), PacketParserResult(ppr[0], self.context()))
Example #3
0
 def next_fn(i):
     labelp = ffi.new("char *[1]")
     fpp = ffi.new("pgp_fingerprint_t[1]")
     binding = lib.sq_binding_iter_next(i, labelp, fpp)
     if binding == ffi.NULL:
         return ffi.NULL
     else:
         return (_str(labelp[0]), Fingerprint(fpp[0], self.context()),
                 Binding(binding, self.context()))
Example #4
0
 def next_fn(i):
     fpp = ffi.new("pgp_fingerprint_t[1]")
     key = lib.sq_key_iter_next(i, fpp)
     if key == ffi.NULL:
         return ffi.NULL
     else:
         return (Fingerprint(fpp[0], ctx), Key(key, ctx))
Example #5
0
def invoke(fun, *args):
    """Invokes the given FFI function.

    This function invokes the given FFI function.  It must only be
    used for functions that expect an error pointer as first argument.

    If an error is encountered, an exception is raised.
    """
    err = ffi.new("pgp_error_t[1]")
    result = fun(err, *args)
    if err[0] != ffi.NULL:
        raise Error._from(err[0])
    return result
Example #6
0
 def buffer_unread_content(self):
     buf_len = ffi.new("size_t[1]")
     buf = invoke(lib.pgp_packet_parser_buffer_unread_content, self.ref(),
                  buf_len)
     return ffi.buffer(buf, buf_len[0])
Example #7
0
 def value(self):
     buf_len = ffi.new("size_t[1]")
     buf = lib.pgp_user_attribute_value(self.ref(), buf_len)
     return ffi.buffer(buf, buf_len[0])