summaryrefslogtreecommitdiff
path: root/lib/base64.rb
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-04-20 06:20:35 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-04-20 06:20:35 +0000
commit4dd5679cbbac110f741a16ad7ca49e985f9fae82 (patch)
tree3e1e182d71267d83d37a5d3cb2dd924997a956c3 /lib/base64.rb
parent5a1e96b22aa6759bde56ff9667759b44e9f6fa28 (diff)
1.1b9_12
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@176 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/base64.rb')
-rw-r--r--lib/base64.rb19
1 files changed, 2 insertions, 17 deletions
diff --git a/lib/base64.rb b/lib/base64.rb
index 8b75ddaa9e..d7461d82e7 100644
--- a/lib/base64.rb
+++ b/lib/base64.rb
@@ -1,15 +1,7 @@
require "kconv"
def decode64(str)
- string = ''
- for line in str.split("\n")
- line.delete!('^A-Za-z0-9+/') # remove non-base64 chars
- line.tr!('A-Za-z0-9+/', ' -_') # convert to uuencoded format
- len = ["#{32 + line.length * 3 / 4}"].pack("c")
- # compute length byte
- string += "#{len}#{line}".unpack("u") # uudecode and concatenate
- end
- return string
+ str.unpack("m")[0]
end
def decode_b(str)
@@ -27,14 +19,7 @@ def decode_b(str)
end
def encode64(bin)
- encode = ""
- pad = 0
- [bin].pack("u").each do |uu|
- len = (2 + (uu[0] - 32)* 4) / 3
- encode << uu[1, len].tr('` -_', 'AA-Za-z0-9+/')
- pad += uu.length - 2 - len
- end
- encode + "=" * (pad % 3)
+ [bin].pack("m")
end
def b64encode(bin, len = 60)