Clone md5 function

pull/22/head
JettTeixeira 7 years ago
parent 0263ab835f
commit baceb77491

@ -203,6 +203,37 @@
this.first = true; this.first = true;
} }
/**
* @method clone
* @memberof Md5
* @description Return a copy of this object
* @returns {Md5} Md5 object
* @example
* hash.clone();
*/
Md5.prototype.clone = function() {
let nMd5 = new Md5();
if (ARRAY_BUFFER) {
var buffer = this.buffer8.buffer.slice();
nMd5.buffer8 = new Uint8Array(buffer);
nMd5.blocks = new Uint32Array(buffer);
} else {
nMd5.blocks = this.blocks.slice();
}
nMd5.bytes = this.bytes;
nMd5.finalized = this.finalized;
nMd5.first = this.first;
nMd5.h0 = this.h0;
nMd5.h1 = this.h1;
nMd5.h2 = this.h2;
nMd5.h3 = this.h3;
nMd5.hBytes = this.hBytes;
nMd5.hashed = this.hashed;
nMd5.start = this.start;
nMd5.lastByteIndex = this.lastByteIndex;
return nMd5;
}
/** /**
* @method update * @method update
* @memberof Md5 * @memberof Md5

@ -189,6 +189,14 @@
hash.update(message); hash.update(message);
return hash.hex(); return hash.hex();
} }
},
{
name: 'clone',
call: function (message) {
var hash = md5.update(message);
var copy = hash.clone();
return copy.hex();
}
} }
]; ];

Loading…
Cancel
Save