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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
"""Provides a base traceset class."""
from pathlib import Path
from typing import List, Union, BinaryIO
from public import public
from pyecsca.sca.trace import Trace
@public
class TraceSet:
"""Set of traces with some metadata."""
_traces: List[Trace]
_keys: List
def __init__(self, *traces: Trace, **kwargs):
self._traces = list(traces)
for trace in self._traces:
trace.trace_set = self
self.__dict__.update(kwargs)
self._keys = list(kwargs.keys())
def __len__(self):
"""Return the number of traces."""
return len(self._traces)
def __getitem__(self, index) -> Trace:
"""Get the trace at `index`."""
return self._traces[index]
def __iter__(self):
"""Iterate over the traces."""
yield from self._traces
@classmethod
def read(cls, input: Union[str, Path, bytes, BinaryIO], **kwargs) -> "TraceSet":
raise NotImplementedError
@classmethod
def inplace(cls, input: Union[str, Path, bytes, BinaryIO], **kwargs) -> "TraceSet":
raise NotImplementedError
def write(self, output: Union[str, Path, BinaryIO]):
raise NotImplementedError
def __repr__(self):
args = ", ".join(
[f"{key}={getattr(self, key)!r}" for key in self._keys]
)
return f"{self.__class__.__name__}({args})"
|