简体   繁体   English

Ruby 1.9.3中的摘要:: MD5

[英]Digest::MD5 in Ruby 1.9.3

I'm running into something weird here. 我在这里碰到了一些奇怪的东西。 I have an "authenticator" that relies on ND5 to hash a certain string we match as password. 我有一个“身份验证器”依赖ND5来哈希我们匹配的某个字符串作为密码。 The problem when I run my tests is this: 我运行测试时的问题是:

NoMethodError: undefined method `md5' for #<CASServer::Authenticators::Billing:0x007fd8e6c906a0>
./models/authenticators/billing.rb:63:in `validate'
./routes/login.rb:166:in `block (2 levels) in <class:Server>'
./routes/login.rb:158:in `each'
./routes/login.rb:158:in `block in <class:Server>'
(eval):2:in `click_button'
./features/step_definitions/when_steps.rb:32:in `/^I enter "(.*)" as username and the generated username password and log in$/'
./features/rubycas.login.feature:14:in `When I enter "username" as username and the generated username password and log in'

So basically he does not recognize the MD5 as part of the Digest library. 所以基本上他不承认MD5是Digest库的一部分。 This problem occurs when running the tests in the IDE, as well as in the IRB console: 在IDE中以及在IRB控制台中运行测试时会发生此问题:

1.9.3-p125 :001 > require "digest/md5" and Digest::MD5("test")
NoMethodError: undefined method `MD5' for Digest:Module

However, when I run the following: 但是,当我运行以下内容时:

[root@DCUDEV01 /home/morn/rubycas/current]# ruby
require "digest/md5" and Digest::MD5("test")

I receive no errors, dumps or exceptions. 我没有收到任何错误,转储或异常。 Ruby just accepts it. Ruby只接受它。 What am I missing in order to get this MD5 stuff working? 为了让这个MD5工作起作用,我缺少什么?

Digest::MD5 is not a method but a module. 摘要:: MD5不是方法,而是模块。 Try 尝试

Digest::MD5.digest("test")

I found it confusing, it doesn't seem like .digest is correct. 我发现它令人困惑,它似乎不像.digest是正确的。 I can't say it is wrong either... 我不能说这也错了......

Commenter @reconbot got it right, IMO, but I saw the comment only after coming back to improve this QA, I think a comment isn't visible enough. 评论者@reconbot说得对,IMO,但是我回过头来改进这个质量保证后才看到评论,我认为评论不够明显。

http://ruby-doc.org/stdlib-2.4.0/libdoc/digest/rdoc/Digest/MD5.html http://ruby-doc.org/stdlib-2.4.0/libdoc/digest/rdoc/Digest/MD5.html

Below is an example usage for md5 hasing for gibbon usage, the mailchimp gem. 下面是md5使用长臂猿使用的示例用法,即mailchimp gem。

md5_hashed_email_address = Digest::MD5.hexdigest("john.doe@example.com")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM