def _PromptUserForEncryptedVolumeCredential(
      self, scan_context, locked_scan_node, output_writer):
    """Prompts the user to provide a credential for an encrypted volume.

    Args:
      scan_context: the source scanner context (instance of
                    SourceScannerContext).
      locked_scan_node: the locked scan node (instance of SourceScanNode).
      output_writer: the output writer (instance of StdoutWriter).
    """
    credentials = credentials_manager.CredentialsManager.GetCredentials(
        locked_scan_node.path_spec)

    # TODO: print volume description.
    if locked_scan_node.type_indicator == definitions.TYPE_INDICATOR_BDE:
      output_writer.WriteLine(u'Found a BitLocker encrypted volume.')
    else:
      output_writer.WriteLine(u'Found an encrypted volume.')

    credentials_list = list(credentials.CREDENTIALS)
    credentials_list.append(u'skip')

    # TODO: check which credentials are available.
    output_writer.WriteLine(u'Supported credentials:')
    output_writer.WriteLine(u'')
    for index, name in enumerate(credentials_list):
      output_writer.WriteLine(u'  {0:d}. {1:s}'.format(index, name))
    output_writer.WriteLine(u'')

    result = False
    while not result:
      output_writer.WriteString(
          u'Select a credential to unlock the volume: ')
      # TODO: add an input reader.
      input_line = sys.stdin.readline()
      input_line = input_line.strip()

      if input_line in credentials_list:
        credential_identifier = input_line
      else:
        try:
          credential_identifier = int(input_line, 10)
          credential_identifier = credentials_list[credential_identifier]
        except (IndexError, ValueError):
          output_writer.WriteLine(
              u'Unsupported credential: {0:s}'.format(input_line))
          continue

      if credential_identifier == u'skip':
        break

      getpass_string = u'Enter credential data: '
      if sys.platform.startswith(u'win') and sys.version_info[0] < 3:
        # For Python 2 on Windows getpass (win_getpass) requires an encoded
        # byte string. For Python 3 we need it to be a Unicode string.
        getpass_string = self._EncodeString(getpass_string)

      credential_data = getpass.getpass(getpass_string)
      output_writer.WriteLine(u'')

      result = self._source_scanner.Unlock(
          scan_context, locked_scan_node.path_spec, credential_identifier,
          credential_data)

      if not result:
        output_writer.WriteLine(u'Unable to unlock volume.')
        output_writer.WriteLine(u'')
dataset/ETHPy150Open log2timeline/dfvfs/examples/source_analyzer.py/SourceAnalyzer._PromptUserForEncryptedVolumeCredential/original