-
Notifications
You must be signed in to change notification settings - Fork 48
/
jwsjs-1.0.min.js
3 lines (3 loc) · 2.12 KB
/
jwsjs-1.0.min.js
1
2
3
/*! jwsjs-1.1 (c) 2012 Kenji Urushima | kjur.github.com/jsjws/license
*/
function _jwsjs_init(){this.aHeader=[];this.sPayload="";this.aSignature=[]}function _jwsjs_initWithJWS(b){this.init();var a=new JWS();a.parseJWS(b);this.aHeader.push(a.parsedJWS.headB64U);this.sPayload=a.parsedJWS.payloadB64U;this.aSignature.push(a.parsedJWS.sigvalB64U)}function _jwsjs_addSignatureByHeaderKey(d,a){var c=b64utoutf8(this.sPayload);var b=new JWS();var e=b.generateJWSByP1PrvKey(d,c,a);this.aHeader.push(b.parsedJWS.headB64U);this.aSignature.push(b.parsedJWS.sigvalB64U)}function _jwsjs_addSignatureByHeaderPayloadKey(d,c,a){var b=new JWS();var e=b.generateJWSByP1PrvKey(d,c,a);this.aHeader.push(b.parsedJWS.headB64U);this.sPayload=b.parsedJWS.payloadB64U;this.aSignature.push(b.parsedJWS.sigvalB64U)}function _jwsjs_verifyWithCerts(b){if(this.aHeader.length!=b.length){throw"num headers does not match with num certs"}if(this.aSignature.length!=b.length){throw"num signatures does not match with num certs"}var j=this.sPayload;var f="";for(var c=0;c<b.length;c++){var d=b[c];var e=this.aHeader[c];var l=this.aSignature[c];var a=e+"."+j+"."+l;var h=new JWS();try{var k=h.verifyJWSByPemX509Cert(a,d);if(k!=1){f+=(c+1)+"th signature unmatch. "}}catch(g){f+=(c+1)+"th signature fail("+g+"). "}}if(f==""){return 1}else{throw f}}function _jwsjs_readJWSJS(a){var c=new JWS();var b=c.readSafeJSONString(a);if(b==null){throw"argument is not JSON string: "+a}this.aHeader=b.headers;this.sPayload=b.payload;this.aSignature=b.signatures}function _jwsjs_getJSON(){return{headers:this.aHeader,payload:this.sPayload,signatures:this.aSignature}}function _jwsjs_isEmpty(){if(this.aHeader.length==0){return 1}return 0}function JWSJS(){this.aHeader=[];this.sPayload="";this.aSignature=[]}JWSJS.prototype.init=_jwsjs_init;JWSJS.prototype.initWithJWS=_jwsjs_initWithJWS;JWSJS.prototype.addSignatureByHeaderKey=_jwsjs_addSignatureByHeaderKey;JWSJS.prototype.addSignatureByHeaderPayloadKey=_jwsjs_addSignatureByHeaderPayloadKey;JWSJS.prototype.getJSON=_jwsjs_getJSON;JWSJS.prototype.readJWSJS=_jwsjs_readJWSJS;JWSJS.prototype.verifyWithCerts=_jwsjs_verifyWithCerts;JWSJS.prototype.isEmpty=_jwsjs_isEmpty;