Commit 08197aa
crypto: remove default encoding from sign/verify
getDefaultEncoding() always returns 'buffer' in Node.js 20. It requires
some careful justification but the default encoding can be eliminated
from sig.js entirely.
In Sign.prototype.update, we can safely remove the conditional
assignment of getDefaultEncoding() to encoding. This is because
SignUpdate() in crypto_sig.cc internally calls node::crypto::Decode,
which returns UTF8 for falsy encoding values. In other words, with the
conditional assignment, StringBytes::Write() ultimately receives the
encoding BUFFER, and without the conditional assignment, it receives the
encoding UTF8. However, StringBytes::Write() treats both encodings
identically, so there is no need to deviate from the internal default
encoding UTF8.
In Sign.prototype.sign, we can also safely remove the conditional
assignment of getDefaultEncoding() to encoding. Whether encoding is
falsy or 'buffer' makes no difference.
In Verify.prototype.verify, we can also safely remove the conditional
assignment of getDefaultEncoding() to sigEncoding. This is because the
function passes the sigEncoding to getArrayBufferOrView(), which passes
it to Buffer.from(). If sigEncoding is 'buffer', getArrayBufferOrView()
instead passes 'utf8' to Buffer.from(). Because the default encoding of
Buffer.from() is 'utf8', passing a falsy encoding to
getArrayBufferOrView() instead of 'buffer' results in the same behavior.
Refs: #47182
PR-URL: #49145
Reviewed-By: Filip Skokan <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>1 parent 173aed4 commit 08197aa
1 file changed
+0
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
38 | 37 | | |
39 | 38 | | |
40 | 39 | | |
| |||
70 | 69 | | |
71 | 70 | | |
72 | 71 | | |
73 | | - | |
74 | | - | |
75 | 72 | | |
76 | 73 | | |
77 | 74 | | |
| |||
131 | 128 | | |
132 | 129 | | |
133 | 130 | | |
134 | | - | |
135 | 131 | | |
136 | 132 | | |
137 | 133 | | |
| |||
216 | 212 | | |
217 | 213 | | |
218 | 214 | | |
219 | | - | |
220 | | - | |
221 | 215 | | |
222 | 216 | | |
223 | 217 | | |
| |||
0 commit comments