diff --git a/lib/net/smtp/auth_cram_md5.rb b/lib/net/smtp/auth_cram_md5.rb deleted file mode 100644 index 0490cd6..0000000 --- a/lib/net/smtp/auth_cram_md5.rb +++ /dev/null @@ -1,48 +0,0 @@ -unless defined? OpenSSL - begin - require 'digest/md5' - rescue LoadError - end -end - -class Net::SMTP - class AuthCramMD5 < Net::SMTP::Authenticator - auth_type :cram_md5 - - def auth(user, secret) - challenge = continue('AUTH CRAM-MD5') - crammed = cram_md5_response(secret, challenge.unpack1('m')) - finish(base64_encode("#{user} #{crammed}")) - end - - IMASK = 0x36 - OMASK = 0x5c - - # CRAM-MD5: [RFC2195] - def cram_md5_response(secret, challenge) - tmp = digest_class::MD5.digest(cram_secret(secret, IMASK) + challenge) - digest_class::MD5.hexdigest(cram_secret(secret, OMASK) + tmp) - end - - CRAM_BUFSIZE = 64 - - def cram_secret(secret, mask) - secret = digest_class::MD5.digest(secret) if secret.size > CRAM_BUFSIZE - buf = secret.ljust(CRAM_BUFSIZE, "\0") - 0.upto(buf.size - 1) do |i| - buf[i] = (buf[i].ord ^ mask).chr - end - buf - end - - def digest_class - @digest_class ||= if defined?(OpenSSL::Digest) - OpenSSL::Digest - elsif defined?(::Digest) - ::Digest - else - raise '"openssl" or "digest" library is required' - end - end - end -end diff --git a/lib/net/smtp/auth_login.rb b/lib/net/smtp/auth_login.rb deleted file mode 100644 index 545c1f9..0000000 --- a/lib/net/smtp/auth_login.rb +++ /dev/null @@ -1,11 +0,0 @@ -class Net::SMTP - class AuthLogin < Net::SMTP::Authenticator - auth_type :login - - def auth(user, secret) - continue('AUTH LOGIN') - continue(base64_encode(user)) - finish(base64_encode(secret)) - end - end -end diff --git a/lib/net/smtp/auth_plain.rb b/lib/net/smtp/auth_plain.rb deleted file mode 100644 index 7fa1198..0000000 --- a/lib/net/smtp/auth_plain.rb +++ /dev/null @@ -1,9 +0,0 @@ -class Net::SMTP - class AuthPlain < Net::SMTP::Authenticator - auth_type :plain - - def auth(user, secret) - finish('AUTH PLAIN ' + base64_encode("\0#{user}\0#{secret}")) - end - end -end diff --git a/test/net/smtp/test_smtp.rb b/test/net/smtp/test_smtp.rb index f7a38b8..d2fd19a 100644 --- a/test/net/smtp/test_smtp.rb +++ b/test/net/smtp/test_smtp.rb @@ -530,16 +530,6 @@ def test_start_auth_cram_md5 assert_raise Net::SMTPAuthenticationError do Net::SMTP.start('localhost', port, user: 'account', password: 'password', authtype: :cram_md5){} end - - port = fake_server_start(auth: 'CRAM-MD5') - smtp = Net::SMTP.new('localhost', port) - auth_cram_md5 = Net::SMTP::AuthCramMD5.new(smtp) - auth_cram_md5.define_singleton_method(:digest_class) { raise '"openssl" or "digest" library is required' } - Net::SMTP::AuthCramMD5.define_singleton_method(:new) { |_| auth_cram_md5 } - e = assert_raise RuntimeError do - smtp.start(user: 'account', password: 'password', authtype: :cram_md5){} - end - assert_equal('"openssl" or "digest" library is required', e.message) end def test_start_instance