Skip to content

Commit afe5bb5

Browse files
author
Tod Beardsley
committed
Get rid of the fall through methods
1 parent 34ece37 commit afe5bb5

File tree

1 file changed

+8
-30
lines changed

1 file changed

+8
-30
lines changed

lib/rex/text.rb

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ module Text
4545

4646
DefaultPatternSets = [ Rex::Text::UpperAlpha, Rex::Text::LowerAlpha, Rex::Text::Numerals ]
4747

48-
# In case Iconv isn't loaded
48+
# The Iconv translation table. The Iconv gem is deprecated in favor of
49+
# String#encode, yet there is no encoding for EBCDIC. See #4525
4950
Iconv_EBCDIC = [
5051
"\x00", "\x01", "\x02", "\x03", "7", "-", ".", "/", "\x16", "\x05",
5152
"%", "\v", "\f", "\r", "\x0E", "\x0F", "\x10", "\x11", "\x12", "\x13",
@@ -386,9 +387,9 @@ def self.to_utf8(str)
386387
#
387388
class IllegalSequence < ArgumentError; end
388389

389-
# A native implementation of the ASCII->EBCDIC table, used to fall back from using
390-
# Iconv
391-
def self.to_ebcdic_rex(str)
390+
# A native implementation of the EBCDIC->ASCII table, since it's not available
391+
# in String#encode
392+
def self.to_ebcdic(str)
392393
new_str = []
393394
str.each_byte do |x|
394395
if Iconv_ASCII.index(x.chr)
@@ -400,9 +401,9 @@ def self.to_ebcdic_rex(str)
400401
new_str.join
401402
end
402403

403-
# A native implementation of the EBCDIC->ASCII table, used to fall back from using
404-
# Iconv
405-
def self.from_ebcdic_rex(str)
404+
# A native implementation of the EBCDIC->ASCII table, since it's not available
405+
# in String#encode
406+
def self.from_ebcdic(str)
406407
new_str = []
407408
str.each_byte do |x|
408409
if Iconv_EBCDIC.index(x.chr)
@@ -414,29 +415,6 @@ def self.from_ebcdic_rex(str)
414415
new_str.join
415416
end
416417

417-
def self.to_ebcdic(str)
418-
begin
419-
Iconv.iconv("EBCDIC-US", "ASCII", str).first
420-
rescue ::Iconv::IllegalSequence => e
421-
raise e
422-
rescue
423-
self.to_ebcdic_rex(str)
424-
end
425-
end
426-
427-
#
428-
# Converts EBCIDC to ASCII
429-
#
430-
def self.from_ebcdic(str)
431-
begin
432-
Iconv.iconv("ASCII", "EBCDIC-US", str).first
433-
rescue ::Iconv::IllegalSequence => e
434-
raise e
435-
rescue
436-
self.from_ebcdic_rex(str)
437-
end
438-
end
439-
440418
#
441419
# Returns the words in +str+ as an Array.
442420
#

0 commit comments

Comments
 (0)