Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: use Crystal::System::Random in Crystal::Hasher #6184

Merged

Conversation

ysbaddaden
Copy link
Contributor

@ysbaddaden ysbaddaden commented Jun 12, 2018

Using Random::Secure in prelude.cr causes some load order issues when the crystal-random shard is required, and this prevents a program compilation (e.g. the crystal-random specs). The exact issue is unknown. Maybe it's related to adding more implementations of the Random module, required by Random::Secure, and creating a kind of loop between Hash -> Crystal::Hasher -> Random::Secure <-> Random that the compiler can't satisfy.

Using Crystal::System::Random directly instead of Random::Secure (which merely delegates to Crystal::System::Random) fixes the compilation issue. I'm not fond of that solution (or hack), but it works.

Using `Random::Secure` in `prelude.cr` causes some load order issues
when the crystal-random shard is required, and this prevents a
program compilation (e.g. the crystal-random specs).

The exact issue is unknown, but using `Crystal::System::Random`
directly instead of `Random::Secure` (which merely delegates to
`Crystal::System::Random`) fixes the compilation issue.
@RX14
Copy link
Contributor

RX14 commented Jun 12, 2018

Can you paste the error you got with the load order?

@straight-shoota
Copy link
Member

Perhaps add a comment about using Crystal::System::Random in the code? Could be a FIXME.

@ysbaddaden
Copy link
Contributor Author

@RX14 : just clone crystal-random, fix the require "secure_random" statements, then:

$ crystal spec --verbose
Error in line 1: while requiring "prelude"
in /usr/share/crystal/src/prelude.cr:41: while requiring "hash"
require "hash"
^
in /usr/share/crystal/src/hash.cr:1: while requiring "crystal/hasher"
require "crystal/hasher"
^
in /usr/share/crystal/src/crystal/hasher.cr:85: undefined constant Random::Secure
  Random::Secure.random_bytes(Slice.new(pointerof(@@seed).as(UInt8*), sizeof(typeof(@@seed))))
  ^~~~~~~~~~~~~~

@straight-shoota we're inside the private Crystal namespace, so it's allowed to use Crystal::System.

@ysbaddaden
Copy link
Contributor Author

Also, a git blame would better answer the question of using Crystal::System::Random rather than Random::Secure.

@straight-shoota
Copy link
Member

straight-shoota commented Jun 12, 2018

we're inside the private Crystal namespace

Ah, I missed that, sorry. It's fine then.

@RX14 RX14 added this to the 0.25.1 milestone Jun 13, 2018
@RX14 RX14 merged commit ebef46b into crystal-lang:master Jun 13, 2018
@ysbaddaden ysbaddaden deleted the fix-dont-use-random-secure-in-prelude branch June 13, 2018 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants