mirror of
https://github.com/emn178/js-sha512.git
synced 2026-08-12 20:31:34 +08:00
Added
- TypeScript definitions. - clone method. Changed - throw error if update after finalize
This commit is contained in:
+20
-1
@@ -203,9 +203,18 @@
|
||||
call: function (key, message) {
|
||||
var hash = algorithm.update(key, message);
|
||||
hash.hex();
|
||||
hash.update(message);
|
||||
hash.finalize();
|
||||
return hash.hex();
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'clone',
|
||||
call: function (key, message) {
|
||||
var hash = algorithm.update(key, message);
|
||||
var hash2 = hash.clone();
|
||||
hash.update('any');
|
||||
return hash2.hex();
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
@@ -250,6 +259,16 @@
|
||||
});
|
||||
});
|
||||
|
||||
context('when update after finalize', function () {
|
||||
it('should throw error', function () {
|
||||
expect(function () {
|
||||
var hash = algorithm.update('key', 'any');
|
||||
hash.hex();
|
||||
hash.update('any');
|
||||
}).to.throwError(/finalize already called/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#' + name, function () {
|
||||
errorTestCases.forEach(function (testCase) {
|
||||
context('when ' + testCase, function () {
|
||||
|
||||
+20
-1
@@ -260,9 +260,18 @@
|
||||
call: function (message) {
|
||||
var hash = algorithm.update(message);
|
||||
hash.hex();
|
||||
hash.update(message);
|
||||
hash.finalize();
|
||||
return hash.hex();
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'clone',
|
||||
call: function (message) {
|
||||
var hash = algorithm.update(message);
|
||||
var hash2 = hash.clone();
|
||||
hash.update('any');
|
||||
return hash2.hex();
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
@@ -317,6 +326,16 @@
|
||||
});
|
||||
});
|
||||
|
||||
context('when update after finalize', function () {
|
||||
it('should throw error', function () {
|
||||
expect(function () {
|
||||
var hash = algorithm.update('any');
|
||||
hash.hex();
|
||||
hash.update('any');
|
||||
}).to.throwError(/finalize already called/);
|
||||
});
|
||||
});
|
||||
|
||||
context('when large size', function () {
|
||||
var hash = algorithm.create();
|
||||
hash.bytes = 4294967295;
|
||||
|
||||
Reference in New Issue
Block a user