code: def Unlock(
        self, scan_context, path_spec, credential_identifier, credential_data):
      
      if not scan_context.HasScanNode(path_spec):
        raise KeyError('Scan node does not exist.')
  
      if not scan_context.IsLockedScanNode(path_spec):
        raise KeyError('Scan node is not locked.')
  
      resolver.Resolver.key_chain.SetCredential(
          path_spec, credential_identifier, credential_data)
  
      if path_spec.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(
            path_spec, resolver_context=self._resolver_context)
        fsapfs_volume = container_file_entry.GetAPFSVolume()
  
        try:
          is_locked = not apfs_helper.APFSUnlockVolume(
              fsapfs_volume, 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(
            path_spec, resolver_context=self._resolver_context)
        is_locked = not file_object or file_object.is_locked
        file_object.close()
  
      if not is_locked:
        scan_context.UnlockScanNode(path_spec)
  
      return not is_locked
docs: Unlocks a locked scan node e.g. the scan node of an encrypted volume.
  
      Args:
        scan_context (SourceScannerContext): source scanner context.
        path_spec (PathSpec): path specification of the locked scan node.
        credential_identifier (str): credential identifier used to unlock
            the scan node.
        credential_data (bytes): credential data used to unlock the scan node.
  
      Returns:
        bool: True if the scan node was successfully unlocked.
  
      Raises:
        BackEndError: if the scan node cannot be unlocked.
        KeyError: if the scan node does not exists or is not locked.