def _fix_new_line_key_format(private_key_string):
  """Format a private key string with new lines.

  Args:
    private_key_string: A private key as a string without newlines.

  Returns:
    The same private key string with new lines inserted as necessary. If the
    format of the input string is not as expected, the original string is
    returned, unaltered instead.
  """
  newline = '\n'
  private_key_dash = ' PRIVATE KEY-----'
  end_key_dash = '-----END'
  every = 64
  beginning_index = private_key_string.find(private_key_dash)
  ending_index = private_key_string.find(end_key_dash)
  if beginning_index == -1 or ending_index == -1:
    # The format was not as expected, so just return the default string.
    return private_key_string

  total_beginning_index = beginning_index + len(private_key_dash)
  beginning_portion = private_key_string[0:total_beginning_index]
  ending_portion = private_key_string[ending_index:]
  actual_key = private_key_string[total_beginning_index:ending_index]

  lines = [beginning_portion]
  for i in range(0, len(actual_key), every):
    lines.append(actual_key[i:i+every])
  lines.append(ending_portion)
  return newline.join(lines)