-
Notifications
You must be signed in to change notification settings - Fork 0
/
ByteBuf.py
32 lines (26 loc) · 859 Bytes
/
ByteBuf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from pkcs7_padding import pkcs7_padding_data_length
import ctypes
class ByteBuf:
def __init__(self, data, size=None):
if data:
self.mem = data
if size is not None:
self.data_size = size
elif data is not None:
self.data_size = len(data)
else:
raise ValueError("Either size or data must be provided")
self.pos = 0
def data(self):
return self.mem
def size(self):
return self.data_size
def remove_padding(self):
padding_size = pkcs7_padding_data_length(self.mem, self.data_size, 16)
if padding_size == 0:
return self.data_size
self.data_size = padding_size
dst = (ctypes.c_uint8 * self.data_size)()
dst = self.mem[:self.data_size]
self.mem = dst
return self.mem