aboutsummaryrefslogtreecommitdiffhomepage
path: root/pyecsca/sca/trace_set/base.py
blob: 222193332b09d5e5bfa6e161dcd9a14c6828476c (plain) (blame)
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 public import public
from typing import List

from ..trace import Trace


@public
class TraceSet(object):
    _traces: List = []
    _keys: List = []

    def __init__(self, *traces: Trace, **kwargs):
        self._traces = list(traces)
        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

    def __repr__(self):
        args = ", ".join(["{}={!r}".format(key, getattr(self, key)) for key in
                          self._keys])
        return "TraceSet({})".format(args)