forked from kjur/jsjws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjwsjs-2.0.min.js
executable file
·3 lines (3 loc) · 1.86 KB
/
jwsjs-2.0.min.js
1
2
3
/*! jwsjs-2.0.0 (c) 2013 Kenji Urushima | kjur.github.com/jsjws/license
*/
if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.jws=="undefined"||!KJUR.jws){KJUR.jws={}}KJUR.jws.JWSJS=function(){this.aHeader=[];this.sPayload="";this.aSignature=[];this.init=function(){this.aHeader=[];this.sPayload="";this.aSignature=[]};this.initWithJWS=function(b){this.init();var a=new KJUR.jws.JWS();a.parseJWS(b);this.aHeader.push(a.parsedJWS.headB64U);this.sPayload=a.parsedJWS.payloadB64U;this.aSignature.push(a.parsedJWS.sigvalB64U)};this.addSignatureByHeaderKey=function(d,a){var c=b64utoutf8(this.sPayload);var b=new KJUR.jws.JWS();var e=b.generateJWSByP1PrvKey(d,c,a);this.aHeader.push(b.parsedJWS.headB64U);this.aSignature.push(b.parsedJWS.sigvalB64U)};this.addSignatureByHeaderPayloadKey=function(d,c,a){var b=new KJUR.jws.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)};this.verifyWithCerts=function(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 KJUR.jws.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}};this.readJWSJS=function(a){var c=new KJUR.jws.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};this.getJSON=function(){return{headers:this.aHeader,payload:this.sPayload,signatures:this.aSignature}};this.isEmpty=function(){if(this.aHeader.length==0){return 1}return 0}};