Login   Register  
Icontem

File: libs/js/pidCrypt/javascripts/compressed/asn1_c.js

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Jason Gerfen  >  jQuery.pidCrypt  >  libs/js/pidCrypt/javascripts/compressed/asn1_c.js  >  Download  
File: libs/js/pidCrypt/javascripts/compressed/asn1_c.js
Role: Application script
Content type: text/plain
Description: Application script
Class: jQuery.pidCrypt
Encrypt form values using RSA and AES
Author: By
Last change:
Date: 2012-05-21 06:18
Size: 8,620 bytes
 

Contents

Class file image Download
function Stream(a,b){if(a instanceof Stream){this.enc=a.enc;this.pos=a.pos}else{this.enc=a;this.pos=b}}Stream.prototype.parseStringHex=function(e,a){if(typeof(a)=="undefined"){a=this.enc.length}var d="";for(var b=e;b<a;++b){var c=this.get(b);d+=this.hexDigits.charAt(c>>4)+this.hexDigits.charAt(c&15)}return d};Stream.prototype.get=function(a){if(a==undefined){a=this.pos++}if(a>=this.enc.length){throw"Requesting byte offset "+a+" on a stream of length "+this.enc.length}return this.enc[a]};Stream.prototype.hexDigits="0123456789ABCDEF";Stream.prototype.hexDump=function(e,a){var d="";for(var b=e;b<a;++b){var c=this.get(b);d+=this.hexDigits.charAt(c>>4)+this.hexDigits.charAt(c&15);if((b&15)==7){d+=" "}d+=((b&15)==15)?"\n":" "}return d};Stream.prototype.parseStringISO=function(d,a){var c="";for(var b=d;b<a;++b){c+=String.fromCharCode(this.get(b))}return c};Stream.prototype.parseStringUTF=function(f,a){var d="",e=0;for(var b=f;b<a;){var e=this.get(b++);if(e<128){d+=String.fromCharCode(e)}else{if((e>191)&&(e<224)){d+=String.fromCharCode(((e&31)<<6)|(this.get(b++)&63))}else{d+=String.fromCharCode(((e&15)<<12)|((this.get(b++)&63)<<6)|(this.get(b++)&63))}}}return d};Stream.prototype.reTime=/^((?:1[89]|2\d)?\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/;Stream.prototype.parseTime=function(d,b){var c=this.parseStringISO(d,b);var a=this.reTime.exec(c);if(!a){return"Unrecognized time: "+c}c=a[1]+"-"+a[2]+"-"+a[3]+" "+a[4];if(a[5]){c+=":"+a[5];if(a[6]){c+=":"+a[6];if(a[7]){c+="."+a[7]}}}if(a[8]){c+=" UTC";if(a[8]!="Z"){c+=a[8];if(a[9]){c+=":"+a[9]}}}return c};Stream.prototype.parseInteger=function(d,a){if((a-d)>4){return undefined}var c=0;for(var b=d;b<a;++b){c=(c<<8)|this.get(b)}return c};Stream.prototype.parseOID=function(g,a){var d,f=0,e=0;for(var c=g;c<a;++c){var b=this.get(c);f=(f<<7)|(b&127);e+=7;if(!(b&128)){if(d==undefined){d=parseInt(f/40)+"."+(f%40)}else{d+="."+((e>=31)?"big":f)}f=e=0}d+=String.fromCharCode()}return d};if(typeof(pidCrypt)!="undefined"){pidCrypt.ASN1=function(d,e,c,a,b){this.stream=d;this.header=e;this.length=c;this.tag=a;this.sub=b};pidCrypt.ASN1.prototype.toHexTree=function(){var c={};c.type=this.typeName();if(c.type!="SEQUENCE"){c.value=this.stream.parseStringHex(this.posContent(),this.posEnd())}if(this.sub!=null){c.sub=[];for(var b=0,a=this.sub.length;b<a;++b){c.sub[b]=this.sub[b].toHexTree()}}return c};pidCrypt.ASN1.prototype.typeName=function(){if(this.tag==undefined){return"unknown"}var c=this.tag>>6;var a=(this.tag>>5)&1;var b=this.tag&31;switch(c){case 0:switch(b){case 0:return"EOC";case 1:return"BOOLEAN";case 2:return"INTEGER";case 3:return"BIT_STRING";case 4:return"OCTET_STRING";case 5:return"NULL";case 6:return"OBJECT_IDENTIFIER";case 7:return"ObjectDescriptor";case 8:return"EXTERNAL";case 9:return"REAL";case 10:return"ENUMERATED";case 11:return"EMBEDDED_PDV";case 12:return"UTF8String";case 16:return"SEQUENCE";case 17:return"SET";case 18:return"NumericString";case 19:return"PrintableString";case 20:return"TeletexString";case 21:return"VideotexString";case 22:return"IA5String";case 23:return"UTCTime";case 24:return"GeneralizedTime";case 25:return"GraphicString";case 26:return"VisibleString";case 27:return"GeneralString";case 28:return"UniversalString";case 30:return"BMPString";default:return"Universal_"+b.toString(16)}case 1:return"Application_"+b.toString(16);case 2:return"["+b+"]";case 3:return"Private_"+b.toString(16)}};pidCrypt.ASN1.prototype.content=function(){if(this.tag==undefined){return null}var d=this.tag>>6;if(d!=0){return null}var b=this.tag&31;var c=this.posContent();var a=Math.abs(this.length);switch(b){case 1:return(this.stream.get(c)==0)?"false":"true";case 2:return this.stream.parseInteger(c,c+a);case 6:return this.stream.parseOID(c,c+a);case 12:return this.stream.parseStringUTF(c,c+a);case 18:case 19:case 20:case 21:case 22:case 26:return this.stream.parseStringISO(c,c+a);case 23:case 24:return this.stream.parseTime(c,c+a)}return null};pidCrypt.ASN1.prototype.toString=function(){return this.typeName()+"@"+this.stream.pos+"[header:"+this.header+",length:"+this.length+",sub:"+((this.sub==null)?"null":this.sub.length)+"]"};pidCrypt.ASN1.prototype.print=function(b){if(b==undefined){b=""}document.writeln(b+this);if(this.sub!=null){b+="  ";for(var c=0,a=this.sub.length;c<a;++c){this.sub[c].print(b)}}};pidCrypt.ASN1.prototype.toPrettyString=function(b){if(b==undefined){b=""}var d=b+this.typeName()+" @"+this.stream.pos;if(this.length>=0){d+="+"}d+=this.length;if(this.tag&32){d+=" (constructed)"}else{if(((this.tag==3)||(this.tag==4))&&(this.sub!=null)){d+=" (encapsulates)"}}d+="\n";if(this.sub!=null){b+="  ";for(var c=0,a=this.sub.length;c<a;++c){d+=this.sub[c].toPrettyString(b)}}return d};pidCrypt.ASN1.prototype.toDOM=function(){var b=document.createElement("div");b.className="node";b.asn1=this;var g=document.createElement("div");g.className="head";var j=this.typeName();g.innerHTML=j;b.appendChild(g);this.head=g;var h=document.createElement("div");h.className="value";j="Offset: "+this.stream.pos+"<br/>";j+="Length: "+this.header+"+";if(this.length>=0){j+=this.length}else{j+=(-this.length)+" (undefined)"}if(this.tag&32){j+="<br/>(constructed)"}else{if(((this.tag==3)||(this.tag==4))&&(this.sub!=null)){j+="<br/>(encapsulates)"}}var e=this.content();if(e!=null){j+="<br/>Value:<br/><b>"+e+"</b>";if((typeof(oids)=="object")&&(this.tag==6)){var c=oids[e];if(c){if(c.d){j+="<br/>"+c.d}if(c.c){j+="<br/>"+c.c}if(c.w){j+="<br/>(warning!)"}}}}h.innerHTML=j;b.appendChild(h);var a=document.createElement("div");a.className="sub";if(this.sub!=null){for(var d=0,f=this.sub.length;d<f;++d){a.appendChild(this.sub[d].toDOM())}}b.appendChild(a);g.switchNode=b;g.onclick=function(){var i=this.switchNode;i.className=(i.className=="node collapsed")?"node":"node collapsed"};return b};pidCrypt.ASN1.prototype.posStart=function(){return this.stream.pos};pidCrypt.ASN1.prototype.posContent=function(){return this.stream.pos+this.header};pidCrypt.ASN1.prototype.posEnd=function(){return this.stream.pos+this.header+Math.abs(this.length)};pidCrypt.ASN1.prototype.toHexDOM_sub=function(d,c,e,f,a){if(f>=a){return}var b=document.createElement("span");b.className=c;b.appendChild(document.createTextNode(e.hexDump(f,a)));d.appendChild(b)};pidCrypt.ASN1.prototype.toHexDOM=function(){var d=document.createElement("span");d.className="hex";this.head.hexNode=d;this.head.onmouseover=function(){this.hexNode.className="hexCurrent"};this.head.onmouseout=function(){this.hexNode.className="hex"};this.toHexDOM_sub(d,"tag",this.stream,this.posStart(),this.posStart()+1);this.toHexDOM_sub(d,(this.length>=0)?"dlen":"ulen",this.stream,this.posStart()+1,this.posContent());if(this.sub==null){d.appendChild(document.createTextNode(this.stream.hexDump(this.posContent(),this.posEnd())))}else{if(this.sub.length>0){var e=this.sub[0];var c=this.sub[this.sub.length-1];this.toHexDOM_sub(d,"intro",this.stream,this.posContent(),e.posStart());for(var b=0,a=this.sub.length;b<a;++b){d.appendChild(this.sub[b].toHexDOM())}this.toHexDOM_sub(d,"outro",this.stream,c.posEnd(),this.posEnd())}}return d};pidCrypt.ASN1.decodeLength=function(d){var b=d.get();var a=b&127;if(a==b){return a}if(a>3){throw"Length over 24 bits not supported at position "+(d.pos-1)}if(a==0){return -1}b=0;for(var c=0;c<a;++c){b=(b<<8)|d.get()}return b};pidCrypt.ASN1.hasContent=function(b,a,g){if(b&32){return true}if((b<3)||(b>4)){return false}var f=new Stream(g);if(b==3){f.get()}var e=f.get();if((e>>6)&1){return false}try{var d=pidCrypt.ASN1.decodeLength(f);return((f.pos-g.pos)+d==a)}catch(c){return false}};pidCrypt.ASN1.decode=function(i){if(!(i instanceof Stream)){i=new Stream(i,0)}var h=new Stream(i);var k=i.get();var f=pidCrypt.ASN1.decodeLength(i);var d=i.pos-h.pos;var a=null;if(pidCrypt.ASN1.hasContent(k,f,i)){var b=i.pos;if(k==3){i.get()}a=[];if(f>=0){var c=b+f;while(i.pos<c){a[a.length]=pidCrypt.ASN1.decode(i)}if(i.pos!=c){throw"Content size is not correct for container starting at offset "+b}}else{try{for(;;){var j=pidCrypt.ASN1.decode(i);if(j.tag==0){break}a[a.length]=j}f=b-i.pos}catch(g){throw"Exception while decoding undefined length content: "+g}}}else{i.pos+=f}return new pidCrypt.ASN1(h,d,f,k,a)};pidCrypt.ASN1.test=function(){var f=[{value:[39],expected:39},{value:[129,201],expected:201},{value:[131,254,220,186],expected:16702650},];for(var c=0,a=f.length;c<a;++c){var e=0;var d=new Stream(f[c].value,0);var b=pidCrypt.ASN1.decodeLength(d);if(b!=f[c].expected){document.write("In test["+c+"] expected "+f[c].expected+" got "+b+"\n")}}}};