code: def _ScanEncryptedVolumeNode(self, scan_context, scan_node):
      
      if scan_node.type_indicator == definitions.TYPE_INDICATOR_APFS_CONTAINER:
        # TODO: consider changes this when upstream changes have been made.
        # Currently pyfsapfs does not support reading from a volume as a device.
        # Also see: https://github.com/log2timeline/dfvfs/issues/332
        container_file_entry = resolver.Resolver.OpenFileEntry(
            scan_node.path_spec, resolver_context=self._resolver_context)
        fsapfs_volume = container_file_entry.GetAPFSVolume()
  
        # TODO: unlocking the volume multiple times is inefficient cache volume
        # object in scan node and use is_locked = fsapfs_volume.is_locked()
        try:
          is_locked = not apfs_helper.APFSUnlockVolume(
              fsapfs_volume, scan_node.path_spec, resolver.Resolver.key_chain)
        except IOError as exception:
          raise errors.BackEndError(
              'Unable to unlock APFS volume with error: {0!s}'.format(exception))
  
      else:
        file_object = resolver.Resolver.OpenFileObject(
            scan_node.path_spec, resolver_context=self._resolver_context)
        is_locked = not file_object or file_object.is_locked
        file_object.close()
  
      if is_locked:
        scan_context.LockScanNode(scan_node.path_spec)
  
        # For BitLocker To Go add a scan node for the unencrypted part of
        # the volume.
        if scan_node.type_indicator == definitions.TYPE_INDICATOR_BDE:
          path_spec = self.ScanForFileSystem(scan_node.path_spec.parent)
          if path_spec:
            scan_context.AddScanNode(path_spec, scan_node.parent_node)
docs: Scans an encrypted volume node for supported formats.
  
      Args:
        scan_context (SourceScannerContext): source scanner context.
        scan_node (SourceScanNode): source scan node.
  
      Raises:
        BackEndError: if the scan node cannot be unlocked.
        ValueError: if the scan context or scan node is invalid.