@@ -112,7 +112,7 @@ var Crypto = (function () {
112
112
* concatenated with the resulting raw ciphertext to construct the "ciphertext"
113
113
* data passed to the recipient.
114
114
*/
115
- function Crypto ( ) { }
115
+ class Crypto {
116
116
117
117
/**
118
118
* Obtain a complete CipherParams instance from the provided params, filling
@@ -123,7 +123,7 @@ var Crypto = (function () {
123
123
* base64-encoded string. May optionally also contain: algorithm (defaults to
124
124
* AES), mode (defaults to 'cbc')
125
125
*/
126
- Crypto . getDefaultParams = function ( params : API . Types . CipherParamOptions ) {
126
+ static getDefaultParams ( params : API . Types . CipherParamOptions ) {
127
127
var key ;
128
128
129
129
if ( ! params . key ) {
@@ -154,15 +154,15 @@ var Crypto = (function () {
154
154
155
155
validateCipherParams ( cipherParams ) ;
156
156
return cipherParams ;
157
- } ;
157
+ }
158
158
159
159
/**
160
160
* Generate a random encryption key from the supplied keylength (or the
161
161
* default keyLength if none supplied) as a Buffer
162
162
* @param keyLength (optional) the required keyLength in bits
163
163
* @param callback (optional) (err, key)
164
164
*/
165
- Crypto . generateRandomKey = function ( keyLength ?: number , callback ?: API . Types . StandardCallback < API . Types . CipherKey > ) {
165
+ static generateRandomKey ( keyLength ?: number , callback ?: API . Types . StandardCallback < API . Types . CipherKey > ) {
166
166
if ( arguments . length == 1 && typeof keyLength == 'function' ) {
167
167
callback = keyLength ;
168
168
keyLength = undefined ;
@@ -175,22 +175,27 @@ var Crypto = (function () {
175
175
generateRandom ( ( keyLength || DEFAULT_KEYLENGTH ) / 8 , ( err , buf ) => {
176
176
callback ! ( err ? ErrorInfo . fromValues ( err ) : null , buf ) ;
177
177
} ) ;
178
- } ;
178
+ }
179
179
180
180
/**
181
181
* Internal; get a ChannelCipher instance based on the given cipherParams
182
182
* @param params either a CipherParams instance or some subset of its
183
183
* fields that includes a key
184
184
*/
185
- Crypto . getCipher = function ( params : IGetCipherParams < IV > ) {
185
+ static getCipher ( params : IGetCipherParams < IV > ) {
186
186
var cipherParams = isInstCipherParams ( params ) ? params : Crypto . getDefaultParams ( params ) ;
187
187
188
188
var iv = params . iv || generateRandom ( DEFAULT_BLOCKLENGTH ) ;
189
189
return {
190
190
cipherParams : cipherParams /* CipherOptions.cipher */ ,
191
191
cipher : new CBCCipher ( cipherParams , iv ) /* CipherOptions.channelCipher */ ,
192
192
} ;
193
- } ;
193
+ }
194
+
195
+ }
196
+
197
+ // TODO sort out
198
+ // Crypto satisfies ICrypto<IV, InputPlaintext, OutputCiphertext, InputCiphertext, OutputPlaintext>;
194
199
195
200
const CBCCipher = function CBCCipher (
196
201
this : { algorithm : string ; key : NodeCipherKey ; iv : IV | null ; encryptCipher : NodeCipher ; blockLength : number } ,
0 commit comments