Skip to content

Instantly share code, notes, and snippets.

@meew0
Created October 16, 2016 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meew0/daf2c57b0de3878ae85e8e38bc6b0282 to your computer and use it in GitHub Desktop.
Save meew0/daf2c57b0de3878ae85e8e38bc6b0282 to your computer and use it in GitHub Desktop.
Error in ./secure_random_test.cr:3: instantiating 'SecureRandom:Module#urlsafe_base64(Int32)'
puts SecureRandom.urlsafe_base64(18)
^~~~~~~~~~~~~~
in ./crystal-arm/src/secure_random.cr:46: instantiating 'random_bytes(Int32)'
Base64.urlsafe_encode(random_bytes(n), padding)
^~~~~~~~~~~~
in ./crystal-arm/src/secure_random.cr:72: instantiating 'init()'
init unless @@initialized
^~~~
in ./crystal-arm/src/secure_random.cr:93: expanding macro
{% if flag?(:linux) %}
^
in macro 'macro_94852657933712' /home/miras/Projects/crystal-arm/src/secure_random.cr:93, line 2:
1.
> 2. if getrandom(Slice(UInt8).new(16)) >= 0
3. @@getrandom_available = true
4. return
5. end
6.
instantiating 'getrandom(Slice(UInt8))'
in ./crystal-arm/src/secure_random.cr:107: expanding macro
{% if flag?(:linux) %}
^
in macro 'macro_94852649582704' /home/miras/Projects/crystal-arm/src/secure_random.cr:107, line 33:
1.
2. @@getrandom_available = false
3.
4. # Reads n random bytes using the Linux `getrandom(2)` syscall.
5. private def self.getrandom(n : Int)
6. Slice(UInt8).new(n).tap do |buf|
7. # getrandom(2) may only read up to 256 bytes at once without being
8. # interrupted or returning early
9. chunk_size = 256
10.
11. while buf.size > 0
12. if buf.size < chunk_size
13. chunk_size = buf.size
14. end
15.
16. read_bytes = getrandom(buf[0, chunk_size])
17. raise Errno.new("getrandom") if read_bytes == -1
18.
19. buf += read_bytes
20. end
21. end
22. end
23.
24. # Low-level wrapper for the `getrandom(2)` syscall, returns the number of
25. # bytes read or `-1` if an error occured (or the syscall isn't available)
26. # and sets `Errno.value`.
27. #
28. # We use the kernel syscall instead of the `getrandom` C function so any
29. # binary compiled for Linux will always use getrandom if the kernel is 3.17+
30. # and silently fallback to read from /dev/urandom if not (so it's more
31. # portable).
32. private def self.getrandom(buf : Slice(UInt8))
> 33. loop do
34. read_bytes = LibC.syscall(LibC::SYS_getrandom, buf, LibC::SizeT.new(buf.size), 0)
35. if read_bytes < 0 && (Errno.value == Errno::EINTR || Errno.value == Errno::EAGAIN)
36. Fiber.yield
37. else
38. return read_bytes
39. end
40. end
41. end
42.
instantiating 'loop()'
in ./crystal-arm/src/secure_random.cr:107: expanding macro
{% if flag?(:linux) %}
^
in macro 'macro_94852649582704' /home/miras/Projects/crystal-arm/src/secure_random.cr:107, line 33:
1.
2. @@getrandom_available = false
3.
4. # Reads n random bytes using the Linux `getrandom(2)` syscall.
5. private def self.getrandom(n : Int)
6. Slice(UInt8).new(n).tap do |buf|
7. # getrandom(2) may only read up to 256 bytes at once without being
8. # interrupted or returning early
9. chunk_size = 256
10.
11. while buf.size > 0
12. if buf.size < chunk_size
13. chunk_size = buf.size
14. end
15.
16. read_bytes = getrandom(buf[0, chunk_size])
17. raise Errno.new("getrandom") if read_bytes == -1
18.
19. buf += read_bytes
20. end
21. end
22. end
23.
24. # Low-level wrapper for the `getrandom(2)` syscall, returns the number of
25. # bytes read or `-1` if an error occured (or the syscall isn't available)
26. # and sets `Errno.value`.
27. #
28. # We use the kernel syscall instead of the `getrandom` C function so any
29. # binary compiled for Linux will always use getrandom if the kernel is 3.17+
30. # and silently fallback to read from /dev/urandom if not (so it's more
31. # portable).
32. private def self.getrandom(buf : Slice(UInt8))
> 33. loop do
34. read_bytes = LibC.syscall(LibC::SYS_getrandom, buf, LibC::SizeT.new(buf.size), 0)
35. if read_bytes < 0 && (Errno.value == Errno::EINTR || Errno.value == Errno::EAGAIN)
36. Fiber.yield
37. else
38. return read_bytes
39. end
40. end
41. end
42.
instantiating 'loop()'
in ./crystal-arm/src/secure_random.cr:107: expanding macro
{% if flag?(:linux) %}
^
in macro 'macro_94852649582704' /home/miras/Projects/crystal-arm/src/secure_random.cr:107, line 34:
1.
2. @@getrandom_available = false
3.
4. # Reads n random bytes using the Linux `getrandom(2)` syscall.
5. private def self.getrandom(n : Int)
6. Slice(UInt8).new(n).tap do |buf|
7. # getrandom(2) may only read up to 256 bytes at once without being
8. # interrupted or returning early
9. chunk_size = 256
10.
11. while buf.size > 0
12. if buf.size < chunk_size
13. chunk_size = buf.size
14. end
15.
16. read_bytes = getrandom(buf[0, chunk_size])
17. raise Errno.new("getrandom") if read_bytes == -1
18.
19. buf += read_bytes
20. end
21. end
22. end
23.
24. # Low-level wrapper for the `getrandom(2)` syscall, returns the number of
25. # bytes read or `-1` if an error occured (or the syscall isn't available)
26. # and sets `Errno.value`.
27. #
28. # We use the kernel syscall instead of the `getrandom` C function so any
29. # binary compiled for Linux will always use getrandom if the kernel is 3.17+
30. # and silently fallback to read from /dev/urandom if not (so it's more
31. # portable).
32. private def self.getrandom(buf : Slice(UInt8))
33. loop do
> 34. read_bytes = LibC.syscall(LibC::SYS_getrandom, buf, LibC::SizeT.new(buf.size), 0)
35. if read_bytes < 0 && (Errno.value == Errno::EINTR || Errno.value == Errno::EAGAIN)
36. Fiber.yield
37. else
38. return read_bytes
39. end
40. end
41. end
42.
undefined constant LibC::SYS_getrandom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment