Skip to content

Commit 1067532

Browse files
fix(stdlib): retain SSL key state creation
Haxe dead-code elimination could remove the key-state helper because its only calls were hidden inside raw Elixir text. Full-DCE runtime tests then generated calls to a function that no longer existed. Return the decoded OTP key term from the target boundary and call the helper through typed Haxe code. This keeps the helper visible to DCE without a keep annotation or generated-code repair. Verified both focused SSL snapshots, the Digest runtime, Haxe formatting, generated formatting, path hygiene, and generated create/1 output. The loaded host exceeded the bounded full Haxe ExUnit runtime cap, so exact-head portable CI remains the final independent proof.
1 parent 0c832bb commit 1067532

5 files changed

Lines changed: 34 additions & 37 deletions

File tree

std/elixir/_std/sys/ssl/Key.hx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Key {
4141

4242
private class KeyState {
4343
public static function readPem(data:String, isPublic:Bool, pass:String):Term {
44-
return untyped __elixir__('(
44+
var decoded:Term = untyped __elixir__('(
4545
entries = :public_key.pem_decode({0})
4646
public_tags = [:SubjectPublicKeyInfo, :RSAPublicKey, :DSAPublicKey, :ECPublicKey]
4747
private_tags = [:PrivateKeyInfo, :RSAPrivateKey, :DSAPrivateKey, :ECPrivateKey]
@@ -54,22 +54,21 @@ private class KeyState {
5454
key_kind = if {1}, do: "public", else: "private"
5555
raise "sys.ssl.Key.readPEM could not find a " <> key_kind <> " key entry"
5656
end
57-
decoded =
58-
if is_nil({2}) do
59-
:public_key.pem_entry_decode(entry)
60-
else
61-
:public_key.pem_entry_decode(entry, String.to_charlist({2}))
62-
end
63-
KeyState.create(decoded)
57+
if is_nil({2}) do
58+
:public_key.pem_entry_decode(entry)
59+
else
60+
:public_key.pem_entry_decode(entry, String.to_charlist({2}))
61+
end
6462
)', data, isPublic, pass);
63+
return create(decoded);
6564
}
6665

6766
public static function readDer(data:Term, isPublic:Bool):Term {
68-
return untyped __elixir__('(
67+
var decoded:Term = untyped __elixir__('(
6968
entry_tag = if {1}, do: :SubjectPublicKeyInfo, else: :PrivateKeyInfo
70-
decoded = :public_key.pem_entry_decode({entry_tag, {0}, :not_encrypted})
71-
KeyState.create(decoded)
69+
:public_key.pem_entry_decode({entry_tag, {0}, :not_encrypted})
7270
)', data, isPublic);
71+
return create(decoded);
7372
}
7473

7574
public static function sslKey(keyRef:Term):Term {

test/snapshot/stdlib/sys_ssl_digest/intended/_GeneratedFiles.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
},
9898
{
9999
"path": "sys/ssl/_key/key_state.ex",
100-
"sha256": "d38e5d22750fade78fa48df740e8b6e52fb8296575bfa9c8d12b49dbbdfd125d"
100+
"sha256": "da511c039d4b27cb6f83ec637c9b6784da702127f247792cc285d1af9ea0df3c"
101101
},
102102
{
103103
"path": "sys/ssl/digest.ex",
@@ -112,5 +112,5 @@
112112
"sha256": "7050c5def57907bbb793022fe8e1bf8d07865bcab165fff31af4e14b05bbab2b"
113113
}
114114
],
115-
"generation": "2ee190719866f7cef2ae75a8776ef3a9fbfb3dc038af7ee2c762569b7670ca22"
115+
"generation": "819913c73c575dc26fe6e6a925f436f58f6e48bf30764fa31fcb5154c58c96e8"
116116
}

test/snapshot/stdlib/sys_ssl_digest/intended/sys/ssl/_key/key_state.ex

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
defmodule KeyState do
22
def read_pem(data, is_public, pass) do
3-
(
3+
decoded = (
44
entries = :public_key.pem_decode(data)
55
public_tags = [:SubjectPublicKeyInfo, :RSAPublicKey, :DSAPublicKey, :ECPublicKey]
66
private_tags = [:PrivateKeyInfo, :RSAPrivateKey, :DSAPrivateKey, :ECPrivateKey]
@@ -13,21 +13,20 @@ defmodule KeyState do
1313
key_kind = if is_public, do: "public", else: "private"
1414
raise "sys.ssl.Key.readPEM could not find a " <> key_kind <> " key entry"
1515
end
16-
decoded =
17-
if is_nil(pass) do
18-
:public_key.pem_entry_decode(entry)
19-
else
20-
:public_key.pem_entry_decode(entry, String.to_charlist(pass))
21-
end
22-
KeyState.create(decoded)
16+
if is_nil(pass) do
17+
:public_key.pem_entry_decode(entry)
18+
else
19+
:public_key.pem_entry_decode(entry, String.to_charlist(pass))
20+
end
2321
)
22+
create(decoded)
2423
end
2524
def read_der(data, is_public) do
26-
(
25+
decoded = (
2726
entry_tag = if is_public, do: :SubjectPublicKeyInfo, else: :PrivateKeyInfo
28-
decoded = :public_key.pem_entry_decode({entry_tag, data, :not_encrypted})
29-
KeyState.create(decoded)
27+
:public_key.pem_entry_decode({entry_tag, data, :not_encrypted})
3028
)
29+
create(decoded)
3130
end
3231
def ssl_key(key_ref) do
3332
(

test/snapshot/stdlib/sys_ssl_socket_surfaces/intended/_GeneratedFiles.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
},
161161
{
162162
"path": "sys/ssl/_key/key_state.ex",
163-
"sha256": "d38e5d22750fade78fa48df740e8b6e52fb8296575bfa9c8d12b49dbbdfd125d"
163+
"sha256": "da511c039d4b27cb6f83ec637c9b6784da702127f247792cc285d1af9ea0df3c"
164164
},
165165
{
166166
"path": "sys/ssl/_socket/ssl_socket_input.ex",
@@ -187,5 +187,5 @@
187187
"sha256": "7050c5def57907bbb793022fe8e1bf8d07865bcab165fff31af4e14b05bbab2b"
188188
}
189189
],
190-
"generation": "1f0baa1817fbd2b3381857b0929b8c612cf22d69197db21ed7977ccfd16e3ab3"
190+
"generation": "e8e29e626b4bc5987bcf2c274c4095e12f005281e98e2be3dc0624e0e0b02832"
191191
}

test/snapshot/stdlib/sys_ssl_socket_surfaces/intended/sys/ssl/_key/key_state.ex

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
defmodule KeyState do
22
def read_pem(data, is_public, pass) do
3-
(
3+
decoded = (
44
entries = :public_key.pem_decode(data)
55
public_tags = [:SubjectPublicKeyInfo, :RSAPublicKey, :DSAPublicKey, :ECPublicKey]
66
private_tags = [:PrivateKeyInfo, :RSAPrivateKey, :DSAPrivateKey, :ECPrivateKey]
@@ -13,21 +13,20 @@ defmodule KeyState do
1313
key_kind = if is_public, do: "public", else: "private"
1414
raise "sys.ssl.Key.readPEM could not find a " <> key_kind <> " key entry"
1515
end
16-
decoded =
17-
if is_nil(pass) do
18-
:public_key.pem_entry_decode(entry)
19-
else
20-
:public_key.pem_entry_decode(entry, String.to_charlist(pass))
21-
end
22-
KeyState.create(decoded)
16+
if is_nil(pass) do
17+
:public_key.pem_entry_decode(entry)
18+
else
19+
:public_key.pem_entry_decode(entry, String.to_charlist(pass))
20+
end
2321
)
22+
create(decoded)
2423
end
2524
def read_der(data, is_public) do
26-
(
25+
decoded = (
2726
entry_tag = if is_public, do: :SubjectPublicKeyInfo, else: :PrivateKeyInfo
28-
decoded = :public_key.pem_entry_decode({entry_tag, data, :not_encrypted})
29-
KeyState.create(decoded)
27+
:public_key.pem_entry_decode({entry_tag, data, :not_encrypted})
3028
)
29+
create(decoded)
3130
end
3231
def ssl_key(key_ref) do
3332
(

0 commit comments

Comments
 (0)