hmac.js 1.6 KB

1
  1. (function(){function m(c){var k=c.jsustoolkitErrCode=c.jsustoolkitErrCode||{};(c.hmac=c.hmac||{}).create=function(){var a=null,g=null,e=null,h={start:function(b,d){if(null!==b)if(b.constructor==String)if(b=b.toLowerCase(),b in c.md.algorithms)a=c.md.algorithms[b].create();else throw{code:"103006",message:k["103006"]};else a=b;if(null!==d){if(d.constructor==String)d=c.util.createBuffer(d);else if(d.constructor==Array){b=d;d=c.util.createBuffer();for(var f=0;f<b.length;++f)d.putByte(b[f])}var h=d.length();h>a.blockLength&&(a.start(),a.update(d.bytes()),d=a.digest());g=c.util.createBuffer();e=c.util.createBuffer();h=d.length();for(f=0;f<h;++f)b=d.at(f),g.putByte(54^b),e.putByte(92^b);if(h<a.blockLength)for(b=a.blockLength-h,f=0;f<b;++f)g.putByte(54),e.putByte(92);g=g.bytes();e=e.bytes()}a.start();a.update(g)},update:function(b){if(null==b)throw{code:"103004",message:k["103004"]};if("undefined"==typeof a)throw{code:"103005",message:k["103005"]};a.update(b)},getMac:function(){var b=a.digest().bytes();a.start();a.update(e);a.update(b);return a.digest()}};h.digest=h.getMac;return h}}var n=["./md","./util"],l=null;"function"!==typeof define&&("object"===typeof module&&module.exports?l=function(c,k){k(require,module)}:(crosscert=window.crosscert=window.crosscert||{},m(crosscert)));(l||"function"===typeof define)&&(l||define)(["require","module"].concat(n),function(c,k){k.exports=function(a){var g=n.map(function(a){return c(a)}).concat(m);a=a||{};a.defined=a.defined||{};if(a.defined.hmac)return a.hmac;a.defined.hmac=!0;for(var e=0;e<g.length;++e)g[e](a);return a.hmac}})})();