Skip to content

fix compiler warning in elixir 1.20#101

Open
slashmili wants to merge 1 commit intovoltone:masterfrom
slashmili:fix-warning-1.20
Open

fix compiler warning in elixir 1.20#101
slashmili wants to merge 1 commit intovoltone:masterfrom
slashmili:fix-warning-1.20

Conversation

@slashmili
Copy link
Copy Markdown

@slashmili slashmili commented Mar 29, 2026

Fixes compiler warning in the upcoming elixir:

elixir --version
Erlang/OTP 28 [erts-16.3] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1]

Elixir 1.20.0-rc.3 (2db87eb) (compiled with Erlang/OTP 28)

mix test
     warning: the variable "size" is accessed inside size(...) of a bitstring but it was defined outside of the match. You must precede it with the pin operator
     \x{2502}
 371 \x{2502}     <<i::unsigned-size(size)-unit(8)>> = :crypto.strong_rand_bytes(size)
     \x{2502}                        ~
     \x{2502}
     \x{2514}\x{2500} lib/x509/certificate.ex:371:24: X509.Certificate.random_serial/1

Copy link
Copy Markdown
Owner

@voltone voltone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Small change request to not break compatibility with older Elixir versions

Comment thread lib/x509/certificate.ex
# Returns a random serial number as an integer
def random_serial(size) do
<<i::unsigned-size(size)-unit(8)>> = :crypto.strong_rand_bytes(size)
<<i::unsigned-size(^size)-unit(8)>> = :crypto.strong_rand_bytes(size)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the use of the pin operator recommended in Elixir 1.20 is not supported by Elixir <=1.14. We can sidestep the issue altogether by using :binary.decode_unsigned/1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants