summaryrefslogtreecommitdiff
path: root/lib/securerandom.rb
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-10 00:35:43 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-10 00:35:43 +0000
commit778bbac8ac2ae50f0987c4888f7158296ee5bbdd (patch)
tree8c930da6175825647fc2640a0ae0277a723333c6 /lib/securerandom.rb
parent4b346b0e7159d95ed0afce0840adaf62d7c1381f (diff)
stdlib: avoid extra calls to eliminate "\n" from Base64
We may use the '0' (zero) to avoid adding the line feed. Furthermore, the '*' (asterisk) modifier is not needed for a single-element arrays. * ext/psych/lib/psych/visitors/yaml_tree.rb (visit_String): eliminate chomp * lib/net/http.rb (connect): eliminate delete * lib/net/http/header.rb (basic_encode): ditto * lib/net/imap.rb (authenticate): eliminate gsub (self.encode_utf7): shorten delete arg * lib/net/smtp.rb (base64_encode): eliminate gsub * lib/open-uri.rb (OpenURI.open_http): eliminate delete * lib/rss/rss.rb: ditto * lib/securerandom.rb (base64): ditto (urlsafe_base64): eliminate delete! * lib/webrick/httpauth/digestauth.rb (split_param_value): eliminate chop * lib/webrick/httpproxy.rb (do_CONNECT): eliminate delete (setup_upstream_proxy_authentication): ditto [ruby-core:72666] [Feature #11938] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53488 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/securerandom.rb')
-rw-r--r--lib/securerandom.rb5
1 files changed, 2 insertions, 3 deletions
diff --git a/lib/securerandom.rb b/lib/securerandom.rb
index b08b62b746..198f273c88 100644
--- a/lib/securerandom.rb
+++ b/lib/securerandom.rb
@@ -136,7 +136,7 @@ module Random::Formatter
#
# See RFC 3548 for the definition of base64.
def base64(n=nil)
- [random_bytes(n)].pack("m*").delete("\n")
+ [random_bytes(n)].pack("m0")
end
# SecureRandom.urlsafe_base64 generates a random URL-safe base64 string.
@@ -166,8 +166,7 @@ module Random::Formatter
#
# See RFC 3548 for the definition of URL-safe base64.
def urlsafe_base64(n=nil, padding=false)
- s = [random_bytes(n)].pack("m*")
- s.delete!("\n")
+ s = [random_bytes(n)].pack("m0")
s.tr!("+/", "-_")
s.delete!("=") unless padding
s