Refactored ID filter checks into #is_valid_id?.

Added call to #remove_rule! as well.
This commit is contained in:
soh_cah_toa
2014-04-24 23:28:11 -04:00
parent bca9eccdf0
commit 32db367ada

View File

@@ -63,11 +63,7 @@ module BeEF
# @return [Hash] hash representation of rule (empty hash if rule wasn't found)
def get_rule(id)
@lock.synchronize do
if BeEF::Filters.hexs_only?(id) &&
!BeEF::Filters.has_null?(id) &&
!BeEF::Filters.has_non_printable_char?(id) &&
id.length == 8
if is_valid_id?(id)
rule = @database.get(id)
rule.nil? ? {} : to_hash(rule)
end
@@ -81,8 +77,10 @@ module BeEF
# @return [Boolean] true if rule was removed, otherwise false
def remove_rule!(id)
@lock.synchronize do
rule = @database.get(id)
rule.nil? ? false : rule.destroy
if is_valid_id?(id)
rule = @database.get(id)
rule.nil? ? false : rule.destroy
end
end
end
@@ -160,6 +158,18 @@ module BeEF
hash
end
# Verifies that the given ID is valid.
#
# @param id [String] identifier to validate
#
# @return [Boolean] true if ID is valid, otherwise false
def is_valid_id?(id)
BeEF::Filters.hexs_only?(id) &&
!BeEF::Filters.has_null?(id) &&
!BeEF::Filters.has_non_printable_char?(id) &&
id.length == 8
end
# Helper method that formats the given resource class in a human-readable format.
#
# @param resource [Resolv::DNS::Resource::IN] resource class