1
mirror of https://github.com/rapid7/metasploit-framework synced 2024-11-05 14:57:30 +01:00

New exceptions

git-svn-id: file:///home/svn/incoming/trunk@2593 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
Spoon M 2005-06-08 21:39:12 +00:00
parent f699fd0a23
commit af49f81f62
7 changed files with 48 additions and 17 deletions

View File

@ -11,9 +11,11 @@ require 'Rex/Encoding/Xor/Generic.rb.ut'
# Byte and Generic tests, oh well for now...
#
class Rex::Encoding::Xor::Byte::UnitTest < Rex::Encoding::Xor::Generic::UnitTest
module Rex::Encoding::Xor
class Byte::UnitTest < Generic::UnitTest
def enc
Rex::Encoding::Xor::Byte
Byte
end
end
end

View File

@ -5,9 +5,11 @@ $:.unshift(File.join('..', '..', '..', File.dirname(__FILE__)))
require 'Rex/Encoding/Xor/DWord'
require 'Rex/Encoding/Xor/Byte.rb.ut'
class Rex::Encoding::Xor::DWord::UnitTest < Rex::Encoding::Xor::Byte::UnitTest
module Rex::Encoding::Xor
class DWord::UnitTest < Byte::UnitTest
def enc
Rex::Encoding::Xor::DWord
DWord
end
end
end

View File

@ -1,5 +1,6 @@
#!/usr/bin/ruby
require 'Rex/Encoding/Xor/Exceptions'
require 'Rex/Encoding/Xor/Generic'
#
@ -80,7 +81,7 @@ class DWordAdditive < Generic
# fuck, we wrapped around!
if key[strip] == kstart[strip]
raise ArgumentError, "FIXME DIFF EXCEPTION", caller
raise KeySearchError, "Key space exhausted on strip #{strip}!", caller
end
end

View File

@ -5,9 +5,11 @@ $:.unshift(File.join('..', '..', '..', File.dirname(__FILE__)))
require 'Rex/Encoding/Xor/DWordAdditive'
require 'Rex/Encoding/Xor/Byte.rb.ut'
class Rex::Encoding::Xor::DWordAdditive::UnitTest < Rex::Encoding::Xor::Byte::UnitTest
module Rex::Encoding::Xor
class DWordAdditive::UnitTest < Byte::UnitTest
def enc
Rex::Encoding::Xor::DWordAdditive
DWordAdditive
end
end
end

View File

@ -0,0 +1,19 @@
#!/usr/bin/ruby
module Rex
module Encoding
module Xor
module Exception
MSG = "Hoe's be frontin n shit"
def to_s
self.class::MSG
end
end
class KeySearchError < ::Exception
include Exception
MSG = "Error finding a key."
end
end end end

View File

@ -1,5 +1,7 @@
#!/usr/bin/ruby
require 'Rex/Encoding/Xor/Exceptions'
module Rex
module Encoding
module Xor
@ -93,7 +95,7 @@ class Generic
kbyte = (kbyte + 1) & 0xff
}
raise ArgumentError, "FIXME DIFF EXCEPTION", caller
raise KeySearchError, "Exhausted byte space for strip #{strip}!", caller
end
key << kbyte
@ -102,7 +104,7 @@ class Generic
# ok, we should have a good key now, lets double check...
if ! _check(data, key, badchars)
raise ArgumentError, "FIXME DIFF EXCEPTION", caller
raise KeySearchError, "Key found, but bad character check failed!", caller
end
return key
@ -111,17 +113,17 @@ class Generic
def Generic.encode(buf, key)
if !key.kind_of?(String)
raise ArgumentError, "Key must be a string!", caller
raise ::ArgumentError, "Key must be a string!", caller
end
len = key.length
if len == 0
raise ArgumentError, "Zero key length!", caller
raise ::ArgumentError, "Zero key length!", caller
end
if keysize != 0 && keysize != len
raise ArgumentError, "Key length #{len}, expected #{keysize}", caller
raise ::ArgumentError, "Key length #{len}, expected #{keysize}", caller
end
encoded = ""

View File

@ -5,15 +5,17 @@ $:.unshift(File.join('..', '..', '..', File.dirname(__FILE__)))
require 'test/unit'
require 'Rex/Encoding/Xor/Generic'
class Rex::Encoding::Xor::Generic::UnitTest < Test::Unit::TestCase
module Rex::Encoding::Xor
class Generic::UnitTest < ::Test::Unit::TestCase
def enc
Rex::Encoding::Xor::Generic
Generic
end
def hook_static_encode(data, key, expected)
if enc.keysize != 0 && key.length != enc.keysize
assert_raise(Rex::ArgumentError) { enc.encode(data,key) }
assert_raise(::ArgumentError) { enc.encode(data,key) }
else
assert_equal(enc.encode(data, key), expected)
end
@ -21,10 +23,10 @@ class Rex::Encoding::Xor::Generic::UnitTest < Test::Unit::TestCase
def test_static_encode
# Test key of zero length
assert_raise(Rex::ArgumentError) { enc.encode("\x00", "") }
assert_raise(::ArgumentError) { enc.encode("\x00", "") }
# Test non-string key
assert_raise(Rex::ArgumentError) { enc.encode("\x00\x01", 1) }
assert_raise(::ArgumentError) { enc.encode("\x00\x01", 1) }
# some simple single byte tests with 0x00
30.times {
@ -115,3 +117,4 @@ class Rex::Encoding::Xor::Generic::UnitTest < Test::Unit::TestCase
]
end
end
end