Esempio n. 1
0
 async def device_id(self) -> str:
     """:return: the current device id"""
     c_future = tankerlib.tanker_device_id(self.c_tanker)
     c_voidp = await ffihelpers.handle_tanker_future(c_future)
     c_str = ffi.cast("char*", c_voidp)
     res = ffihelpers.c_string_to_str(c_str)
     tankerlib.tanker_free_buffer(c_str)
     return res
Esempio n. 2
0
    async def create_group(self, member_identities: List[str]) -> str:
        """Create a group containing the users in `user_ids`"""
        member_list = CCharList(member_identities, ffi, tankerlib)
        c_future = tankerlib.tanker_create_group(self.c_tanker,
                                                 member_list.data,
                                                 member_list.size)

        c_voidp = await ffihelpers.handle_tanker_future(c_future)
        c_str = ffi.cast("char*", c_voidp)
        return ffihelpers.c_string_to_str(c_str)
Esempio n. 3
0
    async def start(self, identity: str) -> Status:
        """Start a new Tanker session

        :param identity: The user's Tanker identity
        :return: A :py:class:`Status` enum
        """
        c_identity = ffihelpers.str_to_c_string(identity)
        c_future = tankerlib.tanker_start(self.c_tanker, c_identity)
        c_voidp = await ffihelpers.handle_tanker_future(c_future)
        return Status(int(ffi.cast("int", c_voidp)))
Esempio n. 4
0
    async def generate_verification_key(self) -> str:
        """Generate a private unlock key

        This can be used to verify an indentity later on
        """
        c_future = tankerlib.tanker_generate_verification_key(self.c_tanker)
        c_voidp = await ffihelpers.handle_tanker_future(c_future)
        c_str = ffi.cast("char*", c_voidp)
        res = ffihelpers.c_string_to_str(c_str)
        tankerlib.tanker_free_buffer(c_str)
        return res
Esempio n. 5
0
 async def _read_with_size(self, size: int) -> bytes:
     buf = bytearray(size)
     c_buf = ffi.from_buffer("uint8_t[]", buf)
     read_fut = tankerlib.tanker_stream_read(self.c_stream, c_buf, size)
     try:
         c_voidptr = await ffihelpers.handle_tanker_future(read_fut)
     except TankerError:
         if self.error:
             raise self.error
         else:
             raise
     nb_read = int(ffi.cast("intptr_t", c_voidptr))
     return buf[0:nb_read]
Esempio n. 6
0
    async def get_verification_methods(self) -> List[VerificationMethod]:
        """Get the list of available verification methods"""
        c_future = tankerlib.tanker_get_verification_methods(self.c_tanker)
        c_voidp = await ffihelpers.handle_tanker_future(c_future)

        c_list = ffi.cast("tanker_verification_method_list_t*", c_voidp)
        count = c_list.count
        c_methods = c_list.methods
        res = list()
        for i in range(count):
            c_method = c_methods[i]
            method = verification_method_from_c(c_method)
            res.append(method)
        tankerlib.tanker_free_verification_method_list(c_list)
        return res
Esempio n. 7
0
    async def get_device_list(self) -> List[Device]:
        """Get the list of devices owned by the current user

        :returns: a list of :py:class`Device` instances
        """
        c_future = tankerlib.tanker_get_device_list(self.c_tanker)
        c_voidp = await ffihelpers.handle_tanker_future(c_future)
        c_list = ffi.cast("tanker_device_list_t*", c_voidp)
        count = c_list.count
        c_devices = c_list.devices
        res = list()
        for i in range(count):
            c_device_list_elem = c_devices[i]
            device_description = Device.from_c(c_device_list_elem)
            res.append(device_description)
        tankerlib.tanker_free_device_list(c_list)
        return res
Esempio n. 8
0
    async def attach_provisional_identity(
            self, provisional_identity: str) -> AttachResult:
        """Attach a provisional identity

        :return: an instance of :py:class:`AttachResult`
        """
        c_future = tankerlib.tanker_attach_provisional_identity(
            self.c_tanker, ffihelpers.str_to_c_string(provisional_identity))
        c_voidp = await ffihelpers.handle_tanker_future(c_future)
        c_attach_result = ffi.cast("tanker_attach_result_t*", c_voidp)
        status = Status(c_attach_result.status)
        result = AttachResult(status)
        if status == Status.IDENTITY_VERIFICATION_NEEDED:
            c_method = c_attach_result.method
            result.verification_method = verification_method_from_c(c_method)
        tankerlib.tanker_free_attach_result(c_attach_result)
        return result
Esempio n. 9
0
    async def set_verification_method(
            self,
            verification: Verification,
            options: Optional[VerificationOptions] = None) -> Optional[str]:
        """Set or update a verification method"""
        c_verification = CVerification(verification)
        if options:
            c_verif_opts = CVerificationOptions(
                with_session_token=options.with_session_token, ).get()
        else:
            c_verif_opts = ffi.NULL
        c_future = tankerlib.tanker_set_verification_method(
            self.c_tanker, c_verification.get(), c_verif_opts)

        c_voidp = await ffihelpers.handle_tanker_future(c_future)
        if c_voidp == ffi.NULL:
            return None
        c_str = ffi.cast("char*", c_voidp)
        res = ffihelpers.c_string_to_str(c_str)
        tankerlib.tanker_free_buffer(c_str)
        return res
Esempio n. 10
0
 def _create_tanker_obj(self) -> None:
     c_url = ffihelpers.str_to_c_string(self.url)
     c_app_id = ffihelpers.str_to_c_string(self.app_id)
     c_persistent_path = ffihelpers.str_to_c_string(self.persistent_path)
     c_cache_path = ffihelpers.str_to_c_string(self.cache_path)
     c_sdk_type = ffihelpers.str_to_c_string(self.sdk_type)
     c_sdk_version = ffihelpers.str_to_c_string(__version__)
     tanker_options = ffi.new(
         "tanker_options_t *",
         {
             "version": 4,
             "app_id": c_app_id,
             "url": c_url,
             "persistent_path": c_persistent_path,
             "sdk_type": c_sdk_type,
             "sdk_version": c_sdk_version,
             "http_options": {
                 "send_request": ffi.NULL,
                 "cancel_request": ffi.NULL,
                 "data": ffi.NULL,
             },
             "cache_path": c_cache_path,
             "datastore_options": {
                 "open": ffi.NULL,
                 "close": ffi.NULL,
                 "nuke": ffi.NULL,
                 "put_serialized_device": ffi.NULL,
                 "find_serialized_device": ffi.NULL,
                 "put_cache_values": ffi.NULL,
                 "find_cache_values": ffi.NULL,
             },
         },
     )
     create_fut = tankerlib.tanker_create(tanker_options)
     ffihelpers.wait_fut_or_raise(create_fut)
     c_voidp = tankerlib.tanker_future_get_voidptr(create_fut)
     self.c_tanker = ffi.cast("tanker_t*", c_voidp)