@@ -4,7 +4,7 @@ import Platform from '../../../../common/platform';
4
4
import crypto from 'crypto' ;
5
5
import ErrorInfo from '../../../../common/lib/types/errorinfo' ;
6
6
import * as API from '../../../../../ably' ;
7
- import { IGetCipherParams } from 'common/types/ICrypto' ;
7
+ import ICrypto , { IGetCipherParams } from 'common/types/ICrypto' ;
8
8
9
9
var Crypto = ( function ( ) {
10
10
var DEFAULT_ALGORITHM = 'aes' ;
@@ -120,9 +120,9 @@ var Crypto = (function () {
120
120
* concatenated with the resulting raw ciphertext to construct the "ciphertext"
121
121
* data passed to the recipient.
122
122
*/
123
- function Crypto ( ) { }
123
+ class Crypto {
124
124
125
- Crypto . CipherParams = CipherParams ;
125
+ static CipherParams = CipherParams ;
126
126
127
127
/**
128
128
* Obtain a complete CipherParams instance from the provided params, filling
@@ -133,7 +133,7 @@ var Crypto = (function () {
133
133
* base64-encoded string. May optionally also contain: algorithm (defaults to
134
134
* AES), mode (defaults to 'cbc')
135
135
*/
136
- Crypto . getDefaultParams = function ( params : API . Types . CipherParamOptions ) {
136
+ static getDefaultParams ( params : API . Types . CipherParamOptions ) {
137
137
var key ;
138
138
139
139
if ( ! params . key ) {
@@ -163,15 +163,15 @@ var Crypto = (function () {
163
163
164
164
validateCipherParams ( cipherParams ) ;
165
165
return cipherParams ;
166
- } ;
166
+ }
167
167
168
168
/**
169
169
* Generate a random encryption key from the supplied keylength (or the
170
170
* default keyLength if none supplied) as a Buffer
171
171
* @param keyLength (optional) the required keyLength in bits
172
172
* @param callback (optional) (err, key)
173
173
*/
174
- Crypto . generateRandomKey = function ( keyLength ?: number , callback ?: API . Types . StandardCallback < API . Types . CipherKey > ) {
174
+ static generateRandomKey ( keyLength ?: number , callback ?: API . Types . StandardCallback < API . Types . CipherKey > ) {
175
175
if ( arguments . length == 1 && typeof keyLength == 'function' ) {
176
176
callback = keyLength ;
177
177
keyLength = undefined ;
@@ -184,14 +184,14 @@ var Crypto = (function () {
184
184
generateRandom ( ( keyLength || DEFAULT_KEYLENGTH ) / 8 , ( err , buf ) => {
185
185
callback ! ( err ? ErrorInfo . fromValues ( err ) : null , buf ) ;
186
186
} ) ;
187
- } ;
187
+ }
188
188
189
189
/**
190
190
* Internal; get a ChannelCipher instance based on the given cipherParams
191
191
* @param params either a CipherParams instance or some subset of its
192
192
* fields that includes a key
193
193
*/
194
- Crypto . getCipher = function (
194
+ static getCipher (
195
195
params : IGetCipherParams
196
196
) {
197
197
var cipherParams = isInstCipherParams ( params ) ? params : Crypto . getDefaultParams ( params ) ;
@@ -201,7 +201,11 @@ var Crypto = (function () {
201
201
cipherParams : cipherParams /* CipherOptions.cipher */ ,
202
202
cipher : new CBCCipher ( cipherParams , iv ) /* CipherOptions.channelCipher */ ,
203
203
} ;
204
- } ;
204
+ }
205
+
206
+ }
207
+
208
+ Crypto satisfies ICrypto ;
205
209
206
210
const CBCCipher = function CBCCipher ( this : any /* TODO */ , params : any /* TODO */ , iv : any /* TODO */ ) {
207
211
var algorithm = ( this . algorithm = params . algorithm + '-' + String ( params . keyLength ) + '-' + params . mode ) ;
0 commit comments