diff --git a/doc/api/crypto.md b/doc/api/crypto.md index e84c10dfa4b469..d9124f500ccdde 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -856,6 +856,12 @@ thrown. ## `crypto` module methods and properties +## crypto.constants + +Returns an object containing commonly used constants for crypto and security +related operations. The specific constants currently defined are described in +[Crypto Constants][]. + ### crypto.DEFAULT_ENCODING The default encoding to use for functions that can take either strings @@ -1205,11 +1211,11 @@ keys: * `key` : {String} - PEM encoded private key * `passphrase` : {String} - Optional passphrase for the private key * `padding` : An optional padding value, one of the following: - * `constants.RSA_NO_PADDING` - * `constants.RSA_PKCS1_PADDING` - * `constants.RSA_PKCS1_OAEP_PADDING` + * `crypto.constants.RSA_NO_PADDING` + * `crypto.constants.RSA_PKCS1_PADDING` + * `crypto.constants.RSA_PKCS1_OAEP_PADDING` -All paddings are defined in the `constants` module. +All paddings are defined in `crypto.constants`. ### crypto.privateEncrypt(private_key, buffer) @@ -1223,11 +1229,11 @@ keys: * `key` : {String} - PEM encoded private key * `passphrase` : {String} - Optional passphrase for the private key * `padding` : An optional padding value, one of the following: - * `constants.RSA_NO_PADDING` - * `constants.RSA_PKCS1_PADDING` - * `constants.RSA_PKCS1_OAEP_PADDING` + * `crypto.constants.RSA_NO_PADDING` + * `crypto.constants.RSA_PKCS1_PADDING` + * `crypto.constants.RSA_PKCS1_OAEP_PADDING` -All paddings are defined in the `constants` module. +All paddings are defined in `crypto.constants`. ### crypto.publicDecrypt(public_key, buffer) @@ -1241,14 +1247,14 @@ keys: * `key` : {String} - PEM encoded public key * `passphrase` : {String} - Optional passphrase for the private key * `padding` : An optional padding value, one of the following: - * `constants.RSA_NO_PADDING` - * `constants.RSA_PKCS1_PADDING` - * `constants.RSA_PKCS1_OAEP_PADDING` + * `crypto.constants.RSA_NO_PADDING` + * `crypto.constants.RSA_PKCS1_PADDING` + * `crypto.constants.RSA_PKCS1_OAEP_PADDING` Because RSA public keys can be derived from private keys, a private key may be passed instead of a public key. -All paddings are defined in the `constants` module. +All paddings are defined in `crypto.constants`. ### crypto.publicEncrypt(public_key, buffer) @@ -1262,14 +1268,14 @@ keys: * `key` : {String} - PEM encoded public key * `passphrase` : {String} - Optional passphrase for the private key * `padding` : An optional padding value, one of the following: - * `constants.RSA_NO_PADDING` - * `constants.RSA_PKCS1_PADDING` - * `constants.RSA_PKCS1_OAEP_PADDING` + * `crypto.constants.RSA_NO_PADDING` + * `crypto.constants.RSA_PKCS1_PADDING` + * `crypto.constants.RSA_PKCS1_OAEP_PADDING` Because RSA public keys can be derived from private keys, a private key may be passed instead of a public key. -All paddings are defined in the `constants` module. +All paddings are defined in `crypto.constants`. ### crypto.randomBytes(size[, callback]) @@ -1313,22 +1319,22 @@ Load and set the `engine` for some or all OpenSSL functions (selected by flags). `engine` could be either an id or a path to the engine's shared library. The optional `flags` argument uses `ENGINE_METHOD_ALL` by default. The `flags` -is a bit field taking one of or a mix of the following flags (defined in the -`constants` module): - -* `ENGINE_METHOD_RSA` -* `ENGINE_METHOD_DSA` -* `ENGINE_METHOD_DH` -* `ENGINE_METHOD_RAND` -* `ENGINE_METHOD_ECDH` -* `ENGINE_METHOD_ECDSA` -* `ENGINE_METHOD_CIPHERS` -* `ENGINE_METHOD_DIGESTS` -* `ENGINE_METHOD_STORE` -* `ENGINE_METHOD_PKEY_METHS` -* `ENGINE_METHOD_PKEY_ASN1_METHS` -* `ENGINE_METHOD_ALL` -* `ENGINE_METHOD_NONE` +is a bit field taking one of or a mix of the following flags (defined in +`crypto.constants`): + +* `crypto.constants.ENGINE_METHOD_RSA` +* `crypto.constants.ENGINE_METHOD_DSA` +* `crypto.constants.ENGINE_METHOD_DH` +* `crypto.constants.ENGINE_METHOD_RAND` +* `crypto.constants.ENGINE_METHOD_ECDH` +* `crypto.constants.ENGINE_METHOD_ECDSA` +* `crypto.constants.ENGINE_METHOD_CIPHERS` +* `crypto.constants.ENGINE_METHOD_DIGESTS` +* `crypto.constants.ENGINE_METHOD_STORE` +* `crypto.constants.ENGINE_METHOD_PKEY_METHS` +* `crypto.constants.ENGINE_METHOD_PKEY_ASN1_METHS` +* `crypto.constants.ENGINE_METHOD_ALL` +* `crypto.constants.ENGINE_METHOD_NONE` ## Notes @@ -1380,6 +1386,311 @@ Based on the recommendations of [NIST SP 800-131A][]: See the reference for other recommendations and details. +## Crypto Constants + +The following constants exported by `crypto.constants` apply to various uses of +the `crypto`, `tls`, and `https` modules and are generally specific to OpenSSL. + +### OpenSSL Options + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ConstantDescription
SSL_OP_ALLApplies multiple bug workarounds within OpenSSL. See https://www.openssl.org/docs/manmaster/ssl/SSL_CTX_set_options.html for detail.
SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATIONAllows legacy insecure renegotiation between OpenSSL and unpatched clients +or servers. See +https://www.openssl.org/docs/manmaster/ssl/SSL_CTX_set_options.html.
SSL_OP_CIPHER_SERVER_PREFERENCEUses the server's preferences instead of the clients when selecting a +cipher. See +https://www.openssl.org/docs/manmaster/ssl/SSL_CTX_set_options.html.
SSL_OP_CISCO_ANYCONNECTInstructs OpenSSL to use Cisco's "speshul" version of DTLS_BAD_VER.
SSL_OP_COOKIE_EXCHANGEInstructs OpenSSL to turn on cookie exchange.
SSL_OP_CRYPTOPRO_TLSEXT_BUGInstructs OpenSSL to add server-hello extension from an early version of the +cryptopro draft.
SSL_OP_DONT_INSERT_EMPTY_FRAGMENTSInstructs OpenSSL to disable a SSL 3.0/TLS 1.0 vulnerability workaround added in OpenSSL 0.9.6d.
SSL_OP_EPHEMERAL_RSAInstructs OpenSSL to always use the tmp_rsa key when performing RSA operations.
SSL_OP_LEGACY_SERVER_CONNECTAllow initial connection to servers that do not support RI.
SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER
SSL_OP_MICROSOFT_SESS_ID_BUG
SSL_OP_MSIE_SSLV2_RSA_PADDINGInstructs OpenSSL to disable the workaround for a man-in-the-middle +protocol-version vulnerability in the SSL 2.0 server implementation.
SSL_OP_NETSCAPE_CA_DN_BUG
SSL_OP_NETSCAPE_CHALLENGE_BUG
SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG
SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG
SSL_OP_NO_COMPRESSIONInstructs OpenSSL to disable support for SSL/TLS compression.
SSL_OP_NO_QUERY_MTU
SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATIONInstructs OpenSSL to always start a new session when performing renegotiation.
SSL_OP_NO_SSLv2Instructs OpenSSL to turn off SSL v2
SSL_OP_NO_SSLv3Instructs OpenSSL to turn off SSL v3
SSL_OP_NO_TICKETInstructs OpenSSL to disable use of RFC4507bis tickets.
SSL_OP_NO_TLSv1Instructs OpenSSL to turn off TLS v1
SSL_OP_NO_TLSv1_1Instructs OpenSSL to turn off TLS v1.1
SSL_OP_NO_TLSv1_2Instructs OpenSSL to turn off TLS v1.2
SSL_OP_PKCS1_CHECK_1
SSL_OP_PKCS1_CHECK_2
SSL_OP_SINGLE_DH_USEInstructs OpenSSL to always create a new key when using temporary/ephemeral +DH parameters.
SSL_OP_SINGLE_ECDH_USEInstructs OpenSSL to always create a new key when using temporary/ephemeral +ECDH parameters.
SSL_OP_SSLEAY_080_CLIENT_DH_BUG
SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG
SSL_OP_TLS_BLOCK_PADDING_BUG
SSL_OP_TLS_D5_BUG
SSL_OP_TLS_ROLLBACK_BUGInstructs OpenSSL to disable version rollback attack detection.
+ +### OpenSSL Engine Constants + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ConstantDescription
ENGINE_METHOD_RSALimit engine usage to RSA
ENGINE_METHOD_DSALimit engine usage to DSA
ENGINE_METHOD_DHLimit engine usage to DH
ENGINE_METHOD_RANDLimit engine usage to RAND
ENGINE_METHOD_ECDHLimit engine usage to ECDH
ENGINE_METHOD_ECDSALimit engine usage to ECDSA
ENGINE_METHOD_CIPHERSLimit engine usage to CIPHERS
ENGINE_METHOD_DIGESTSLimit engine usage to DIGESTS
ENGINE_METHOD_STORELimit engine usage to STORE
ENGINE_METHOD_PKEY_METHSLimit engine usage to PKEY_METHDS
ENGINE_METHOD_PKEY_ASN1_METHSLimit engine usage to PKEY_ASN1_METHS
ENGINE_METHOD_ALL
ENGINE_METHOD_NONE
+ +### Other OpenSSL Constants + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ConstantDescription
DH_CHECK_P_NOT_SAFE_PRIME
DH_CHECK_P_NOT_PRIME
DH_UNABLE_TO_CHECK_GENERATOR
DH_NOT_SUITABLE_GENERATOR
NPN_ENABLED
ALPN_ENABLED
RSA_PKCS1_PADDING
RSA_SSLV23_PADDING
RSA_NO_PADDING
RSA_PKCS1_OAEP_PADDING
RSA_X931_PADDING
RSA_PKCS1_PSS_PADDING
POINT_CONVERSION_COMPRESSED
POINT_CONVERSION_UNCOMPRESSED
POINT_CONVERSION_HYBRID
+ +### Node.js Crypto Constants + + + + + + + + + + + + + + +
ConstantDescription
defaultCoreCipherListSpecifies the built in default cipher list used by Node.js.
defaultCipherListSpecifies the active default cipher list used by the current Node.js +process.
+ + [`Buffer`]: buffer.html [`cipher.final()`]: #crypto_cipher_final_output_encoding [`cipher.update()`]: #crypto_cipher_update_data_input_encoding_output_encoding @@ -1423,3 +1734,4 @@ See the reference for other recommendations and details. [RFC 3526]: https://www.rfc-editor.org/rfc/rfc3526.txt [stream]: stream.html [stream-writable-write]: stream.html#stream_writable_write_chunk_encoding_callback +[Crypto Constants]: #crypto_crypto_constants diff --git a/doc/api/fs.md b/doc/api/fs.md index 895d5c5e931c00..2602984288a4eb 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -271,13 +271,13 @@ optional integer that specifies the accessibility checks to be performed. The following constants define the possible values of `mode`. It is possible to create a mask consisting of the bitwise OR of two or more values. -- `fs.F_OK` - File is visible to the calling process. This is useful for -determining if a file exists, but says nothing about `rwx` permissions. +- `fs.constants.F_OK` - File is visible to the calling process. This is useful +for determining if a file exists, but says nothing about `rwx` permissions. Default if no `mode` is specified. -- `fs.R_OK` - File can be read by the calling process. -- `fs.W_OK` - File can be written by the calling process. -- `fs.X_OK` - File can be executed by the calling process. This has no effect -on Windows (will behave like `fs.F_OK`). +- `fs.constants.R_OK` - File can be read by the calling process. +- `fs.constants.W_OK` - File can be written by the calling process. +- `fs.constants.X_OK` - File can be executed by the calling process. This has no +effect on Windows (will behave like `fs.constants.F_OK`). The final argument, `callback`, is a callback function that is invoked with a possible error argument. If any of the accessibility checks fail, the error @@ -285,7 +285,7 @@ argument will be populated. The following example checks if the file `/etc/passwd` can be read and written by the current process. ```js -fs.access('/etc/passwd', fs.R_OK | fs.W_OK, (err) => { +fs.access('/etc/passwd', fs.constants.R_OK | fs.constants.W_OK, (err) => { console.log(err ? 'no access!' : 'can read/write'); }); ``` @@ -295,8 +295,8 @@ fs.access('/etc/passwd', fs.R_OK | fs.W_OK, (err) => { * `path` {String | Buffer} * `mode` {Integer} -Synchronous version of [`fs.access()`][]. This throws if any accessibility checks -fail, and does nothing otherwise. +Synchronous version of [`fs.access()`][]. This throws if any accessibility +checks fail, and does nothing otherwise. ## fs.appendFile(file, data[, options], callback) @@ -389,6 +389,12 @@ to the completion callback. Synchronous close(2). Returns `undefined`. +## fs.constants + +Returns an object containing commonly used constants for file system +operations. The specific constants currently defined are described in +[FS Constants][]. + ## fs.createReadStream(path[, options]) * `path` {String | Buffer} @@ -424,9 +430,9 @@ the file instead of the entire file. Both `start` and `end` are inclusive and start at 0. The `encoding` can be any one of those accepted by [`Buffer`][]. If `fd` is specified, `ReadStream` will ignore the `path` argument and will use -the specified file descriptor. This means that no `'open'` event will be emitted. -Note that `fd` should be blocking; non-blocking `fd`s should be passed to -[`net.Socket`][]. +the specified file descriptor. This means that no `'open'` event will be +emitted. Note that `fd` should be blocking; non-blocking `fd`s should be passed +to [`net.Socket`][]. If `autoClose` is false, then the file descriptor won't be closed, even if there's an error. It is your responsibility to close it and make sure @@ -473,7 +479,8 @@ Returns a new [`WriteStream`][] object. (See [Writable Stream][]). `options` may also include a `start` option to allow writing data at some position past the beginning of the file. Modifying a file rather than replacing it may require a `flags` mode of `r+` rather than the -default mode `w`. The `defaultEncoding` can be any one of those accepted by [`Buffer`][]. +default mode `w`. The `defaultEncoding` can be any one of those accepted by +[`Buffer`][]. If `autoClose` is set to true (default behavior) on `error` or `end` the file descriptor will be closed automatically. If `autoClose` is false, @@ -512,7 +519,8 @@ non-existent. ## fs.existsSync(path) - Stability: 0 - Deprecated: Use [`fs.statSync()`][] or [`fs.accessSync()`][] instead. + Stability: 0 - Deprecated: Use [`fs.statSync()`][] or [`fs.accessSync()`][] + instead. * `path` {String | Buffer} @@ -797,7 +805,7 @@ to a non-existent file. The exclusive flag may or may not work with network file systems. `flags` can also be a number as documented by open(2); commonly used constants -are available from `require('constants')`. On Windows, flags are translated to +are available from `fs.constants`. On Windows, flags are translated to their equivalent ones where applicable, e.g. `O_WRONLY` to `FILE_GENERIC_WRITE`, or `O_EXCL|O_CREAT` to `CREATE_NEW`, as accepted by CreateFileW. @@ -1046,11 +1054,11 @@ Synchronous stat(2). Returns an instance of [`fs.Stats`][]. * `callback` {Function} Asynchronous symlink(2). No arguments other than a possible exception are given -to the completion callback. -The `type` argument can be set to `'dir'`, `'file'`, or `'junction'` (default -is `'file'`) and is only available on Windows (ignored on other platforms). -Note that Windows junction points require the destination path to be absolute. When using -`'junction'`, the `target` argument will automatically be normalized to absolute path. +to the completion callback. The `type` argument can be set to `'dir'`, +`'file'`, or `'junction'` (default is `'file'`) and is only available on +Windows (ignored on other platforms). Note that Windows junction points require +the destination path to be absolute. When using `'junction'`, the `target` +argument will automatically be normalized to absolute path. Here is an example below: @@ -1263,9 +1271,9 @@ _Note: when an `fs.watchFile` operation results in an `ENOENT` error, it will of zero. If the file is created later on, the listener will be called again, with the latest stat objects. This is a change in functionality since v0.10._ -_Note: [`fs.watch()`][] is more efficient than `fs.watchFile` and `fs.unwatchFile`. -`fs.watch` should be used instead of `fs.watchFile` and `fs.unwatchFile` -when possible._ +_Note: [`fs.watch()`][] is more efficient than `fs.watchFile` and +`fs.unwatchFile`. `fs.watch` should be used instead of `fs.watchFile` and +`fs.unwatchFile` when possible._ ## fs.write(fd, buffer, offset, length[, position], callback) @@ -1395,6 +1403,216 @@ The synchronous version of [`fs.writeFile()`][]. Returns `undefined`. Synchronous versions of [`fs.write()`][]. Returns the number of bytes written. +## FS Constants + +The following constants are exported by `fs.constants`. **Note:** not every +constant will be available on every operating system. + +### File Access Constants + +The following constants are meant for use with [`fs.access()`][]. + + + + + + + + + + + + + + + + + + + + + + +
ConstantDescription
F_OKFlag indicating that the file is visible to the calling process.
R_OKFlag indicating that the file can be read by the calling process.
W_OKFlag indicating that the file can be written by the calling process.
X_OKFlag indicating that the file can be executed by the calling process.
+ +### File Open Constants + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ConstantDescription
O_RDONLYFlag indicating to open a file for read-only access.
O_WRONLYFlag indicating to open a file for write-only access.
O_RDWRFlag indicating to open a file for read-write access.
O_CREATFlag indicating to create the file if it does not already exist.
O_EXCLFlag indicating that opening a file should fail if the O_CREAT +flag is set and the file already exists.
O_NOCTTYFlag indicating that if path identifies a terminal device, opening the path +shall not cause that terminal to become the controlling terminal for the +process.
O_TRUNCFlag indicating that if the file exists and is a regular file, and the file +is opened successfully for write access, it's length shall be truncated to +zero.
O_APPENDFlag indicating that data will be appended to the end of the file.
O_DIRECTORYFlag indicating that the open should fail if the path is not a +directory.
O_NOATIMEFlag indicating reading accesses to the file system will no longer result in + an update to the `atime` information associated with the file. This flag is + available on Linux operating systems only.
O_NOFOLLOWFlag indicating that the open should fail if the path is a symbolic +link.
O_SYNCFlag indicating that the file is opened for synchronous I/O.
O_SYMLINKFlag indicating to open the symbolic link itself rather than the resource it +is pointing to.
O_DIRECTWhen set, an attempt will be made to minimize caching effects of file +I/O.
O_NONBLOCKFlag indicating to open the file in nonblocking mode when possible.
+ +### File Type Constants + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ConstantDescription
S_IFMTBit mask used to extract the file type code.
S_IFREGFile type constant for a regular file.
S_IFDIRFile type constant for a directory.
S_IFCHRFile type constant for a character-oriented device file.
S_IFBLKFile type constant for a block-oriented device file.
S_IFIFOFile type constant for a FIFO/pipe.
S_IFLNKFile type constant for a symbolic link.
S_IFSOCKFile type constant for a socket.
+ +### File Mode Constants + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ConstantDescription
S_IRWXUFile mode indicating read, write and execute by owner.
S_IRUSRFile mode indicating read by owner.
S_IWUSRFile mode indicating write by owner.
S_IXUSRFile mode indicating execute by owner.
S_IRWXGFile mode indicating read, write and execute by group.
S_IRGRPFile mode indicating read by group.
S_IWGRPFile mode indicating write by group.
S_IXGRPFile mode indicating execute by group.
S_IRWXOFile mode indicating read, write and execute by others.
S_IROTHFile mode indicating read by others.
S_IWOTHFile mode indicating write by others.
S_IXOTHFile mode indicating execute by others.
+ [`Buffer.byteLength`]: buffer.html#buffer_class_method_buffer_bytelength_string_encoding [`Buffer`]: buffer.html#buffer_buffer [Caveats]: #fs_caveats @@ -1426,3 +1644,4 @@ Synchronous versions of [`fs.write()`][]. Returns the number of bytes written. [Readable Stream]: stream.html#stream_class_stream_readable [Writable Stream]: stream.html#stream_class_stream_writable [inode]: http://www.linux.org/threads/intro-to-inodes.4130 +[FS Constants]: #fs_fs_constants diff --git a/doc/api/os.md b/doc/api/os.md index 43e71460c24471..51e520cc163acc 100644 --- a/doc/api/os.md +++ b/doc/api/os.md @@ -16,6 +16,12 @@ system. Returns the operating system CPU architecture. Possible values are `'x64'`, `'arm'` and `'ia32'`. Returns the value of [`process.arch`][]. +## os.constants + +Returns an object containing commonly used operating system specific constants +for error codes, process signals, and so on. The specific constants currently +defined are described in [OS Constants][]. + ## os.cpus() Returns an array of objects containing information about each CPU/core @@ -198,5 +204,622 @@ operating system. This differs from the result of `os.homedir()`, which queries several environment variables for the home directory before falling back to the operating system response. +## OS Constants + +The following constants are exported by `os.constants`. **Note:** Not all +constants will be available on every operating system. + +### Signal Constants + +The following signal constants are exported by `os.constants.signals`: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ConstantDescription
SIGHUPSent to indicate when a controlling terminal or process is closed.
SIGINTSent to indicate when a user wishes to interrupt a process.
SIGQUITSent to indicate when a user wishes to terminate a process and perform a +core dump.
SIGILLSent to a process to notify that it has attempted to perform an illegal, +malformed, unknown or privileged instruction.
SIGTRAPSent to a proces when an exception has occurred.
SIGABRTSent to a process to request that it abort.
SIGIOTSynonym for SIGABRT
SIGBUSSent to a process to notify that it has caused a bus error.
SIGFPESent to a process to notify that it has performed an illegal arithmetic +operation.
SIGKILLSent to a process to terminate it immediately.
SIGUSR1 SIGUSR2Sent to a process to identify user-defined conditions.
SIGSEGVSent to a process to notify of a segmentation fault.
SIGPIPESent to a process when it has attempted to write to a disconnected pipe.
SIGALRMSent to a process when a system timer elapses.
SIGTERMSent to a process to request termination.
SIGCHLDSent to a process when a child process terminates.
SIGSTKFLTSent to a process to indicate a stack fault on a coprocessor.
SIGCONTSent to instruct the operating system to continue a paused process.
SIGSTOPSent to instruct the operating system to halt a process.
SIGTSTPSent to a process to request it to stop.
SIGBREAKSent to indicate when a user wishes to interrupt a process.
SIGTTINSent to a process when it reads from the TTY while in the background.
SIGTTOUSent to a process when it writes to the TTY while in the background.
SIGURGSent to a process when a socket has urgent data to read.
SIGXCPUSent to a process when it has exceeded it's limit on CPI usage.
SIGXFSZSent to a process when it grows a file larger than the maximum allowed.
SIGVTALRMSent to a process when a virtual timer has elapsed.
SIGPROFSent to a process when a system timer has elapsed.
SIGWINCHSent to a process when the controlling terminal has changed sized.
SIGIOSent to a process when I/O is available.
SIGPOLLSynonym for SIGIO
SIGLOSTSent to a process when a file lock has been lost.
SIGPWRSent to a process to notify of a power failure.
SIGINFOSynonym for SIGPWR
SIGSYSSent to a process to notify of a bad argument.
SIGUNUSEDSynonym for SIGSYS
+ +### Error Constants + +The following error constants are exported by `os.constants.errno`: + +#### POSIX Error Constants + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ConstantDescription
E2BIGIndicates that the list of arguments is longer than expected.
EACCESIndicates that the operation did not have sufficient permissions.
EADDRINUSEIndicates that the network address is already in use.
EADDRNOTAVAILIndicates that the network address is currently unavailable for use.
EAFNOSUPPORTIndicates that the network address family is not supported.
EAGAINIndicates that there is currently no data available and to try the operation +again later.
EALREADYIndicates that the socket already has a pending connection in progress.
EBADFIndicates that a file descriptor is not valid.
EBADMSGIndicates an invalid data message.
EBUSYIndicates that a device or resource is busy.
ECANCELEDIndicates that an operation was canceled.
ECHILDIndicates that there are no child processes.
ECONNABORTEDIndicates that the network connection has been aborted.
ECONNREFUSEDIndicates that the network connection has been refused.
ECONNRESETIndicates that the network connection has been reset.
EDEADLKIndicates that a resource deadlock has been avoided.
EDESTADDRREQIndicates that a destination address is required.
EDOMIndicates that an argument is out of the domain of the function.
EDQUOTIndicates that the disk quota has been exceeded.
EEXISTIndicates that the file already exists.
EFAULTIndicates an invalid pointer address.
EFBIGIndicates that the file is too large.
EHOSTUNREACHIndicates that the host is unreachable.
EIDRMIndicates that the identifier has been removed.
EILSEQIndicates an illegal byte sequence.
EINPROGRESSIndicates that an operation is already in progress.
EINTRIndicates that a function call was interrupted.
EINVALIndicates that an invalid argument was provided.
EIOIndicates an otherwise unspecified I/O error.
EISCONNIndicates that the socket is connected.
EISDIRIndicates that the path is a directory.
ELOOPIndicates too many levels of symbolic links in a path.
EMFILEIndicates that there are too many open files.
EMLINKIndicates that there are too many links.
EMSGSIZEIndicates that the provided message is too long.
EMULTIHOPIndicates that a multihop was attempted.
ENAMETOOLONGIndicates that the filename is too long.
ENETDOWNIndicates that the network is down.
ENETRESETIndicates that the connection has been aborted by the network.
ENETUNREACHIndicates that the network is unreachable.
ENFILEIndicates too many open files in the system.
ENOBUFSIndicates that no buffer space is available.
ENODATAIndicates that no message is available on the stream head read queue.
ENODEVIndicates that there is no such device.
ENOENTIndicates that there is no such file or directory.
ENOEXECIndicates an exec format error.
ENOLCKIndicates that there are no locks available.
ENOLINKIndications that a link has been severed.
ENOMEMIndicates that there is not enough space.
ENOMSGIndicates that there is no message of the desired type.
ENOPROTOOPTIndicates that a given protocol is not available.
ENOSPCIndicates that there is no space available on the device.
ENOSRIndicates that there are no stream resources available.
ENOSTRIndicates that a given resource is not a stream.
ENOSYSIndicates that a function has not been implemented.
ENOTCONNIndicates that the socket is not connected.
ENOTDIRIndicates that the path is not a directory.
ENOTEMPTYIndicates that the directory is not empty.
ENOTSOCKIndicates that the given item is not a socket.
ENOTSUPIndicates that a given operation is not supported.
ENOTTYIndicates an inappropriate I/O control operation.
ENXIOIndicates no such device or address.
EOPNOTSUPPIndicates that an operation is not supported on the socket.
EOVERFLOWIndicates that a value is too large to be stored in a given data type.
EPERMIndicates that the operation is not permitted.
EPIPEIndicates a broken pipe.
EPROTOIndicates a protocol error.
EPROTONOSUPPORTIndicates that a protocol is not supported.
EPROTOTYPEIndicates the wrong type of protocol for a socket.
ERANGEIndicates that the results are too large.
EROFSIndicates that the file system is read only.
ESPIPEIndicates an invalid seek operation.
ESRCHIndicates that there is no such process.
ESTALEIndicates that the file handle is stale.
ETIMEIndicates an expired timer.
ETIMEDOUTIndicates that the connection timed out.
ETXTBSYIndicates that a text file is busy.
EWOULDBLOCKIndicates that the operation would block.
EXDEVIndicates an improper link. +
+ +#### Windows Specific Error Constants + +The following error codes are specific to the Windows operating system: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ConstantDescription
WSAEINTRIndicates an interrupted function call.
WSAEBADFIndicates an invalid file handle.
WSAEACCESIndicates insufficient permissions to complete the operation.
WSAEFAULTIndicates an invalid pointer address.
WSAEINVALIndicates that an invalid argument was passed.
WSAEMFILEIndicates that there are too many open files.
WSAEWOULDBLOCKIndicates that a resource is temporarily unavailable.
WSAEINPROGRESSIndicates that an operation is currently in progress.
WSAEALREADYIndicates that an operation is already in progress.
WSAENOTSOCKIndicates that the resource is not a socket.
WSAEDESTADDRREQIndicates that a destination address is required.
WSAEMSGSIZEIndicates that the message size is too long.
WSAEPROTOTYPEIndicates the wrong protocol type for the socket.
WSAENOPROTOOPTIndicates a bad protocol option.
WSAEPROTONOSUPPORTIndicates that the protocol is not supported.
WSAESOCKTNOSUPPORTIndicates that the socket type is not supported.
WSAEOPNOTSUPPIndicates that the operation is not supported.
WSAEPFNOSUPPORTIndicates that the protocol family is not supported.
WSAEAFNOSUPPORTIndicates that the address family is not supported.
WSAEADDRINUSEIndicates that the network address is already in use.
WSAEADDRNOTAVAILIndicates that the network address is not available.
WSAENETDOWNIndicates that the network is down.
WSAENETUNREACHIndicates that the network is unreachable.
WSAENETRESETIndicates that the network connection has been reset.
WSAECONNABORTEDIndicates that the connection has been aborted.
WSAECONNRESETIndicates that the connection has been reset by the peer.
WSAENOBUFSIndicates that there is no buffer space available.
WSAEISCONNIndicates that the socket is already connected.
WSAENOTCONNIndicates that the socket is not connected.
WSAESHUTDOWNIndicates that data cannot be sent after the socket has been shutdown.
WSAETOOMANYREFSIndicates that there are too many references.
WSAETIMEDOUTIndicates that the connection has timed out.
WSAECONNREFUSEDIndicates that the connection has been refused.
WSAELOOPIndicates that a name cannot be translated.
WSAENAMETOOLONGIndicates that a name was too long.
WSAEHOSTDOWNIndicates that a network host is down.
WSAEHOSTUNREACHIndicates that there is no route to a network host.
WSAENOTEMPTYIndicates that the directory is not empty.
WSAEPROCLIMIndicates that there are too many processes.
WSAEUSERSIndicates that the user quota has been exceeded.
WSAEDQUOTIndicates that the disk quota has been exceeded.
WSAESTALEIndicates a stale file handle reference.
WSAEREMOTEIndicates that the item is remote.
WSASYSNOTREADYIndicates that the network subsystem is not ready.
WSAVERNOTSUPPORTEDIndicates that the winsock.dll version is out of range.
WSANOTINITIALISEDIndicates that successful WSAStartup has not yet been performed.
WSAEDISCONIndicates that a graceful shutdown is in progress.
WSAENOMOREIndicates that there are no more results.
WSAECANCELLEDIndicates that an operation has been canceled.
WSAEINVALIDPROCTABLEIndicates that the procedure call table is invalid.
WSAEINVALIDPROVIDERIndicates an invalid service provider.
WSAEPROVIDERFAILEDINITIndicates that the service provider failed to initialized.
WSASYSCALLFAILUREIndicates a system call failure.
WSASERVICE_NOT_FOUNDIndicates that a service was not found.
WSATYPE_NOT_FOUNDIndicates that a class type was not found.
WSA_E_NO_MOREIndicates that there are no more results.
WSA_E_CANCELLEDIndicates that the call was canceled.
WSAEREFUSEDIndicates that a database query was refused.
+ +### libuv Constants + + + + + + + + + + +
ConstantDescription
UV_UDP_REUSEADDR
+ [`process.arch`]: process.html#process_process_arch [`process.platform`]: process.html#process_process_platform +[OS Constants]: #os_os_constants diff --git a/lib/_tls_common.js b/lib/_tls_common.js index 382ba5e8f479ef..d75b9ffe28188d 100644 --- a/lib/_tls_common.js +++ b/lib/_tls_common.js @@ -1,9 +1,11 @@ 'use strict'; const internalUtil = require('internal/util'); -const constants = require('constants'); const tls = require('tls'); +const SSL_OP_CIPHER_SERVER_PREFERENCE = + process.binding('constants').crypto.SSL_OP_CIPHER_SERVER_PREFERENCE; + // Lazily loaded var crypto = null; @@ -38,7 +40,7 @@ exports.createSecureContext = function createSecureContext(options, context) { var secureOptions = options.secureOptions; if (options.honorCipherOrder) - secureOptions |= constants.SSL_OP_CIPHER_SERVER_PREFERENCE; + secureOptions |= SSL_OP_CIPHER_SERVER_PREFERENCE; var c = new SecureContext(options.secureProtocol, secureOptions, context); diff --git a/lib/child_process.js b/lib/child_process.js index 81fb8c1fcd0fe8..8e1b6f138693c4 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -3,7 +3,7 @@ const util = require('util'); const internalUtil = require('internal/util'); const debug = util.debuglog('child_process'); -const constants = require('constants'); +const constants = process.binding('constants').os.signals; const uv = process.binding('uv'); const spawn_sync = process.binding('spawn_sync'); diff --git a/lib/constants.js b/lib/constants.js index 9fa017904ceb45..deebf90513da46 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -1,3 +1,11 @@ 'use strict'; -module.exports = process.binding('constants'); +// This module is soft-deprecated. Users should be directed towards using +// the specific constants exposed by the individual modules on which they +// are most relevant. +const constants = process.binding('constants'); +Object.assign(exports, + constants.os.errors, + constants.os.signals, + constants.fs, + constants.crypto); diff --git a/lib/crypto.js b/lib/crypto.js index 688ac34e4ad767..b0f0f5ddef656a 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -8,6 +8,7 @@ internalUtil.assertCrypto(exports); exports.DEFAULT_ENCODING = 'buffer'; +const constants = process.binding('constants').crypto; const binding = process.binding('crypto'); const randomBytes = binding.randomBytes; const getCiphers = binding.getCiphers; @@ -17,13 +18,18 @@ const getFipsCrypto = binding.getFipsCrypto; const setFipsCrypto = binding.setFipsCrypto; const Buffer = require('buffer').Buffer; -const constants = require('constants'); const stream = require('stream'); const util = require('util'); const LazyTransform = require('internal/streams/lazy_transform'); const DH_GENERATOR = 2; +Object.defineProperty(exports, 'constants', { + configurable: false, + enumerable: true, + value: constants +}); + // This is here because many functions accepted binary strings without // any explicit encoding in older versions of node, and we don't want // to break them unnecessarily. diff --git a/lib/dgram.js b/lib/dgram.js index 4473282148fdff..e6e88b1a9a5ed6 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -4,7 +4,7 @@ const assert = require('assert'); const Buffer = require('buffer').Buffer; const util = require('util'); const EventEmitter = require('events'); -const constants = require('constants'); +const UV_UDP_REUSEADDR = process.binding('constants').os.UV_UDP_REUSEADDR; const UDP = process.binding('udp_wrap').UDP; const SendWrap = process.binding('udp_wrap').SendWrap; @@ -186,7 +186,7 @@ Socket.prototype.bind = function(port_ /*, address, callback*/) { var flags = 0; if (self._reuseAddr) - flags |= constants.UV_UDP_REUSEADDR; + flags |= UV_UDP_REUSEADDR; if (cluster.isWorker && !exclusive) { function onHandle(err, handle) { diff --git a/lib/fs.js b/lib/fs.js index e441746366e729..f0ad82cfb18bb0 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -3,11 +3,11 @@ 'use strict'; +const constants = process.binding('constants').fs; const util = require('util'); const pathModule = require('path'); const binding = process.binding('fs'); -const constants = require('constants'); const fs = exports; const Buffer = require('buffer').Buffer; const Stream = require('stream').Stream; @@ -15,6 +15,12 @@ const EventEmitter = require('events'); const FSReqWrap = binding.FSReqWrap; const FSEvent = process.binding('fs_event_wrap').FSEvent; +Object.defineProperty(exports, 'constants', { + configurable: false, + enumerable: true, + value: constants +}); + const Readable = Stream.Readable; const Writable = Stream.Writable; diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index ff26e8b75ab58c..73c641c116d24e 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -6,7 +6,7 @@ const EventEmitter = require('events'); const net = require('net'); const dgram = require('dgram'); const util = require('util'); -const constants = require('constants'); +const constants = process.binding('constants').os.signals; const assert = require('assert'); const Process = process.binding('process_wrap').Process; diff --git a/lib/internal/process.js b/lib/internal/process.js index 881d91b11e9a73..219fae9ac3ac56 100644 --- a/lib/internal/process.js +++ b/lib/internal/process.js @@ -4,7 +4,7 @@ var _lazyConstants = null; function lazyConstants() { if (!_lazyConstants) { - _lazyConstants = process.binding('constants'); + _lazyConstants = process.binding('constants').os.signals; } return _lazyConstants; } @@ -145,8 +145,7 @@ function setupKillAndExit() { err = process._kill(pid, 0); } else { sig = sig || 'SIGTERM'; - if (lazyConstants()[sig] && - sig.slice(0, 3) === 'SIG') { + if (lazyConstants()[sig]) { err = process._kill(pid, lazyConstants()[sig]); } else { throw new Error(`Unknown signal: ${sig}`); @@ -170,7 +169,6 @@ function setupSignalHandlers() { function isSignal(event) { return typeof event === 'string' && - event.slice(0, 3) === 'SIG' && lazyConstants().hasOwnProperty(event); } diff --git a/lib/os.js b/lib/os.js index d065449da84898..206e9941625965 100644 --- a/lib/os.js +++ b/lib/os.js @@ -1,6 +1,7 @@ 'use strict'; const binding = process.binding('os'); +const constants = process.binding('constants').os; const internalUtil = require('internal/util'); const isWindows = process.platform === 'win32'; @@ -16,6 +17,11 @@ exports.networkInterfaces = binding.getInterfaceAddresses; exports.homedir = binding.getHomeDirectory; exports.userInfo = binding.getUserInfo; +Object.defineProperty(exports, 'constants', { + configurable: false, + enumerable: true, + value: constants +}); exports.arch = function() { return process.arch; diff --git a/lib/tls.js b/lib/tls.js index 8699207a24a586..0bd13e5e13dfd6 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -6,7 +6,6 @@ const net = require('net'); const url = require('url'); const binding = process.binding('crypto'); const Buffer = require('buffer').Buffer; -const constants = require('constants'); // Allow {CLIENT_RENEG_LIMIT} client-initiated session renegotiations // every {CLIENT_RENEG_WINDOW} seconds. An error event is emitted if more @@ -17,7 +16,8 @@ exports.CLIENT_RENEG_WINDOW = 600; exports.SLAB_BUFFER_SIZE = 10 * 1024 * 1024; -exports.DEFAULT_CIPHERS = constants.defaultCipherList; +exports.DEFAULT_CIPHERS = + process.binding('constants').crypto.defaultCipherList; exports.DEFAULT_ECDH_CURVE = 'prime256v1'; diff --git a/src/node.cc b/src/node.cc index 6f155a64a387c6..4b05e7a4097850 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2507,7 +2507,7 @@ static void Binding(const FunctionCallbackInfo& args) { cache->Set(module, exports); } else if (!strcmp(*module_v, "constants")) { exports = Object::New(env->isolate()); - DefineConstants(exports); + DefineConstants(env->isolate(), exports); cache->Set(module, exports); } else if (!strcmp(*module_v, "natives")) { exports = Object::New(env->isolate()); diff --git a/src/node_constants.cc b/src/node_constants.cc index 928502f6affca9..2e6be8df37c345 100644 --- a/src/node_constants.cc +++ b/src/node_constants.cc @@ -1,4 +1,6 @@ #include "node_constants.h" +#include "env.h" +#include "env-inl.h" #include "uv.h" @@ -1140,14 +1142,26 @@ void DefineCryptoConstants(Local target) { #endif } -void DefineConstants(Local target) { - DefineErrnoConstants(target); - DefineWindowsErrorConstants(target); - DefineSignalConstants(target); - DefineOpenSSLConstants(target); - DefineSystemConstants(target); - DefineUVConstants(target); - DefineCryptoConstants(target); +void DefineConstants(v8::Isolate* isolate, Local target) { + Local os_constants = Object::New(isolate); + Local err_constants = Object::New(isolate); + Local sig_constants = Object::New(isolate); + Local fs_constants = Object::New(isolate); + Local crypto_constants = Object::New(isolate); + + DefineErrnoConstants(err_constants); + DefineWindowsErrorConstants(err_constants); + DefineSignalConstants(sig_constants); + DefineUVConstants(os_constants); + DefineSystemConstants(fs_constants); + DefineOpenSSLConstants(crypto_constants); + DefineCryptoConstants(crypto_constants); + + os_constants->Set(OneByteString(isolate, "errno"), err_constants); + os_constants->Set(OneByteString(isolate, "signals"), sig_constants); + target->Set(OneByteString(isolate, "os"), os_constants); + target->Set(OneByteString(isolate, "fs"), fs_constants); + target->Set(OneByteString(isolate, "crypto"), crypto_constants); } } // namespace node diff --git a/src/node_constants.h b/src/node_constants.h index a7c75c4eb2bf38..133e68c1926ed7 100644 --- a/src/node_constants.h +++ b/src/node_constants.h @@ -34,7 +34,7 @@ namespace node { extern const char* default_cipher_list; #endif -void DefineConstants(v8::Local target); +void DefineConstants(v8::Isolate* isolate, v8::Local target); } // namespace node #endif // SRC_NODE_CONSTANTS_H_ diff --git a/test/parallel/test-constants.js b/test/parallel/test-constants.js new file mode 100644 index 00000000000000..ea0b93ba7fab6a --- /dev/null +++ b/test/parallel/test-constants.js @@ -0,0 +1,12 @@ +'use strict'; + +require('../common'); +const constants = process.binding('constants'); +const assert = require('assert'); + +assert.ok(constants); +assert.ok(constants.os); +assert.ok(constants.os.signals); +assert.ok(constants.os.errno); +assert.ok(constants.fs); +assert.ok(constants.crypto); diff --git a/test/parallel/test-crypto-binary-default.js b/test/parallel/test-crypto-binary-default.js index 921f236e90fba7..cfe12baa669bca 100644 --- a/test/parallel/test-crypto-binary-default.js +++ b/test/parallel/test-crypto-binary-default.js @@ -5,7 +5,6 @@ var common = require('../common'); var assert = require('assert'); -var constants = require('constants'); if (!common.hasCrypto) { console.log('1..0 # Skipped: missing crypto'); @@ -13,6 +12,7 @@ if (!common.hasCrypto) { } var crypto = require('crypto'); var tls = require('tls'); +const DH_NOT_SUITABLE_GENERATOR = crypto.constants.DH_NOT_SUITABLE_GENERATOR; crypto.DEFAULT_ENCODING = 'binary'; @@ -556,7 +556,7 @@ var p = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' + '4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' + 'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF'; var d = crypto.createDiffieHellman(p, 'hex'); -assert.equal(d.verifyError, constants.DH_NOT_SUITABLE_GENERATOR); +assert.equal(d.verifyError, DH_NOT_SUITABLE_GENERATOR); // Test RSA key signing/verification var rsaSign = crypto.createSign('RSA-SHA1'); diff --git a/test/parallel/test-crypto-dh.js b/test/parallel/test-crypto-dh.js index 4eb3977d63f391..6efd5bde20fbe9 100644 --- a/test/parallel/test-crypto-dh.js +++ b/test/parallel/test-crypto-dh.js @@ -1,13 +1,13 @@ 'use strict'; const common = require('../common'); const assert = require('assert'); -const constants = require('constants'); if (!common.hasCrypto) { console.log('1..0 # Skipped: missing crypto'); return; } const crypto = require('crypto'); +const DH_NOT_SUITABLE_GENERATOR = crypto.constants.DH_NOT_SUITABLE_GENERATOR; // Test Diffie-Hellman with two parties sharing a secret, // using various encodings as we go along @@ -79,8 +79,8 @@ bob.generateKeys(); var aSecret = alice.computeSecret(bob.getPublicKey()).toString('hex'); var bSecret = bob.computeSecret(alice.getPublicKey()).toString('hex'); assert.equal(aSecret, bSecret); -assert.equal(alice.verifyError, constants.DH_NOT_SUITABLE_GENERATOR); -assert.equal(bob.verifyError, constants.DH_NOT_SUITABLE_GENERATOR); +assert.equal(alice.verifyError, DH_NOT_SUITABLE_GENERATOR); +assert.equal(bob.verifyError, DH_NOT_SUITABLE_GENERATOR); /* Ensure specific generator (buffer) works as expected. * The values below (modp2/modp2buf) are for a 1024 bits long prime from @@ -107,8 +107,8 @@ exmodp2.generateKeys(); var modp2Secret = modp2.computeSecret(exmodp2.getPublicKey()).toString('hex'); var exmodp2Secret = exmodp2.computeSecret(modp2.getPublicKey()).toString('hex'); assert.equal(modp2Secret, exmodp2Secret); -assert.equal(modp2.verifyError, constants.DH_NOT_SUITABLE_GENERATOR); -assert.equal(exmodp2.verifyError, constants.DH_NOT_SUITABLE_GENERATOR); +assert.equal(modp2.verifyError, DH_NOT_SUITABLE_GENERATOR); +assert.equal(exmodp2.verifyError, DH_NOT_SUITABLE_GENERATOR); // Ensure specific generator (string with encoding) works as expected. @@ -118,7 +118,7 @@ modp2Secret = modp2.computeSecret(exmodp2_2.getPublicKey()).toString('hex'); var exmodp2_2Secret = exmodp2_2.computeSecret(modp2.getPublicKey()) .toString('hex'); assert.equal(modp2Secret, exmodp2_2Secret); -assert.equal(exmodp2_2.verifyError, constants.DH_NOT_SUITABLE_GENERATOR); +assert.equal(exmodp2_2.verifyError, DH_NOT_SUITABLE_GENERATOR); // Ensure specific generator (string without encoding) works as expected. @@ -128,7 +128,7 @@ modp2Secret = modp2.computeSecret(exmodp2_3.getPublicKey()).toString('hex'); var exmodp2_3Secret = exmodp2_3.computeSecret(modp2.getPublicKey()) .toString('hex'); assert.equal(modp2Secret, exmodp2_3Secret); -assert.equal(exmodp2_3.verifyError, constants.DH_NOT_SUITABLE_GENERATOR); +assert.equal(exmodp2_3.verifyError, DH_NOT_SUITABLE_GENERATOR); // Ensure specific generator (numeric) works as expected. @@ -138,7 +138,7 @@ modp2Secret = modp2.computeSecret(exmodp2_4.getPublicKey()).toString('hex'); var exmodp2_4Secret = exmodp2_4.computeSecret(modp2.getPublicKey()) .toString('hex'); assert.equal(modp2Secret, exmodp2_4Secret); -assert.equal(exmodp2_4.verifyError, constants.DH_NOT_SUITABLE_GENERATOR); +assert.equal(exmodp2_4.verifyError, DH_NOT_SUITABLE_GENERATOR); var p = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' + @@ -146,7 +146,7 @@ var p = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' + '4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' + 'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF'; var bad_dh = crypto.createDiffieHellman(p, 'hex'); -assert.equal(bad_dh.verifyError, constants.DH_NOT_SUITABLE_GENERATOR); +assert.equal(bad_dh.verifyError, DH_NOT_SUITABLE_GENERATOR); // Test ECDH diff --git a/test/parallel/test-crypto-rsa-dsa.js b/test/parallel/test-crypto-rsa-dsa.js index e6f2fe6eb25131..4272a30e81e26c 100644 --- a/test/parallel/test-crypto-rsa-dsa.js +++ b/test/parallel/test-crypto-rsa-dsa.js @@ -2,7 +2,7 @@ var common = require('../common'); var assert = require('assert'); var fs = require('fs'); -var constants = require('constants'); +var constants = require('crypto').constants; if (!common.hasCrypto) { console.log('1..0 # Skipped: missing crypto'); diff --git a/test/parallel/test-fs-open-flags.js b/test/parallel/test-fs-open-flags.js index cf451b4f8d5d95..d212130bc903d1 100644 --- a/test/parallel/test-fs-open-flags.js +++ b/test/parallel/test-fs-open-flags.js @@ -2,16 +2,15 @@ require('../common'); var assert = require('assert'); -var constants = require('constants'); var fs = require('fs'); -var O_APPEND = constants.O_APPEND || 0; -var O_CREAT = constants.O_CREAT || 0; -var O_EXCL = constants.O_EXCL || 0; -var O_RDONLY = constants.O_RDONLY || 0; -var O_RDWR = constants.O_RDWR || 0; -var O_TRUNC = constants.O_TRUNC || 0; -var O_WRONLY = constants.O_WRONLY || 0; +var O_APPEND = fs.constants.O_APPEND || 0; +var O_CREAT = fs.constants.O_CREAT || 0; +var O_EXCL = fs.constants.O_EXCL || 0; +var O_RDONLY = fs.constants.O_RDONLY || 0; +var O_RDWR = fs.constants.O_RDWR || 0; +var O_TRUNC = fs.constants.O_TRUNC || 0; +var O_WRONLY = fs.constants.O_WRONLY || 0; assert.equal(fs._stringToFlags('r'), O_RDONLY); assert.equal(fs._stringToFlags('r+'), O_RDWR); diff --git a/test/parallel/test-fs-open-numeric-flags.js b/test/parallel/test-fs-open-numeric-flags.js index d3bd42227c2a53..1bd9a043927039 100644 --- a/test/parallel/test-fs-open-numeric-flags.js +++ b/test/parallel/test-fs-open-numeric-flags.js @@ -1,7 +1,6 @@ 'use strict'; const common = require('../common'); -const constants = require('constants'); const assert = require('assert'); const fs = require('fs'); const path = require('path'); @@ -11,6 +10,6 @@ common.refreshTmpDir(); // O_WRONLY without O_CREAT shall fail with ENOENT const pathNE = path.join(common.tmpDir, 'file-should-not-exist'); assert.throws( - () => fs.openSync(pathNE, constants.O_WRONLY), + () => fs.openSync(pathNE, fs.constants.O_WRONLY), (e) => e.code === 'ENOENT' ); diff --git a/test/parallel/test-fs-write.js b/test/parallel/test-fs-write.js index 5ddd83e026c095..9cdabe40d3e7c9 100644 --- a/test/parallel/test-fs-write.js +++ b/test/parallel/test-fs-write.js @@ -7,7 +7,7 @@ var fs = require('fs'); var fn = path.join(common.tmpDir, 'write.txt'); var fn2 = path.join(common.tmpDir, 'write2.txt'); var expected = 'ümlaut.'; -var constants = require('constants'); +var constants = fs.constants; var found, found2; common.refreshTmpDir(); @@ -55,4 +55,3 @@ process.on('exit', function() { assert.equal(expected, found); assert.equal(expected, found2); }); - diff --git a/test/parallel/test-https-agent-session-eviction.js b/test/parallel/test-https-agent-session-eviction.js index df6fdc3658c2c9..e6b608c14511c0 100644 --- a/test/parallel/test-https-agent-session-eviction.js +++ b/test/parallel/test-https-agent-session-eviction.js @@ -10,12 +10,12 @@ if (!common.hasCrypto) { const assert = require('assert'); const https = require('https'); const fs = require('fs'); -const constants = require('constants'); +const SSL_OP_NO_TICKET = require('crypto').constants.SSL_OP_NO_TICKET; const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'), - secureOptions: constants.SSL_OP_NO_TICKET + secureOptions: SSL_OP_NO_TICKET }; // Create TLS1.2 server diff --git a/test/parallel/test-tls-async-cb-after-socket-end.js b/test/parallel/test-tls-async-cb-after-socket-end.js index d89a4e9930ca6a..f836f7ab827b86 100644 --- a/test/parallel/test-tls-async-cb-after-socket-end.js +++ b/test/parallel/test-tls-async-cb-after-socket-end.js @@ -4,7 +4,7 @@ var common = require('../common'); var path = require('path'); var fs = require('fs'); -var constants = require('constants'); +const SSL_OP_NO_TICKET = require('crypto').constants.SSL_OP_NO_TICKET; if (!common.hasCrypto) { console.log('1..0 # Skipped: missing crypto'); @@ -14,7 +14,7 @@ if (!common.hasCrypto) { var tls = require('tls'); var options = { - secureOptions: constants.SSL_OP_NO_TICKET, + secureOptions: SSL_OP_NO_TICKET, key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')), cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')) }; diff --git a/test/parallel/test-tls-cipher-list.js b/test/parallel/test-tls-cipher-list.js index 70c99dd91e439c..38d3a72a55a3c2 100644 --- a/test/parallel/test-tls-cipher-list.js +++ b/test/parallel/test-tls-cipher-list.js @@ -8,13 +8,13 @@ if (!common.hasCrypto) { const assert = require('assert'); const spawn = require('child_process').spawn; -const defaultCoreList = require('constants').defaultCoreCipherList; +const defaultCoreList = require('crypto').constants.defaultCoreCipherList; function doCheck(arg, check) { var out = ''; arg = arg.concat([ '-pe', - 'require("constants").defaultCipherList' + 'require("crypto").constants.defaultCipherList' ]); spawn(process.execPath, arg, {}). on('error', common.fail). diff --git a/test/parallel/test-tls-ocsp-callback.js b/test/parallel/test-tls-ocsp-callback.js index 27afb3431a48fc..fcff346c8672c8 100644 --- a/test/parallel/test-tls-ocsp-callback.js +++ b/test/parallel/test-tls-ocsp-callback.js @@ -18,10 +18,11 @@ if (!common.hasCrypto) { var tls = require('tls'); var assert = require('assert'); -var constants = require('constants'); var fs = require('fs'); var join = require('path').join; +const SSL_OP_NO_TICKET = require('crypto').constants.SSL_OP_NO_TICKET; + var pfx = fs.readFileSync(join(common.fixturesDir, 'keys', 'agent1-pfx.pem')); function test(testOptions, cb) { @@ -76,7 +77,7 @@ function test(testOptions, cb) { port: common.PORT, requestOCSP: testOptions.ocsp !== false, secureOptions: testOptions.ocsp === false ? - constants.SSL_OP_NO_TICKET : 0, + SSL_OP_NO_TICKET : 0, rejectUnauthorized: false }, function() { clientSecure++; diff --git a/test/parallel/test-tls-server-verify.js b/test/parallel/test-tls-server-verify.js index c9d4d263f5be7d..ac82a870e9f6d2 100644 --- a/test/parallel/test-tls-server-verify.js +++ b/test/parallel/test-tls-server-verify.js @@ -104,7 +104,9 @@ if (!common.hasCrypto) { } var tls = require('tls'); -var constants = require('constants'); +const SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION = + require('crypto').constants.SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION; + var assert = require('assert'); var fs = require('fs'); var spawn = require('child_process').spawn; @@ -262,7 +264,7 @@ function runTest(port, testIndex) { */ if (tcase.renegotiate) { serverOptions.secureOptions = - constants.SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION; + SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION; } var renegotiated = false;