Skip to content

Commit fe6c3a9

Browse files
committed
rewrite Base.create()
1 parent a6b5280 commit fe6c3a9

File tree

9 files changed

+91
-155
lines changed

9 files changed

+91
-155
lines changed

package-lock.json

Lines changed: 0 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cipher-core.js

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class Cipher extends BufferedBlockAlgorithm {
3030
*
3131
* @example
3232
*
33-
* const cipher = CryptoJS.algo.AES.create(
33+
* const cipher = new Cipher(
3434
* CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray }
3535
* );
3636
*/
@@ -70,7 +70,7 @@ export class Cipher extends BufferedBlockAlgorithm {
7070
* const cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray });
7171
*/
7272
static createEncryptor(key, cfg) {
73-
return this.create(this._ENC_XFORM_MODE, key, cfg);
73+
return new this(this._ENC_XFORM_MODE, key, cfg);
7474
}
7575

7676
/**
@@ -88,7 +88,7 @@ export class Cipher extends BufferedBlockAlgorithm {
8888
* const cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray });
8989
*/
9090
static createDecryptor(key, cfg) {
91-
return this.create(this._DEC_XFORM_MODE, key, cfg);
91+
return new this(this._DEC_XFORM_MODE, key, cfg);
9292
}
9393

9494
/**
@@ -221,7 +221,7 @@ export class BlockCipherMode extends Base {
221221
*
222222
* @example
223223
*
224-
* const mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words);
224+
* const mode = new BlockCipherMode(cipher, iv.words);
225225
*/
226226
constructor(cipher, iv) {
227227
super();
@@ -243,7 +243,7 @@ export class BlockCipherMode extends Base {
243243
* const mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words);
244244
*/
245245
static createEncryptor(cipher, iv) {
246-
return this.Encryptor.create(cipher, iv);
246+
return new this.Encryptor(cipher, iv);
247247
}
248248

249249
/**
@@ -259,7 +259,7 @@ export class BlockCipherMode extends Base {
259259
* const mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words);
260260
*/
261261
static createDecryptor(cipher, iv) {
262-
return this.Decryptor.create(cipher, iv);
262+
return new this.Decryptor(cipher, iv);
263263
}
264264
}
265265

