module EICAR
Constants
Public Class Methods
antivirus_active?()
click to toggle source
Tests if antivirus is active as far as the EICAR
test file is concerned. @return [Boolean]
# File lib/eicar.rb, line 58 def self.antivirus_active? begin self.test_string rescue EICAR::EICARReadError return true end return false end
create(path=self.test_file_path)
click to toggle source
Creates the EICAR
test file in a given path. If successful, returns the path written to. Without an argument, it attempts to write to the expected EICAR.test_file_path
For system-wide gem installs, this will usually need to be run as root, or else you'll raise.
@param path [String] the path to write to @return [String] the full, non-relative path written to
# File lib/eicar.rb, line 83 def self.create(path=self.test_file_path) write_data = self.rot13(ROT13_DOWNCASE_EICAR).upcase expanded_path = File.expand_path(path) begin File.open(expanded_path, "wb") {|f| f.write write_data} rescue SystemCallError raise EICAR::EICARWriteError end begin if File.readable? expanded_path read_data = File.open(expanded_path, "rb") {|f| f.read f.stat.size} end rescue SystemCallError raise EICAR::EICARReadError end if read_data == write_data return File.path(expanded_path) else raise EICAR::Error end end
rot13(str)
click to toggle source
Creates a ROT13 encoded string. @param str [String] the string to encode @return [String] the encoded string
# File lib/eicar.rb, line 71 def self.rot13(str) str.tr "A-Za-z", "N-ZA-Mn-za-m" end
test_file_path()
click to toggle source
The default path for the EICAR
test file. Usually, it will be in the bin path of your GEM_HOME @return [String] the full path of the EICAR
test file
# File lib/eicar.rb, line 37 def self.test_file_path lib_path = File.expand_path(File.dirname(__FILE__)) bin_path = File.expand_path(File.join(lib_path, "..", "bin")) File.join(bin_path, "eicar.com") end
test_string()
click to toggle source
version()
click to toggle source
@return [String] The library/gem version.
# File lib/eicar.rb, line 14 def self.version EICAR::VERSION end