Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit 135e849

Browse files
committed
doc: crypto.DEFAULT_ENCODING
1 parent 3ca0550 commit 135e849

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

doc/api/crypto.markdown

+23-10
Original file line numberDiff line numberDiff line change
@@ -398,32 +398,45 @@ Generates cryptographically strong pseudo-random data. Usage:
398398
// handle error
399399
}
400400

401-
## Proposed API Changes in Future Versions of Node
401+
## crypto.DEFAULT_ENCODING
402+
403+
The default encoding to use for functions that can take either strings
404+
or buffers. The default value is `'buffer'`. This is here to make
405+
the crypto module more easily compatible with legacy programs that
406+
expected `'binary'` to be the default encoding.
407+
408+
Note that new programs will probably expect buffers, so only use this
409+
as a temporary measure.
410+
411+
## Recent API Changes
402412

403413
The Crypto module was added to Node before there was the concept of a
404414
unified Stream API, and before there were Buffer objects for handling
405415
binary data.
406416

407417
As such, the streaming classes don't have the typical methods found on
408-
other Node classes, and many methods accept and return Binary-encoded
409-
strings by default rather than Buffers.
418+
other Node classes, and many methods accepted and returned
419+
Binary-encoded strings by default rather than Buffers. This was
420+
changed to use Buffers by default instead.
410421

411-
A future version of node will make Buffers the default data type.
412-
This will be a breaking change for some use cases, but not all.
422+
This is a breaking change for some use cases, but not all.
413423

414424
For example, if you currently use the default arguments to the Sign
415425
class, and then pass the results to the Verify class, without ever
416426
inspecting the data, then it will continue to work as before. Where
417-
you now get a binary string and then present the binary string to the
418-
Verify object, you'll get a Buffer, and present the Buffer to the
419-
Verify object.
427+
you once got a binary string and then presented the binary string to
428+
the Verify object, you'll now get a Buffer, and present the Buffer to
429+
the Verify object.
420430

421-
However, if you are doing things with the string data that will not
431+
However, if you were doing things with the string data that will not
422432
work properly on Buffers (such as, concatenating them, storing in
423433
databases, etc.), or you are passing binary strings to the crypto
424434
functions without an encoding argument, then you will need to start
425435
providing encoding arguments to specify which encoding you'd like to
426-
use.
436+
use. To switch to the previous style of using binary strings by
437+
default, set the `crypto.DEFAULT_ENCODING` field to 'binary'. Note
438+
that new programs will probably expect buffers, so only use this as a
439+
temporary measure.
427440

428441
Also, a Streaming API will be provided, but this will be done in such
429442
a way as to preserve the legacy API surface.

0 commit comments

Comments
 (0)