@@ -10,6 +10,8 @@ const { validateString } = require('internal/validators');
10
10
const { isArrayBufferView } = require ( 'internal/util/types' ) ;
11
11
const {
12
12
getDefaultEncoding,
13
+ kHandle,
14
+ legacyNativeHandle,
13
15
toBuf
14
16
} = require ( 'internal/crypto/util' ) ;
15
17
const {
@@ -59,10 +61,10 @@ function DiffieHellman(sizeOrKey, keyEncoding, generator, genEncoding) {
59
61
else if ( typeof generator !== 'number' )
60
62
generator = toBuf ( generator , genEncoding ) ;
61
63
62
- this . _handle = new _DiffieHellman ( sizeOrKey , generator ) ;
64
+ legacyNativeHandle ( this , new _DiffieHellman ( sizeOrKey , generator ) ) ;
63
65
Object . defineProperty ( this , 'verifyError' , {
64
66
enumerable : true ,
65
- value : this . _handle . verifyError ,
67
+ value : this [ kHandle ] . verifyError ,
66
68
writable : false
67
69
} ) ;
68
70
}
@@ -71,10 +73,10 @@ function DiffieHellman(sizeOrKey, keyEncoding, generator, genEncoding) {
71
73
function DiffieHellmanGroup ( name ) {
72
74
if ( ! ( this instanceof DiffieHellmanGroup ) )
73
75
return new DiffieHellmanGroup ( name ) ;
74
- this . _handle = new _DiffieHellmanGroup ( name ) ;
76
+ legacyNativeHandle ( this , new _DiffieHellmanGroup ( name ) ) ;
75
77
Object . defineProperty ( this , 'verifyError' , {
76
78
enumerable : true ,
77
- value : this . _handle . verifyError ,
79
+ value : this [ kHandle ] . verifyError ,
78
80
writable : false
79
81
} ) ;
80
82
}
@@ -85,7 +87,7 @@ DiffieHellmanGroup.prototype.generateKeys =
85
87
dhGenerateKeys ;
86
88
87
89
function dhGenerateKeys ( encoding ) {
88
- const keys = this . _handle . generateKeys ( ) ;
90
+ const keys = this [ kHandle ] . generateKeys ( ) ;
89
91
encoding = encoding || getDefaultEncoding ( ) ;
90
92
return encode ( keys , encoding ) ;
91
93
}
@@ -99,7 +101,7 @@ function dhComputeSecret(key, inEnc, outEnc) {
99
101
const encoding = getDefaultEncoding ( ) ;
100
102
inEnc = inEnc || encoding ;
101
103
outEnc = outEnc || encoding ;
102
- const ret = this . _handle . computeSecret ( toBuf ( key , inEnc ) ) ;
104
+ const ret = this [ kHandle ] . computeSecret ( toBuf ( key , inEnc ) ) ;
103
105
if ( typeof ret === 'string' )
104
106
throw new ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY ( ) ;
105
107
return encode ( ret , outEnc ) ;
@@ -111,7 +113,7 @@ DiffieHellmanGroup.prototype.getPrime =
111
113
dhGetPrime ;
112
114
113
115
function dhGetPrime ( encoding ) {
114
- const prime = this . _handle . getPrime ( ) ;
116
+ const prime = this [ kHandle ] . getPrime ( ) ;
115
117
encoding = encoding || getDefaultEncoding ( ) ;
116
118
return encode ( prime , encoding ) ;
117
119
}
@@ -122,7 +124,7 @@ DiffieHellmanGroup.prototype.getGenerator =
122
124
dhGetGenerator ;
123
125
124
126
function dhGetGenerator ( encoding ) {
125
- const generator = this . _handle . getGenerator ( ) ;
127
+ const generator = this [ kHandle ] . getGenerator ( ) ;
126
128
encoding = encoding || getDefaultEncoding ( ) ;
127
129
return encode ( generator , encoding ) ;
128
130
}
@@ -133,7 +135,7 @@ DiffieHellmanGroup.prototype.getPublicKey =
133
135
dhGetPublicKey ;
134
136
135
137
function dhGetPublicKey ( encoding ) {
136
- const key = this . _handle . getPublicKey ( ) ;
138
+ const key = this [ kHandle ] . getPublicKey ( ) ;
137
139
encoding = encoding || getDefaultEncoding ( ) ;
138
140
return encode ( key , encoding ) ;
139
141
}
@@ -144,22 +146,22 @@ DiffieHellmanGroup.prototype.getPrivateKey =
144
146
dhGetPrivateKey ;
145
147
146
148
function dhGetPrivateKey ( encoding ) {
147
- const key = this . _handle . getPrivateKey ( ) ;
149
+ const key = this [ kHandle ] . getPrivateKey ( ) ;
148
150
encoding = encoding || getDefaultEncoding ( ) ;
149
151
return encode ( key , encoding ) ;
150
152
}
151
153
152
154
153
155
DiffieHellman . prototype . setPublicKey = function setPublicKey ( key , encoding ) {
154
156
encoding = encoding || getDefaultEncoding ( ) ;
155
- this . _handle . setPublicKey ( toBuf ( key , encoding ) ) ;
157
+ this [ kHandle ] . setPublicKey ( toBuf ( key , encoding ) ) ;
156
158
return this ;
157
159
} ;
158
160
159
161
160
162
DiffieHellman . prototype . setPrivateKey = function setPrivateKey ( key , encoding ) {
161
163
encoding = encoding || getDefaultEncoding ( ) ;
162
- this . _handle . setPrivateKey ( toBuf ( key , encoding ) ) ;
164
+ this [ kHandle ] . setPrivateKey ( toBuf ( key , encoding ) ) ;
163
165
return this ;
164
166
} ;
165
167
@@ -169,7 +171,7 @@ function ECDH(curve) {
169
171
return new ECDH ( curve ) ;
170
172
171
173
validateString ( curve , 'curve' ) ;
172
- this . _handle = new _ECDH ( curve ) ;
174
+ legacyNativeHandle ( this , new _ECDH ( curve ) ) ;
173
175
}
174
176
175
177
ECDH . prototype . computeSecret = DiffieHellman . prototype . computeSecret ;
@@ -178,14 +180,14 @@ ECDH.prototype.setPublicKey = DiffieHellman.prototype.setPublicKey;
178
180
ECDH . prototype . getPrivateKey = DiffieHellman . prototype . getPrivateKey ;
179
181
180
182
ECDH . prototype . generateKeys = function generateKeys ( encoding , format ) {
181
- this . _handle . generateKeys ( ) ;
183
+ this [ kHandle ] . generateKeys ( ) ;
182
184
183
185
return this . getPublicKey ( encoding , format ) ;
184
186
} ;
185
187
186
188
ECDH . prototype . getPublicKey = function getPublicKey ( encoding , format ) {
187
189
const f = getFormat ( format ) ;
188
- const key = this . _handle . getPublicKey ( f ) ;
190
+ const key = this [ kHandle ] . getPublicKey ( f ) ;
189
191
encoding = encoding || getDefaultEncoding ( ) ;
190
192
return encode ( key , encoding ) ;
191
193
} ;
0 commit comments