@@ -105,7 +105,7 @@ var Crypto = (function () {
105
105
* concatenated with the resulting raw ciphertext to construct the "ciphertext"
106
106
* data passed to the recipient.
107
107
*/
108
- function Crypto ( ) { }
108
+ class Crypto {
109
109
110
110
/**
111
111
* Obtain a complete CipherParams instance from the provided params, filling
@@ -116,7 +116,7 @@ var Crypto = (function () {
116
116
* base64-encoded string. May optionally also contain: algorithm (defaults to
117
117
* AES), mode (defaults to 'cbc')
118
118
*/
119
- Crypto . getDefaultParams = function ( params : API . Types . CipherParamOptions ) {
119
+ static getDefaultParams ( params : API . Types . CipherParamOptions ) {
120
120
var key ;
121
121
122
122
if ( ! params . key ) {
@@ -147,15 +147,15 @@ var Crypto = (function () {
147
147
148
148
validateCipherParams ( cipherParams ) ;
149
149
return cipherParams ;
150
- } ;
150
+ }
151
151
152
152
/**
153
153
* Generate a random encryption key from the supplied keylength (or the
154
154
* default keyLength if none supplied) as a Buffer
155
155
* @param keyLength (optional) the required keyLength in bits
156
156
* @param callback (optional) (err, key)
157
157
*/
158
- Crypto . generateRandomKey = function ( keyLength ?: number , callback ?: API . Types . StandardCallback < API . Types . CipherKey > ) {
158
+ static generateRandomKey ( keyLength ?: number , callback ?: API . Types . StandardCallback < API . Types . CipherKey > ) {
159
159
if ( arguments . length == 1 && typeof keyLength == 'function' ) {
160
160
callback = keyLength ;
161
161
keyLength = undefined ;
@@ -168,14 +168,14 @@ var Crypto = (function () {
168
168
generateRandom ( ( keyLength || DEFAULT_KEYLENGTH ) / 8 , ( err , buf ) => {
169
169
callback ! ( err ? ErrorInfo . fromValues ( err ) : null , buf ) ;
170
170
} ) ;
171
- } ;
171
+ }
172
172
173
173
/**
174
174
* Internal; get a ChannelCipher instance based on the given cipherParams
175
175
* @param params either a CipherParams instance or some subset of its
176
176
* fields that includes a key
177
177
*/
178
- Crypto . getCipher = function (
178
+ static getCipher (
179
179
params : IGetCipherParams
180
180
) {
181
181
var cipherParams = isInstCipherParams ( params ) ? params : Crypto . getDefaultParams ( params ) ;
@@ -185,7 +185,11 @@ var Crypto = (function () {
185
185
cipherParams : cipherParams /* CipherOptions.cipher */ ,
186
186
cipher : new CBCCipher ( cipherParams , iv ) /* CipherOptions.channelCipher */ ,
187
187
} ;
188
- } ;
188
+ }
189
+
190
+ }
191
+
192
+ Crypto satisfies ICrypto ;
189
193
190
194
const CBCCipher = function CBCCipher ( this : { algorithm : string ; key : NodeCipherKey ; iv : Buffer | null ; encryptCipher : NodeCipher ; blockLength : number ; } , params : API . Types . CipherParams , iv : Buffer | BrowserBufferlike ) {
191
195
this . algorithm = params . algorithm + '-' + String ( params . keyLength ) + '-' + params . mode ;
0 commit comments