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);
1919 // c0fa1bc00531bd78ef38c628449c5102aeabd49b5dc3a2a516ea6ea959d6658e
2020```
2121
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+
2237## Class: Certificate
2338
2439SPKAC is a Certificate Signing Request mechanism originally implemented by
Original file line number Diff line number Diff line change 11'use strict' ;
22
3+ require ( 'internal/util' ) . assertCrypto ( exports ) ;
4+
35const assert = require ( 'assert' ) ;
46const EventEmitter = require ( 'events' ) ;
57const stream = require ( 'stream' ) ;
@@ -9,12 +11,7 @@ const common = require('_tls_common');
911const debug = util . debuglog ( 'tls-legacy' ) ;
1012const Buffer = require ( 'buffer' ) . Buffer ;
1113const 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 ;
1815
1916function SlabBuffer ( ) {
2017 this . create ( ) ;
Original file line number Diff line number Diff line change 11'use strict' ;
22
3+ require ( 'internal/util' ) . assertCrypto ( exports ) ;
4+
35const assert = require ( 'assert' ) ;
46const crypto = require ( 'crypto' ) ;
57const net = require ( 'net' ) ;
Original file line number Diff line number Diff line change 33
44'use strict' ;
55
6+ const internalUtil = require ( 'internal/util' ) ;
7+ internalUtil . assertCrypto ( exports ) ;
8+
69exports . DEFAULT_ENCODING = 'buffer' ;
710
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 ;
1918
2019const Buffer = require ( 'buffer' ) . Buffer ;
2120const constants = require ( 'constants' ) ;
2221const stream = require ( 'stream' ) ;
2322const util = require ( 'util' ) ;
24- const internalUtil = require ( 'internal/util' ) ;
2523const LazyTransform = require ( 'internal/streams/lazy_transform' ) ;
2624
2725const DH_GENERATOR = 2 ;
Original file line number Diff line number Diff line change 11'use strict' ;
22
3+ require ( 'internal/util' ) . assertCrypto ( exports ) ;
4+
35const tls = require ( 'tls' ) ;
46const url = require ( 'url' ) ;
57const http = require ( 'http' ) ;
Original file line number Diff line number Diff line change @@ -96,3 +96,9 @@ exports.isError = function isError(e) {
9696exports . objectToString = function objectToString ( o ) {
9797 return Object . prototype . toString . call ( o ) ;
9898} ;
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 11'use strict' ;
22
3+ require ( 'internal/util' ) . assertCrypto ( exports ) ;
4+
35const net = require ( 'net' ) ;
46const url = require ( 'url' ) ;
57const binding = process . binding ( 'crypto' ) ;
You can’t perform that action at this time.
0 commit comments