@@ -398,32 +398,45 @@ Generates cryptographically strong pseudo-random data. Usage:
398
398
// handle error
399
399
}
400
400
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
402
412
403
413
The Crypto module was added to Node before there was the concept of a
404
414
unified Stream API, and before there were Buffer objects for handling
405
415
binary data.
406
416
407
417
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.
410
421
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.
413
423
414
424
For example, if you currently use the default arguments to the Sign
415
425
class, and then pass the results to the Verify class, without ever
416
426
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.
420
430
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
422
432
work properly on Buffers (such as, concatenating them, storing in
423
433
databases, etc.), or you are passing binary strings to the crypto
424
434
functions without an encoding argument, then you will need to start
425
435
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.
427
440
428
441
Also, a Streaming API will be provided, but this will be done in such
429
442
a way as to preserve the legacy API surface.
0 commit comments