lib/arachni/support/signature.rb in arachni-1.4 vs lib/arachni/support/signature.rb in arachni-1.5
- old
+ new
@@ -1,7 +1,7 @@
=begin
- Copyright 2010-2016 Tasos Laskos <tasos.laskos@arachni-scanner.com>
+ Copyright 2010-2017 Sarosys LLC <http://www.sarosys.com>
This file is part of the Arachni Framework project and is subject to
redistribution and commercial restrictions. Please see the Arachni Framework
web site for more information on licensing and terms of use.
=end
@@ -43,14 +43,21 @@
# Data to use to refine the signature.
#
# @return [Signature]
# `self`
def refine!( data )
+ @hash_cache = nil
@tokens &= tokenize( data )
self
end
+ def <<( data )
+ @hash_cache = nil
+ @tokens.merge tokenize( data )
+ self
+ end
+
# @note The string will be tokenized based on whitespace.
#
# @param [String, Signature] data
# Data to use to refine the signature.
#
@@ -80,29 +87,34 @@
def similar?( other, threshold = @options[:threshold] )
fail 'No threshold given.' if !threshold
self == other || differences( other ) < threshold
end
+ def empty?
+ @tokens.empty?
+ end
+
# @return [Signature]
# Copy of `self`.
def dup
- self.class.new( '' ).tap { |s| s.copy( tokens, @options ) }
+ self.class.new( '' ).tap { |s| s.copy( @hash_cache, tokens, @options ) }
end
def hash
- tokens.hash
+ @hash_cache ||= tokens.hash
end
# @param [Signature] other
def ==( other )
hash == other.hash
end
protected
- def copy( tokens, options )
- @tokens = tokens.dup
- @options = options.dup
+ def copy( hash, tokens, options )
+ @hash_cache = hash
+ @tokens = tokens.dup
+ @options = options.dup
end
private
# @param [Signature, String] data