Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion klvdata/elementparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ def __str__(self):

class MappedElementParser(ElementParser, metaclass=ABCMeta):
def __init__(self, value):
super().__init__(MappedValue(value, self._domain, self._range))
try:
super().__init__(MappedValue(value, self._domain, self._range))
except ValueError:
print('Error in decoding Tag n.', self.key.hex(), ' (hexadecimal)')

@property
@classmethod
Expand Down
214 changes: 213 additions & 1 deletion klvdata/misb0102.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from klvdata.common import hexstr_to_bytes
from klvdata.element import UnknownElement
from klvdata.elementparser import BytesElementParser
from klvdata.elementparser import StringElementParser
from klvdata.misb0601 import UASLocalMetadataSet
from klvdata.setparser import SetParser
from klvdata.streamparser import StreamParser

_classifying_country_coding = {
b'\x01': 'ISO-3166 Two Letter',
Expand Down Expand Up @@ -83,6 +86,13 @@ class SecurityLocalMetadataSet(SetParser):
Must be a subclass of Element or duck type Element.
"""
key, name = b'\x30', "Security Local Metadata Set"

TAG = 48
UDSKey = hexstr_to_bytes('06 0E 2B 34 - 02 03 01 01 – 0E 01 03 03 - 02 00 00 00')
LDSName = "Security Local Metadata Set"
ESDName = ""
UDSName = ""

parsers = {}

_unknown_element = UnknownElement
Expand All @@ -97,11 +107,213 @@ class SecurityClassification(BytesElementParser):
accordance with U.S. and NATO classification guidance.
"""
key = b'\x01'

TAG = 1
UDSKey = "-"
LDSName = "Security Classification"
ESDName = ""
UDSName = ""

_classification = {
b'\x01': 'UNCLASSIFIED',
b'\x02': 'RESTRICTED',
b'\x03': 'CONFIDENTIAL',
b'\x04': 'SECRET',
b'\x05': 'TOP SECRET',
}


@SecurityLocalMetadataSet.add_parser
class ClassifyingCountryAndReleasingInstructionCCM(BytesElementParser):
"""
"""
key = b'\x02'
TAG = 2
UDSKey = "-"
LDSName = "Classifying Country And Releasing Instruction Country Coding Method"
ESDName = ""
UDSName = ""

_classification = _classifying_country_coding


@SecurityLocalMetadataSet.add_parser
class ClassifyingCountry(StringElementParser):
"""
"""
key = b'\x03'
TAG = 3
UDSKey = "-"
LDSName = "Classyfing Country"
ESDName = ""
UDSName = ""


@SecurityLocalMetadataSet.add_parser
class SecuritySCISHIInformation(StringElementParser):
"""
"""
key = b'\x04'
TAG = 4
UDSKey = "-"
LDSName = 'Security-SCI/SHI Information'
ESDName = ""
UDSName = ""


@SecurityLocalMetadataSet.add_parser
class Caveats(StringElementParser):
"""
"""
key = b'\x05'
TAG = 5
UDSKey = "-"
LDSName = 'Caveats'
ESDName = ""
UDSName = ""


@SecurityLocalMetadataSet.add_parser
class ReleasingInstructions(StringElementParser):
"""
"""
key = b'\x06'
TAG = 6
UDSKey = "-"
LDSName = 'Releasing Instructions'
ESDName = ""
UDSName = ""


@SecurityLocalMetadataSet.add_parser
class ClassifiedBy(StringElementParser):
"""
"""
key = b'\x07'
TAG = 7
UDSKey = "-"
LDSName = 'Classified By'
ESDName = ""
UDSName = ""


@SecurityLocalMetadataSet.add_parser
class DerivedFrom(StringElementParser):
"""
"""
key = b'\x08'
TAG = 8
UDSKey = "-"
LDSName = 'Derived From'
ESDName = ""
UDSName = ""


@SecurityLocalMetadataSet.add_parser
class ClassificationReason(StringElementParser):
"""
"""
key = b'\x09'
TAG = 9
UDSKey = "-"
LDSName = 'Classification Reason'
ESDName = ""
UDSName = ""


@SecurityLocalMetadataSet.add_parser
class DeclassificationDate(StringElementParser):
"""
"""
key = b'\x0A'
TAG = 10
UDSKey = "-"
LDSName = 'Declassification Date'
ESDName = ""
UDSName = ""
min_length, max_length = 8, 8


@SecurityLocalMetadataSet.add_parser
class ClassificationAndMarkingSystem(StringElementParser):
"""
"""
key = b'\x0B'
TAG = 11
UDSKey = "-"
LDSName = 'Classification And Marking System'
ESDName = ""
UDSName = ""


@SecurityLocalMetadataSet.add_parser
class ObjectCountryCodingMethod(BytesElementParser):
"""
"""
key = b'\x0C'
TAG = 12
UDSKey = "-"
LDSName = 'Object Country Coding Method'
ESDName = ""
UDSName = ""

_classification = _object_country_coding


@SecurityLocalMetadataSet.add_parser
class ObjectCountryCodes(StringElementParser):
"""
"""
key = b'\x0D'
TAG = 13
UDSKey = "-"
LDSName = 'Object Country Codes'
ESDName = ""
UDSName = ""


@SecurityLocalMetadataSet.add_parser
class ClassificationComments(StringElementParser):
"""
"""
key = b'\x0E'
TAG = 14
UDSKey = "-"
LDSName = 'Classification Comments'
ESDName = ""
UDSName = ""


@SecurityLocalMetadataSet.add_parser
class Version(BytesElementParser):
"""
"""
key = b'\x16'
TAG = 22
UDSKey = "-"
LDSName = 'Version'
ESDName = ""
UDSName = ""


@SecurityLocalMetadataSet.add_parser
class ClassifyingCountryAndReleasingInstructionCCMVD(StringElementParser):
"""
"""
key = b'\x17'
TAG = 23
UDSKey = "-"
LDSName = 'Classifying Country And Releasing Instruction Courntry Coding Method Version Date'
ESDName = ""
UDSName = ""


@SecurityLocalMetadataSet.add_parser
class ClassifyingCountryCodeMethodVersionDate(StringElementParser):
"""
"""
key = b'\x18'
TAG = 24
UDSKey = "-"
LDSName = 'Classifying Country Code Method Version Date'
ESDName = ""
UDSName = ""
16 changes: 8 additions & 8 deletions klvdata/misb0601.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,14 +660,14 @@ class GenericFlagData01(MappedElementParser):
_range = (0, 2**8-1)


# @UASLocalMetadataSet.add_parser
# class SecurityLocalMetadataSet(MappedElementParser):
# key = b'\x30'
# TAG = 48
# UDSKey = "06 0E 2B 34 02 03 01 01 0E 01 03 03 02 00 00 00"
# LDSName = "Security Local Set"
# ESDName = ""
# UDSName = "Security Local Set"
@UASLocalMetadataSet.add_parser
class SecurityLocalMetadataSet(MappedElementParser):
key = b'\x30'
TAG = 48
UDSKey = "06 0E 2B 34 02 03 01 01 0E 01 03 03 02 00 00 00"
LDSName = "Security Local Set"
ESDName = ""
UDSName = "Security Local Set"


@UASLocalMetadataSet.add_parser
Expand Down
15 changes: 12 additions & 3 deletions klvdata/setparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def parse(self):
except KeyError:
self.items[key] = self._unknown_element(key, value)


@classmethod
def add_parser(cls, obj):
"""Decorator method used to register a parser to the class parsing repertoire.
Expand Down Expand Up @@ -100,18 +101,26 @@ def __str__(self):
return str_dict(self.items)

def MetadataList(self):

''' Return metadata dictionary'''

metadata = {}

def repeat(items, indent=1):
def repeat(items, indent=1, parentTAG=0):
for item in items:
try:
metadata[item.TAG] = (item.LDSName, item.ESDName, item.UDSName, str(item.value.value))
if not parentTAG :
metadata[item.TAG] = (item.LDSName, item.ESDName, item.UDSName, str(item.value.value))
else :
metadata[parentTAG][len(metadata[parentTAG])-1][item.TAG] = (item.LDSName, item.ESDName, item.UDSName, str(item.value.value))
except:
None
if hasattr(item, 'items'):
repeat(item.items.values(), indent + 1)
metadata[item.TAG] = (item.LDSName, item.ESDName, item.UDSName, {})
repeat(item.items.values(), indent + 1, item.TAG)

repeat(self.items.values())

return OrderedDict(metadata)

def structure(self):
Expand Down