Skip to content

Commit b4f8943

Browse files
committed
Merge branch 'pilip/remove-revocation' into 'master'
Pilip/remove revocation See merge request TankerHQ/sdk-python!224
2 parents 317c50c + 9dfa0df commit b4f8943

File tree

3 files changed

+12
-94
lines changed

3 files changed

+12
-94
lines changed

cffi_defs.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,6 @@ enum tanker_status
205205
TANKER_STATUS_LAST
206206
};
207207

208-
enum tanker_event
209-
{
210-
TANKER_EVENT_SESSION_CLOSED,
211-
TANKER_EVENT_DEVICE_REVOKED,
212-
213-
TANKER_EVENT_LAST,
214-
};
215-
216208
enum tanker_verification_method_type
217209
{
218210
TANKER_VERIFICATION_METHOD_EMAIL = 0x1,
@@ -288,9 +280,6 @@ struct tanker_log_record
288280

289281
typedef void (*tanker_log_handler_t)(tanker_log_record_t const* record);
290282

291-
typedef struct tanker_connection tanker_connection_t;
292-
typedef void (*tanker_event_callback_t)(void* arg, void* data);
293-
294283
struct tanker_options
295284
{
296285
uint8_t version;
@@ -391,14 +380,6 @@ tanker_future_t* tanker_create(tanker_options_t const* options);
391380

392381
tanker_future_t* tanker_destroy(tanker_t* tanker);
393382

394-
tanker_expected_t* tanker_event_connect(tanker_t* tanker,
395-
enum tanker_event event,
396-
tanker_event_callback_t cb,
397-
void* data);
398-
399-
tanker_expected_t* tanker_event_disconnect(tanker_t* tanker,
400-
enum tanker_event event);
401-
402383
tanker_future_t* tanker_start(tanker_t* tanker, char const* identity);
403384

404385
tanker_expected_t* tanker_enroll_user(tanker_t* tanker,
@@ -462,8 +443,6 @@ tanker_future_t* tanker_attach_provisional_identity(
462443
tanker_future_t* tanker_verify_provisional_identity(
463444
tanker_t* ctanker, tanker_verification_t const* verification);
464445

465-
tanker_future_t* tanker_revoke_device(tanker_t* session, char const* device_id);
466-
467446
void tanker_free_buffer(void const* buffer);
468447

469448
void tanker_free_device_list(tanker_device_list_t* list);
@@ -548,7 +527,6 @@ tanker_future_t* tanker_encryption_session_stream_encrypt(
548527

549528
// cffi specific
550529
extern "Python" void log_handler(tanker_log_record_t*);
551-
extern "Python" void revoke_callback(void* arg, void* data);
552530
extern "Python" void stream_input_source_callback(
553531
uint8_t* buffer,
554532
int64_t buffer_size,

tankersdk/tanker.py

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import warnings
44
import weakref
55
from enum import Enum
6-
from typing import Any, Callable, List, Optional, cast
6+
from typing import Any, List, Optional, cast
77

88
import typing_extensions
99
from _tanker import ffi
@@ -35,13 +35,6 @@ def log_handler(record: CData) -> None:
3535
tankerlib.tanker_set_log_handler(tankerlib.log_handler)
3636

3737

38-
@ffi.def_extern() # type: ignore
39-
def revoke_callback(args: CData, data: CData) -> None:
40-
tanker_instance = ffi.from_handle(data)() # data is a weakref.ref
41-
if tanker_instance and tanker_instance.on_revoked:
42-
tanker_instance.on_revoked()
43-
44-
4538
class Status(Enum):
4639
"""Represent the status of a Tanker session"""
4740

@@ -204,9 +197,6 @@ def verification_method_from_c(c_verification_method: CData) -> VerificationMeth
204197
return res
205198

206199

207-
RevokeFunc = Callable[[], None]
208-
209-
210200
class AttachResult:
211201
"""Represent the result of a call to `attach_provisional_identity`
212202
@@ -631,8 +621,6 @@ def __init__(
631621
self.c_tanker = None
632622

633623
self._create_tanker_obj()
634-
self._set_event_callbacks()
635-
self.on_revoked = None # type: Optional[RevokeFunc]
636624

637625
def __del__(self) -> None:
638626
if getattr(self, "c_tanker", None):
@@ -695,19 +683,6 @@ def _create_tanker_obj(self) -> None:
695683
c_voidp = tankerlib.tanker_future_get_voidptr(create_fut)
696684
self.c_tanker = ffi.cast("tanker_t*", c_voidp)
697685

698-
def _set_event_callbacks(self) -> None:
699-
# userdata must live as long as self, and userdata must not hold a
700-
# reference on self
701-
userdata = ffi.new_handle(weakref.ref(self))
702-
_GLOBAL_TANKERS[self] = userdata
703-
c_future_connect = tankerlib.tanker_event_connect(
704-
self.c_tanker,
705-
tankerlib.TANKER_EVENT_DEVICE_REVOKED,
706-
tankerlib.revoke_callback,
707-
userdata,
708-
)
709-
ffihelpers.wait_fut_or_raise(c_future_connect)
710-
711686
@property
712687
def status(self) -> Status:
713688
"""Retrieve the status of the current session, as a :py:class:`Status` instance"""
@@ -846,6 +821,11 @@ async def decrypt_stream(self, encrypted_stream: Stream) -> Stream:
846821

847822
async def device_id(self) -> str:
848823
""":return: the current device id"""
824+
warnings.warn(
825+
'The "device_id" method is deprecated, it will be removed in the future',
826+
DeprecationWarning,
827+
)
828+
849829
c_future = tankerlib.tanker_device_id(self.c_tanker)
850830
c_voidp = await ffihelpers.handle_tanker_future(c_future)
851831
c_str = ffi.cast("char*", c_voidp)
@@ -858,6 +838,11 @@ async def get_device_list(self) -> List[Device]:
858838
859839
:returns: a list of :py:class`Device` instances
860840
"""
841+
warnings.warn(
842+
'The "get_device_list" method is deprecated, it will be removed in the future',
843+
DeprecationWarning,
844+
)
845+
861846
c_future = tankerlib.tanker_get_device_list(self.c_tanker)
862847
c_voidp = await ffihelpers.handle_tanker_future(c_future)
863848
c_list = ffi.cast("tanker_device_list_t*", c_voidp)
@@ -871,16 +856,6 @@ async def get_device_list(self) -> List[Device]:
871856
tankerlib.tanker_free_device_list(c_list)
872857
return res
873858

874-
async def revoke_device(self, device_id: str) -> None:
875-
"""Revoke the given device"""
876-
warnings.warn(
877-
'The "revoke_device" method is deprecated, it will be removed in the future',
878-
DeprecationWarning,
879-
)
880-
c_device_id = ffihelpers.str_to_c_string(device_id)
881-
c_future = tankerlib.tanker_revoke_device(self.c_tanker, c_device_id)
882-
await ffihelpers.handle_tanker_future(c_future)
883-
884859
def get_resource_id(self, encrypted_data: bytes) -> str:
885860
"""Get resource ID from `encrypted` data"""
886861
c_expected = tankerlib.tanker_get_resource_id(

test/test_tanker.py

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
import base64
32
import io
43
import json
@@ -624,43 +623,17 @@ async def test_add_device(tmp_path: Path, app: Dict[str, str]) -> None:
624623
await phone.stop()
625624

626625

627-
@pytest.mark.asyncio
628-
async def test_revoke_device(tmp_path: Path, app: Dict[str, str]) -> None:
629-
_, laptop, phone = await create_two_devices(tmp_path, app)
630-
laptop_id = await laptop.device_id()
631-
laptop_revoked = asyncio.Event()
632-
loop = asyncio.get_event_loop()
633-
634-
def on_revoked() -> None:
635-
async def cb() -> None:
636-
laptop_revoked.set()
637-
638-
asyncio.run_coroutine_threadsafe(cb(), loop)
639-
640-
laptop.on_revoked = on_revoked
641-
await phone.revoke_device(laptop_id)
642-
with pytest.raises(error.DeviceRevoked):
643-
await laptop.encrypt(b"will fail")
644-
# Check callback is called
645-
await asyncio.wait_for(laptop_revoked.wait(), timeout=1)
646-
assert laptop.status == TankerStatus.STOPPED
647-
648-
649626
@pytest.mark.asyncio
650627
async def test_get_device_list(tmp_path: Path, app: Dict[str, str]) -> None:
651628
_, laptop, phone = await create_two_devices(tmp_path, app)
652629
laptop_id = await laptop.device_id()
653630
phone_id = await phone.device_id()
654631

655-
await phone.revoke_device(laptop_id)
656-
657632
actual_list = await phone.get_device_list()
658633
actual_ids = [x.device_id for x in actual_list]
659634
assert set(actual_ids) == set([laptop_id, phone_id])
660635
revoked = [x for x in actual_list if x.is_revoked]
661-
assert len(revoked) == 1
662-
actual_revoked_id = revoked[0].device_id
663-
assert actual_revoked_id == laptop_id
636+
assert len(revoked) == 0
664637

665638

666639
@pytest.mark.asyncio
@@ -1138,14 +1111,6 @@ async def test_group_not_found(tmp_path: Path, app: Dict[str, str]) -> None:
11381111
)
11391112

11401113

1141-
@pytest.mark.asyncio
1142-
async def test_device_not_found(tmp_path: Path, app: Dict[str, str]) -> None:
1143-
device_id = encode("*" * 32)
1144-
alice = await create_user_session(tmp_path, app)
1145-
with pytest.raises(error.InvalidArgument):
1146-
await alice.session.revoke_device(device_id)
1147-
1148-
11491114
@pytest.mark.asyncio
11501115
async def test_get_verification_methods(tmp_path: Path, app: Dict[str, str]) -> None:
11511116
tanker = create_tanker(app["id"], persistent_path=tmp_path)

0 commit comments

Comments
 (0)