@@ -390,7 +390,7 @@ export const Pkcs7 = {
390390
for (let i = 0; i < nPaddingBytes; i += 4) {
391391
paddingWords.push(paddingWord);
392392
}
393-
const padding = WordArray.create(paddingWords, nPaddingBytes);
393+
const padding =new WordArray(paddingWords, nPaddingBytes);
394394

395395
// Add padding
396396
data.concat(padding);
@@ -524,7 +524,7 @@ export class CipherParams extends Base {
524524
*
525525
* @example
526526
*
527-
* var cipherParams = CryptoJS.lib.CipherParams.create({
527+
* let cipherParams =new CipherParams({
528528
* ciphertext: ciphertextWordArray,
529529
* key: keyWordArray,
530530
* iv: ivWordArray,
@@ -553,9 +553,9 @@ export class CipherParams extends Base {
553553
*
554554
* @example
555555
*
556-
* var string = cipherParams + '';
557-
* var string = cipherParams.toString();
558-
* var string = cipherParams.toString(CryptoJS.format.OpenSSL);
556+
* let string = cipherParams + '';
557+
* let string = cipherParams.toString();
558+
* let string = cipherParams.toString(CryptoJS.format.OpenSSL);
559559
*/
560560
toString(formatter) {
561561
return (formatter || this.formatter).stringify(this);
@@ -577,7 +577,7 @@ export const OpenSSLFormatter = {
577577
*
578578
* @example
579579
*
580-
* var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams);
580+
* let openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams);
581581
*/
582582
stringify(cipherParams) {
583583
let wordArray;
@@ -590,7 +590,7 @@ export const OpenSSLFormatter = {
590590

591591
// Format
592592
if (salt) {
593-
wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext);
593+
wordArray =new WordArray([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext);
594594
} else {
595595
wordArray = ciphertext;
596596
}
@@ -609,7 +609,7 @@ export const OpenSSLFormatter = {
609609
*
610610
* @example
611611
*
612-
* var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString);
612+
* let cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString);
613613
*/
614614
parse(openSSLStr) {
615615
let salt;
@@ -623,14 +623,14 @@ export const OpenSSLFormatter = {
623623
// Test for salt
624624
if (ciphertextWords[0] === 0x53616c74 && ciphertextWords[1] === 0x65645f5f) {
625625
// Extract salt
626-
salt = WordArray.create(ciphertextWords.slice(2, 4));
626+
salt =new WordArray(ciphertextWords.slice(2, 4));
627627

628628
// Remove salt from ciphertext
629629
ciphertextWords.splice(0, 4);
630630
ciphertext.sigBytes -= 16;
631631
}
632632

633-
return CipherParams.create({
633+
return new CipherParams({
634634
ciphertext,
635635
salt
636636
});
@@ -655,11 +655,11 @@ export class SerializableCipher extends Base {
655655
*
656656
* @example
657657
*
658-
* var ciphertextParams = CryptoJS.lib.SerializableCipher
658+
* let ciphertextParams = CryptoJS.lib.SerializableCipher
659659
* .encrypt(CryptoJS.algo.AES, message, key);
660-
* var ciphertextParams = CryptoJS.lib.SerializableCipher
660+
* let ciphertextParams = CryptoJS.lib.SerializableCipher
661661
* .encrypt(CryptoJS.algo.AES, message, key, { iv: iv });
662-
* var ciphertextParams = CryptoJS.lib.SerializableCipher
662+
* let ciphertextParams = CryptoJS.lib.SerializableCipher
663663
* .encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL });
664664
*/
665665
static encrypt(cipher, message, key, cfg) {
@@ -674,7 +674,7 @@ export class SerializableCipher extends Base {
674674
const cipherCfg = encryptor.cfg;
675675

676676
// Create and return serializable cipher params
677-
return CipherParams.create({
677+
return new CipherParams({
678678
ciphertext,
679679
key,
680680
iv: cipherCfg.iv,
@@ -700,10 +700,10 @@ export class SerializableCipher extends Base {
700700
*
701701
* @example
702702
*
703-
* var plaintext = CryptoJS.lib.SerializableCipher
703+
* let plaintext = CryptoJS.lib.SerializableCipher
704704
* .decrypt(CryptoJS.algo.AES, formattedCiphertext, key,
705705
* { iv: iv, format: CryptoJS.format.OpenSSL });
706-
* var plaintext = CryptoJS.lib.SerializableCipher
706+
* let plaintext = CryptoJS.lib.SerializableCipher
707707
* .decrypt(CryptoJS.algo.AES, ciphertextParams, key,
708708
* { iv: iv, format: CryptoJS.format.OpenSSL });
709709
*/
@@ -735,7 +735,7 @@ export class SerializableCipher extends Base {
735735
*
736736
* @example
737737
*
738-
* var ciphertextParams = CryptoJS.lib.SerializableCipher
738+
* let ciphertextParams = CryptoJS.lib.SerializableCipher
739739
* ._parse(ciphertextStringOrParams, format);
740740
*/
741741
static _parse(ciphertext, format) {
@@ -778,8 +778,8 @@ export const OpenSSLKdf = {
778778
*
779779
* @example
780780
*
781-
* var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32);
782-
* var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt');
781+
* let derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32);
782+
* let derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt');
783783
*/
784784
execute(password, keySize, ivSize, salt) {
785785
let _salt = salt;
@@ -790,16 +790,16 @@ export const OpenSSLKdf = {
790790
}
791791

792792
// Derive key and IV
793-
const key = EvpKDFAlgo.create({
793+
const key =new EvpKDFAlgo({
794794
keySize: keySize + ivSize
795795
}).compute(password, _salt);
796796

797797
// Separate key and IV
798-
const iv = WordArray.create(key.words.slice(keySize), ivSize * 4);
798+
const iv =new WordArray(key.words.slice(keySize), ivSize * 4);
799799
key.sigBytes = keySize * 4;
800800

801801
// Return params
802-
return CipherParams.create({
802+
return new CipherParams({
803803
key,
804804
iv,
805805
salt: _salt
@@ -826,9 +826,9 @@ export class PasswordBasedCipher extends SerializableCipher {
826826
*
827827
* @example
828828
*
829-
* var ciphertextParams = CryptoJS.lib.PasswordBasedCipher
829+
* let ciphertextParams = CryptoJS.lib.PasswordBasedCipher
830830
* .encrypt(CryptoJS.algo.AES, message, 'password');
831-
* var ciphertextParams = CryptoJS.lib.PasswordBasedCipher
831+
* let ciphertextParams = CryptoJS.lib.PasswordBasedCipher
832832
* .encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL });
833833
*/
834834
static encrypt(cipher, message, password, cfg) {
@@ -865,10 +865,10 @@ export class PasswordBasedCipher extends SerializableCipher {
865865
*
866866
* @example
867867
*
868-
* var plaintext = CryptoJS.lib.PasswordBasedCipher
868+
* let plaintext = CryptoJS.lib.PasswordBasedCipher
869869
* .decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password',
870870
* { format: CryptoJS.format.OpenSSL });
871-
* var plaintext = CryptoJS.lib.PasswordBasedCipher
871+
* let plaintext = CryptoJS.lib.PasswordBasedCipher
872872
* .decrypt(CryptoJS.algo.AES, ciphertextParams, 'password',
873873
* { format: CryptoJS.format.OpenSSL });
874874
*/

0 commit comments

Comments
 (0)