<commit_before>"""
<Name>
  uptane/encoding/vehicle_manifest_asn1_coder.py

<Purpose>
  This module contains conversion functions (get_asn_signed and get_json_signed)
  for converting vehicle version manifests to and from Uptane's standard
  Python dictionary metadata format (usually serialized as JSON) and an ASN.1
  format that conforms to pyasn1 specifications and Uptane's ASN.1 definitions.

<Functions>
  get_asn_signed(pydict_signed)
  get_json_signed(asn_signed)    # TODO: Rename to get_pydict_signed in all mods

"""
from __future__ import print_function
from __future__ import unicode_literals

from pyasn1.type import univ, tag

from uptane.encoding.asn1_definitions import *

import uptane.encoding.ecu_manifest_asn1_coder as ecu_manifest_asn1_coder


def get_asn_signed(json_signed):
  signed = VehicleVersionManifestSigned()\
           .subtype(implicitTag=tag.Tag(tag.tagClassContext,
                                        tag.tagFormatConstructed, 0))

  signed['vehicleIdentifier'] = json_signed['vin']
  signed['primaryIdentifier'] = json_signed['primary_ecu_serial']

  ecuVersionManifests = ECUVersionManifests()\
                        .subtype(implicitTag=tag.Tag(tag.tagClassContext,
                                                     tag.tagFormatSimple, 3))
  numberOfECUVersionManifests = 0

  for ecu_serial in json_signed['ecu_version_manifests']:
    for manifest in json_signed['ecu_version_manifests'][ecu_serial]:
      temp_ecu_manifest = ECUVersionManifest()
      json_signed = manifest['signed']
      json_signatures = manifest['signatures']
      # This is the 'signed' element of the ECU Manifest,<commit_msg>DER: Make ECU Manifest order in ASN.1 Vehicle Manifests deterministic<commit_after>"""
<Name>
  uptane/encoding/vehicle_manifest_asn1_coder.py

<Purpose>
  This module contains conversion functions (get_asn_signed and get_json_signed)
  for converting vehicle version manifests to and from Uptane's standard
  Python dictionary metadata format (usually serialized as JSON) and an ASN.1
  format that conforms to pyasn1 specifications and Uptane's ASN.1 definitions.

<Functions>
  get_asn_signed(pydict_signed)
  get_json_signed(asn_signed)    # TODO: Rename to get_pydict_signed in all mods

"""
from __future__ import print_function
from __future__ import unicode_literals

from pyasn1.type import univ, tag

from uptane.encoding.asn1_definitions import *

import uptane.encoding.ecu_manifest_asn1_coder as ecu_manifest_asn1_coder


def get_asn_signed(json_signed):
  signed = VehicleVersionManifestSigned()\
           .subtype(implicitTag=tag.Tag(tag.tagClassContext,
                                        tag.tagFormatConstructed, 0))

  signed['vehicleIdentifier'] = json_signed['vin']
  signed['primaryIdentifier'] = json_signed['primary_ecu_serial']

  ecuVersionManifests = ECUVersionManifests()\
                        .subtype(implicitTag=tag.Tag(tag.tagClassContext,
                                                     tag.tagFormatSimple, 3))
  numberOfECUVersionManifests = 0

  # We're going to generate a list of ECU Manifests from the dictionary of lists
  # of ECU Manifests.
  # The DER will contain this list, and the order of items in this list will
  # affect hashing of the DER, and therefore signature verification.
  # We have to make the order deterministic.
  sorted_ecu_serials = sorted(json_signed['ecu_version_manifests'])
  for ecu_serial in sorted_ecu_serials:
    for manifest in json_signed['ecu_version_manifests'][ecu_serial]:
      temp_ecu_manifest = ECUVersionManifest()
      json_signed = manifest['signed']
      json_signatures = manifest['signatures']
      # This is the 'signed' element of the ECU Manifest,
{'fraction_non_alphanumeric': 0.06946688206785137, 'fraction_numerical': 0.006192784060312331, 'mean_word_length': 3.849869451697128, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1361931', 'n_tokens_mistral': 1153, 'n_tokens_neox': 1099, 'n_words': 286}