1# This file is Copyright 2019 Volatility Foundation and licensed under the Volatility Software License 1.0
2# which is available at https://www.volatilityfoundation.org/license/vsl-v1.0
3#
4
5from typing import List, Mapping
6
7from volatility.framework import interfaces
8
9
10class Flags:
11    """Object that converts an integer into a set of flags based on their
12    masks."""
13
14    def __init__(self, choices: Mapping[str, int]) -> None:
15        self._choices = interfaces.objects.ReadOnlyMapping(choices)
16
17    @property
18    def choices(self) -> interfaces.objects.ReadOnlyMapping:
19        return self._choices
20
21    def __call__(self, value: int) -> List[str]:
22        """Return the appropriate Flags."""
23        result = []
24        for k, v in self.choices.items():
25            if value & v:
26                result.append(k)
27        return result
28