Skip to content

Commit

Permalink
add 'create' to be more compatible with crypto-js
Browse files Browse the repository at this point in the history
fix #9
  • Loading branch information
PeterAlfredLee committed Aug 7, 2023
1 parent c018d05 commit 596159e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ export class Base {
Object.assign(clone, this);
return clone;
}

/**
* Get a new instance of this class.
* Arguments to create() will be passed to constructor.
*
* @return {Object} The new object.
*
* @static
*
* @example
*
* var instance = MyType.create();
*/
static create(...args) {
return new this(...args);
}
}

/**
Expand Down
10 changes: 10 additions & 0 deletions test/md5.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ describe('algo-md5-test', () => {
expect(md5.finalize().toString()).toBe('7d017545e0268a6a12f2b507871d0429');
});

test('testCreate', () => {
let i = 0;
const md5 = C.algo.MD5.create();
while (i < 100) {
md5.update('12345678901234567890123456789012345678901234567890');
i++;
}
expect(md5.finalize().toString()).toBe('7d017545e0268a6a12f2b507871d0429');
});

test('testInputIntegrity', () => {
const message = new C.lib.WordArray([0x12345678]);
const expected = message.toString();
Expand Down

0 comments on commit 596159e

Please sign in to comment.