Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# Impacket - Collection of Python classes for working with network protocols. 

2# 

3# SECUREAUTH LABS. Copyright (C) 2021 SecureAuth Corporation. All rights reserved. 

4# 

5# This software is provided under a slightly modified version 

6# of the Apache Software License. See the accompanying LICENSE file 

7# for more information. 

8# 

9# Description: 

10# IEEE 802.11 Network packet codecs. 

11# 

12# Author: 

13# Gustavo Moreira 

14 

15from array import array 

16class KeyManager: 

17 def __init__(self): 

18 self.keys = {} 

19 

20 def __get_bssid_hasheable_type(self, bssid): 

21 # List is an unhashable type 

22 if not isinstance(bssid, (list,tuple,array)): 22 ↛ 23line 22 didn't jump to line 23, because the condition on line 22 was never true

23 raise Exception('BSSID datatype must be a tuple, list or array') 

24 return tuple(bssid) 

25 

26 def add_key(self, bssid, key): 

27 bssid=self.__get_bssid_hasheable_type(bssid) 

28 if bssid not in self.keys: 28 ↛ 32line 28 didn't jump to line 32, because the condition on line 28 was never false

29 self.keys[bssid] = key 

30 return True 

31 else: 

32 return False 

33 

34 def replace_key(self, bssid, key): 

35 bssid=self.__get_bssid_hasheable_type(bssid) 

36 self.keys[bssid] = key 

37 

38 return True 

39 

40 def get_key(self, bssid): 

41 bssid=self.__get_bssid_hasheable_type(bssid) 

42 if bssid in self.keys: 42 ↛ 45line 42 didn't jump to line 45, because the condition on line 42 was never false

43 return self.keys[bssid] 

44 else: 

45 return False 

46 

47 def delete_key(self, bssid): 

48 bssid=self.__get_bssid_hasheable_type(bssid) 

49 if not isinstance(bssid, list): 

50 raise Exception('BSSID datatype must be a list') 

51 

52 if bssid in self.keys: 

53 del self.keys[bssid] 

54 return True 

55 

56 return False