File tree Expand file tree Collapse file tree 7 files changed +40
-18
lines changed Expand file tree Collapse file tree 7 files changed +40
-18
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,21 @@ console.log(hash);
19
19
// c0fa1bc00531bd78ef38c628449c5102aeabd49b5dc3a2a516ea6ea959d6658e
20
20
```
21
21
22
+ ## Determining if crypto support is unavailable
23
+
24
+ It is possible for Node.js to be built without including support for the
25
+ ` crypto ` module. In such cases, calling ` require('crypto') ` will result in an
26
+ error being thrown.
27
+
28
+ ``` js
29
+ var crypto;
30
+ try {
31
+ crypto = require (' crypto' );
32
+ } catch (err) {
33
+ console .log (' crypto support is disabled!' );
34
+ }
35
+ ```
36
+
22
37
## Class: Certificate
23
38
24
39
SPKAC is a Certificate Signing Request mechanism originally implemented by
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
+ require ( 'internal/util' ) . assertCrypto ( exports ) ;
4
+
3
5
const assert = require ( 'assert' ) ;
4
6
const EventEmitter = require ( 'events' ) ;
5
7
const stream = require ( 'stream' ) ;
@@ -9,12 +11,7 @@ const common = require('_tls_common');
9
11
const debug = util . debuglog ( 'tls-legacy' ) ;
10
12
const Buffer = require ( 'buffer' ) . Buffer ;
11
13
const Timer = process . binding ( 'timer_wrap' ) . Timer ;
12
- var Connection = null ;
13
- try {
14
- Connection = process . binding ( 'crypto' ) . Connection ;
15
- } catch ( e ) {
16
- throw new Error ( 'Node.js is not compiled with openssl crypto support' ) ;
17
- }
14
+ const Connection = process . binding ( 'crypto' ) . Connection ;
18
15
19
16
function SlabBuffer ( ) {
20
17
this . create ( ) ;
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
+ require ( 'internal/util' ) . assertCrypto ( exports ) ;
4
+
3
5
const assert = require ( 'assert' ) ;
4
6
const crypto = require ( 'crypto' ) ;
5
7
const net = require ( 'net' ) ;
Original file line number Diff line number Diff line change 3
3
4
4
'use strict' ;
5
5
6
+ const internalUtil = require ( 'internal/util' ) ;
7
+ internalUtil . assertCrypto ( exports ) ;
8
+
6
9
exports . DEFAULT_ENCODING = 'buffer' ;
7
10
8
- try {
9
- var binding = process . binding ( 'crypto' ) ;
10
- var randomBytes = binding . randomBytes ;
11
- var getCiphers = binding . getCiphers ;
12
- var getHashes = binding . getHashes ;
13
- var getCurves = binding . getCurves ;
14
- var getFipsCrypto = binding . getFipsCrypto ;
15
- var setFipsCrypto = binding . setFipsCrypto ;
16
- } catch ( e ) {
17
- throw new Error ( 'Node.js is not compiled with openssl crypto support' ) ;
18
- }
11
+ const binding = process . binding ( 'crypto' ) ;
12
+ const randomBytes = binding . randomBytes ;
13
+ const getCiphers = binding . getCiphers ;
14
+ const getHashes = binding . getHashes ;
15
+ const getCurves = binding . getCurves ;
16
+ const getFipsCrypto = binding . getFipsCrypto ;
17
+ const setFipsCrypto = binding . setFipsCrypto ;
19
18
20
19
const Buffer = require ( 'buffer' ) . Buffer ;
21
20
const constants = require ( 'constants' ) ;
22
21
const stream = require ( 'stream' ) ;
23
22
const util = require ( 'util' ) ;
24
- const internalUtil = require ( 'internal/util' ) ;
25
23
const LazyTransform = require ( 'internal/streams/lazy_transform' ) ;
26
24
27
25
const DH_GENERATOR = 2 ;
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
+ require ( 'internal/util' ) . assertCrypto ( exports ) ;
4
+
3
5
const tls = require ( 'tls' ) ;
4
6
const url = require ( 'url' ) ;
5
7
const http = require ( 'http' ) ;
Original file line number Diff line number Diff line change @@ -96,3 +96,9 @@ exports.isError = function isError(e) {
96
96
exports . objectToString = function objectToString ( o ) {
97
97
return Object . prototype . toString . call ( o ) ;
98
98
} ;
99
+
100
+ const noCrypto = ! process . versions . openssl ;
101
+ exports . assertCrypto = function ( exports ) {
102
+ if ( noCrypto )
103
+ throw new Error ( 'Node.js is not compiled with openssl crypto support' ) ;
104
+ } ;
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
+ require ( 'internal/util' ) . assertCrypto ( exports ) ;
4
+
3
5
const net = require ( 'net' ) ;
4
6
const url = require ( 'url' ) ;
5
7
const binding = process . binding ( 'crypto' ) ;
You can’t perform that action at this time.
0 commit comments