Skip to content

Commit

Permalink
Logging for ASN1 schema fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
impratikjaiswal committed Jun 29, 2024
1 parent 44cf812 commit a987493
Show file tree
Hide file tree
Showing 103 changed files with 5,236 additions and 2,614 deletions.
2 changes: 1 addition & 1 deletion asn1_play/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

from incremental import Version

__version__ = Version("asn1_play", 8, 3, 0)
__version__ = Version("asn1_play", 8, 3, 1)
__all__ = ["__version__"]
6 changes: 4 additions & 2 deletions asn1_play/generated_code/asn1/asn1.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def __set_asn1_object(self, asn1_object):

def __set_asn1_object_alternate(self, asn1_object_alternate):
if asn1_object_alternate is None and self.asn1_object is not None:
self.asn1_object_alternate = self.asn1_object.replace('-', '_')
temp = self.asn1_object.replace('-', '_')
if temp != self.asn1_object:
self.asn1_object_alternate = temp
else:
self.asn1_object_alternate = asn1_object_alternate

Expand All @@ -71,4 +73,4 @@ def get_asn1_object_list(self, str_format=False):
return PhConstants.SEPERATOR_TWO_LINES.join(self.asn1_objects_list) if str_format else self.asn1_objects_list

def __set_asn1_objects_list(self):
self.asn1_objects_list = list(self.get_asn1_mapping().keys())
self.asn1_objects_list = list(self.get_asn1_mapping().keys()) if self.asn1_mapping else None
33 changes: 26 additions & 7 deletions asn1_play/main/convert/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,33 @@ def print_data(data, meta_data):
meta_data.output_dic.update(
get_dic_data_and_print(PhKeys.REMARKS_GENERATED, PhConstants.SEPERATOR_ONE_LINE,
remarks_generated))
asn1_info = data.get_asn1_element_info()
info = PhConstants.SEPERATOR_MULTI_OBJ.join(filter(None, [
get_dic_data_and_print(PhKeys.TRANSACTION_ID, PhConstants.SEPERATOR_ONE_LINE, meta_data.transaction_id,
dic_format=False, print_also=False),
get_dic_data_and_print(PhKeys.MODE, PhConstants.SEPERATOR_ONE_LINE,
get_mode(data.input_format, data.output_format, meta_data.input_mode_key,
data.get_input_modes_hierarchy()), dic_format=False, print_also=False),
get_dic_data_and_print(PhKeys.ASN1_ELEMENT, PhConstants.SEPERATOR_ONE_LINE, data.get_asn1_element_name(),
dic_format=False,
print_also=False) if data.get_asn1_element_name() else None,
#
get_dic_data_and_print(PhKeys.ASN1_SCHEMA, PhConstants.SEPERATOR_ONE_LINE,
asn1_info.get(PhKeys.ASN1_SCHEMA), dic_format=False,
print_also=False) if asn1_info.get(PhKeys.ASN1_SCHEMA, None) else None,
get_dic_data_and_print(PhKeys.ASN1_MODULE, PhConstants.SEPERATOR_ONE_LINE,
asn1_info.get(PhKeys.ASN1_MODULE), dic_format=False,
print_also=False) if asn1_info.get(PhKeys.ASN1_MODULE, None) else None,
get_dic_data_and_print(PhKeys.ASN1_MODULE_VERSION, PhConstants.SEPERATOR_ONE_LINE,
asn1_info.get(PhKeys.ASN1_MODULE_VERSION), dic_format=False,
print_also=False) if asn1_info.get(PhKeys.ASN1_MODULE_VERSION, None) else None,
get_dic_data_and_print(PhKeys.ASN1_OBJECT, PhConstants.SEPERATOR_ONE_LINE,
asn1_info.get(PhKeys.ASN1_OBJECT), dic_format=False,
print_also=False) if asn1_info.get(PhKeys.ASN1_OBJECT, None) else None,
get_dic_data_and_print(PhKeys.ASN1_OBJECT_ALTERNATE, PhConstants.SEPERATOR_ONE_LINE,
asn1_info.get(PhKeys.ASN1_OBJECT_ALTERNATE), dic_format=False,
print_also=False) if asn1_info.get(PhKeys.ASN1_OBJECT_ALTERNATE, None) else None,
get_dic_data_and_print(PhKeys.FETCH_ASN1_OBJECTS_LIST, PhConstants.SEPERATOR_ONE_LINE,
asn1_info.get(PhKeys.FETCH_ASN1_OBJECTS_LIST), dic_format=False,
print_also=False) if asn1_info.get(PhKeys.FETCH_ASN1_OBJECTS_LIST, None) else None,
#
get_dic_data_and_print(PhKeys.INPUT_FORMAT, PhConstants.SEPERATOR_ONE_LINE, data.input_format,
dic_format=False, print_also=False),
get_dic_data_and_print(PhKeys.OUTPUT_FORMAT, PhConstants.SEPERATOR_ONE_LINE, data.output_format,
Expand Down Expand Up @@ -102,7 +120,7 @@ def print_data(data, meta_data):


def get_dic_data_and_print(key, sep, value, dic_format=True, print_also=True):
if value is not None and '\n' in value:
if value is not None and isinstance(value, str) and '\n' in value:
value = PreservedScalarString(value)
return PhUtil.get_key_value_pair(key=key, value=value, sep=sep, dic_format=dic_format, print_also=print_also)

Expand Down Expand Up @@ -138,9 +156,10 @@ def prepare_config_data(data):
if not v:
continue
if k in [PhKeys.ASN1_ELEMENT]:
value = data.get_asn1_element_name()
value_alternate = data.get_asn1_element_name_alternate()
module_name = data.get_asn1_module_name()
asn1_element_info = data.get_asn1_element_info(verbose=True)
value = asn1_element_info.get(PhKeys.ASN1_OBJECT)
value_alternate = asn1_element_info.get(PhKeys.ASN1_OBJECT_ALTERNATE)
module_name = asn1_element_info.get(PhKeys.ASN1_MODULE)
class_obj = None
module_path = None
# Legacy Code
Expand Down
8 changes: 3 additions & 5 deletions asn1_play/main/convert/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def decode_encode_asn(input_data=PhConstants.STR_EMPTY, parse_only=True, input_f
PhExceptionHelper(msg_key=Constants.INPUT_DATA_CONVERSION_NOT_POSSIBLE, function_name=func_name,
additional_msgs_list=additional_msgs_list))
if not asn1_element or asn1_element is None:
raise ValueError(PhExceptionHelper(msg_key=Constants.ASN1_ELEMENT_IS_EMPTY_OR_MISSING, function_name=func_name))
raise ValueError(PhExceptionHelper(msg_key=Constants.ASN1_SCHEMA_IS_EMPTY_OR_MISSING, function_name=func_name))
if isinstance(asn1_element, Asn1):
# Run Time Versions
asn1_object = asn1_element.get_asn1_object()
Expand All @@ -109,10 +109,8 @@ def decode_encode_asn(input_data=PhConstants.STR_EMPTY, parse_only=True, input_f
print_debug_var(Constants.ASN1_ELEMENT_MAPPING_IS_DONE)
if asn1_element_fetched is None:
raise ValueError(
PhExceptionHelper(msg_key=Constants.UNKNOWN_ASN1_ELEMENT, msg_value=asn1_object,
function_name=func_name,
additional_msgs_list=[PhUtil.get_key_value_pair(PhKeys.ASN1_SCHEMA,
asn1_element.get_asn1_schema().get_name())]))
PhExceptionHelper(msg_key=Constants.UNKNOWN_ASN1_OBJECT, msg_value=asn1_object,
function_name=func_name))
else:
print_debug_var(Constants.ASN1_ELEMENT_MAPPING_IS_FAIL)
else:
Expand Down
4 changes: 4 additions & 0 deletions asn1_play/main/convert/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from python_helpers.ph_constants import PhConstants
from python_helpers.ph_constants_config import PhConfigConst
from python_helpers.ph_exception_helper import PhExceptionHelper
from python_helpers.ph_keys import PhKeys
from python_helpers.ph_modes_error_handling import PhErrorHandlingModes
from python_helpers.ph_util import PhUtil
Expand All @@ -15,6 +16,7 @@
from asn1_play.generated_code.asn1.TCA.eUICC_Profile_Package import version as epp_version
from asn1_play.main.convert import converter
from asn1_play.main.convert.handler import decode_encode_asn
from asn1_play.main.helper.constants import Constants
from asn1_play.main.helper.constants_config import ConfigConst as ConfigConst_local
from asn1_play.main.helper.formats_group import FormatsGroup
from asn1_play.main.helper.metadata import MetaData
Expand Down Expand Up @@ -84,6 +86,8 @@ def parse_or_update_any_data(data, meta_data=None):
# Binary File
with open(data.input_data, 'rb') as the_file:
resp = the_file.read()
if not resp:
raise ValueError(PhExceptionHelper(msg_key=Constants.INPUT_FILE_EMPTY))
file_ext = PhUtil.get_file_name_and_extn(file_path=data.input_data, only_extn=True)
if file_ext in FormatsGroup.INPUT_FILE_FORMATS_YML:
meta_data.input_mode_key = PhKeys.INPUT_YML
Expand Down
11 changes: 1 addition & 10 deletions asn1_play/main/data_type/data_type_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,6 @@ def to_dic(self, data):
:return:
"""
set_defaults(data, None)
asn1_data = {}
if data.asn1_element and isinstance(data.asn1_element, Asn1):
asn1_data.update({PhKeys.ASN1_SCHEMA: data.asn1_element.asn1_schema.get_name()})
asn1_object = data.asn1_element.get_asn1_object()
asn1_data.update({PhKeys.ASN1_OBJECT: asn1_object})
asn1_data.update({
PhKeys.ASN1_OBJECT_ALTERNATE: data.asn1_element.get_asn1_object_alternate() if (
not asn1_object or asn1_object is None) else None})
asn1_data.update({PhKeys.FETCH_ASN1_OBJECTS_LIST: data.asn1_element.fetch_asn1_objects_list})
common_data = {
PhKeys.INPUT_DATA: data.input_data,
PhKeys.REMARKS: data.get_remarks_as_str(),
Expand All @@ -252,4 +243,4 @@ def to_dic(self, data):
PhKeys.TLV_PARSING_OF_OUTPUT: data.tlv_parsing_of_output,
PhKeys.OUTPUT_FILE_NAME_KEYWORD: data.output_file_name_keyword,
}
return {**common_data, **asn1_data}
return {**common_data, **data.get_asn1_element_info()}
1 change: 1 addition & 0 deletions asn1_play/main/data_type/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,6 @@ def set_data_pool(self):
input_format=Formats.JSON,
output_format=Formats.ASN1,
),
#
]
super().set_data_pool(data_pool)
17 changes: 11 additions & 6 deletions asn1_play/main/helper/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@


class Constants:
# Verified
UNKNOWN_INPUT_DATA = 'Unknown Input Data'
UNKNOWN_INPUT_FORMAT = 'Unknown Input Format'
UNKNOWN_OUTPUT_FORMAT = 'Unknown Output Format'
UNKNOWN_ASN1_SCHEMA = 'Unknown Asn1 Schema'
UNKNOWN_ASN1_OBJECT = 'Unknown Asn1 Object'
#
INPUT_FILE_EMPTY = 'Input File Is empty.'
ASN1_OBJECT_IS_EMPTY_OR_MISSING = 'Asn1 Object is either empty or not provided.'
ASN1_SCHEMA_IS_EMPTY_OR_MISSING = 'Asn1 Schema is either empty or not provided.'
# Not Verified
INPUT_DATA_ASN1_FORMATION_ISSUE = 'input data is not a valid ASN'
UNKNOWN_INPUT_DATA = 'Unknown input data'
UNKNOWN_PARENT_OF_ASN1_OBJECT = 'asn1_element must be child of Asn1'
UNKNOWN_ASN1_ELEMENT = 'Unknown asn1 element'
ASN1_ELEMENT_MAPPING_IS_DONE = 'asn1_element mapping conversion is done'
ASN1_ELEMENT_MAPPING_IS_FAIL = 'asn1_element mapping conversion is fail'
INPUT_DATA_CONVERSION_NOT_POSSIBLE = 'input data conversion is not possible'
ASN1_ELEMENT_IS_EMPTY_OR_MISSING = 'asn1_element is either empty or not provided'
ASN1_OBJECT_IS_EMPTY_OR_MISSING = 'asn1_object is either empty or not provided'
INPUT_DATA_HEX_CONVERSION_IS_DONE = 'input data hex conversion is done'
INPUT_DATA_BASE_64_CONVERSION_IS_DONE = 'input data base64 conversion is done'
ASN1_ELEMENT_IS_NOT_NEEDED = 'asn1_element is not needed; Conversion can be performed'
INPUT_DATA_TRIMMING_IS_DONE = 'input data trimming is done'
UNKNOWN_OUTPUT_FORMAT = 'Unknown output format'
UNKNOWN_INPUT_FORMAT = 'Unknown input format'
INPUT_DATA_MISSING = 'Mandatory input data is missing.'
CONFIG_INPUT_MISSING = 'Mandatory Config "input" is missing.'
STR_CONVERSION_MODE = 'Conversion'
Expand Down
32 changes: 31 additions & 1 deletion asn1_play/main/helper/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def __init__(self,
self.data_group = kwargs.get(PhKeys.DATA_GROUP, None)
# Handle Internal args
self.__input_modes_hierarchy = []
self.__asn1_schema_name = None
self.__asn1_element_name = None
self.__asn1_element_name_alternate = None
self.__asn1_module_name = None
Expand Down Expand Up @@ -143,18 +144,22 @@ def set_one_time_remarks(self, one_time_remarks):

def set_asn1_element_name(self):
if not self.asn1_element or self.asn1_element is None:
self.__asn1_schema_name = None
self.__asn1_element_name = None
self.__asn1_element_name_alternate = None
self.__asn1_module_name = None
self.__asn1_module_version = None
return
if isinstance(self.asn1_element, Asn1):
self.__asn1_schema_name = self.asn1_element.get_asn1_schema().get_name()
self.__asn1_element_name = self.asn1_element.get_asn1_object()
self.__asn1_element_name_alternate = self.asn1_element.get_asn1_object_alternate()
self.__asn1_module_name = self.asn1_element.get_asn1_schema().get_asn1_class_name()
self.__asn1_module_version = self.asn1_element.get_asn1_schema().get_asn1_version()
return
# Below code is to support legacy functionality
# Where the direct code is being used with compile Time Versions
# Either Object is passed or Object Name is passed
if isinstance(self.asn1_element, str):
self.__asn1_element_name = self.asn1_element
else:
Expand All @@ -170,18 +175,43 @@ def set_asn1_element_name(self):
if self.__asn1_module_name == KeyWords.MODULE_EPP:
self.__asn1_module_version = epp_version

def get_asn1_element_info(self, verbose=False):
if not self.asn1_element:
return {}
asn1_schema = self.get_asn1_schema_name()
asn1_data_schema = {
PhKeys.ASN1_SCHEMA: asn1_schema,
}
asn1_data_module = {
PhKeys.ASN1_MODULE: self.get_asn1_module_name(),
PhKeys.ASN1_MODULE_VERSION: self.get_asn1_module_version(),
}
asn1_data = asn1_data_schema if asn1_schema and not verbose else asn1_data_module
# PhKeys.ASN1_OBJECT: self.asn1_element.get_asn1_object(),
asn1_data.update({PhKeys.ASN1_OBJECT: self.get_asn1_element_name()})
# PhKeys.ASN1_OBJECT_ALTERNATE: self.asn1_element.get_asn1_object_alternate(),
asn1_data.update({PhKeys.ASN1_OBJECT_ALTERNATE: self.get_asn1_element_name_alternate()})
if asn1_schema:
asn1_data.update({PhKeys.FETCH_ASN1_OBJECTS_LIST: self.asn1_element.fetch_asn1_objects_list})
return asn1_data

def get_asn1_element_name(self):
return self.__asn1_element_name

def get_asn1_element_name_alternate(self):
return self.__asn1_element_name_alternate

def set_asn1_element_name_alternate(self):
self.__asn1_element_name_alternate = self.__asn1_element_name.replace('-', '_')
temp = self.__asn1_element_name.replace('-', '_')
if temp != self.__asn1_element_name:
self.__asn1_element_name_alternate = temp

def get_asn1_element(self):
return self.asn1_element

def get_asn1_schema_name(self):
return self.__asn1_schema_name

def get_asn1_module_name(self):
return self.__asn1_module_name

Expand Down
1 change: 1 addition & 0 deletions asn1_play/main/helper/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Defaults:
"""
Unit Testing Sequences
sgp22_v3_1__epp_v3_3_1__sgp32_v1_1
sgp22_v2_4__epp_v3_2__sgp32_v1_0_1
sgp22_v3_0_0__epp_v3_1__sgp32_v1_0_1
sgp22_v3_0_0__epp_v3_2__sgp32_v1_1
Expand Down
Loading

0 comments on commit a987493

Please sign in to comment.