Handle wrong UTF8 encodings gracefully

This commit is contained in:
Thomas Oberndörfer 2013-07-12 14:59:38 +02:00
parent a2db324605
commit 322f57cc17
3 changed files with 14 additions and 6 deletions

View File

@ -7383,7 +7383,7 @@ function openpgp_config() {
keyserver: "keyserver.linux.it" // "pgp.mit.edu:11371"
};
this.versionstring ="OpenPGP.js v.1.20130627";
this.versionstring ="OpenPGP.js v.1.20130712";
this.commentstring ="http://openpgpjs.org";
/**
* Reads the config out of the HTML5 local storage
@ -13204,7 +13204,11 @@ var Util = function() {
* @return {String} A native javascript string
*/
this.decode_utf8 = function(utf8) {
return decodeURIComponent(escape(utf8));
try {
return decodeURIComponent(escape(utf8));
} catch (e) {
return utf8;
}
};
var str2bin = function(str, result) {

View File

@ -285,7 +285,7 @@ JXG.Util.asciiCharCodeAt=function(b,a){var c=b.charCodeAt(a);if(255<c)switch(c){
151;break;case 732:c=152;break;case 8482:c=153;break;case 353:c=154;break;case 8250:c=155;break;case 339:c=156;break;case 382:c=158;break;case 376:c=159}return c};
JXG.Util.utf8Decode=function(b){var a=[],c=0,d=0,e=0,f;if(!JXG.exists(b))return"";for(;c<b.length;)d=b.charCodeAt(c),128>d?(a.push(String.fromCharCode(d)),c++):191<d&&224>d?(e=b.charCodeAt(c+1),a.push(String.fromCharCode((d&31)<<6|e&63)),c+=2):(e=b.charCodeAt(c+1),f=b.charCodeAt(c+2),a.push(String.fromCharCode((d&15)<<12|(e&63)<<6|f&63)),c+=3);return a.join("")};
JXG.Util.genUUID=function(){for(var b="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),a=Array(36),c=0,d,e=0;36>e;e++)8==e||13==e||18==e||23==e?a[e]="-":14==e?a[e]="4":(2>=c&&(c=33554432+16777216*Math.random()|0),d=c&15,c>>=4,a[e]=b[19==e?d&3|8:d]);return a.join("")};
function openpgp_config(){this.config=null;this.default_config={prefer_hash_algorithm:8,encryption_cipher:9,compression:1,show_version:!0,show_comment:!0,integrity_protect:!0,composition_behavior:0,keyserver:"keyserver.linux.it"};this.versionstring="OpenPGP.js v.1.20130627";this.commentstring="http://openpgpjs.org";this.debug=!1;this.read=function(){var b=JSON.parse(window.localStorage.getItem("config"));null==b?(this.config=this.default_config,this.write()):this.config=b};this.write=function(){window.localStorage.setItem("config",
function openpgp_config(){this.config=null;this.default_config={prefer_hash_algorithm:8,encryption_cipher:9,compression:1,show_version:!0,show_comment:!0,integrity_protect:!0,composition_behavior:0,keyserver:"keyserver.linux.it"};this.versionstring="OpenPGP.js v.1.20130712";this.commentstring="http://openpgpjs.org";this.debug=!1;this.read=function(){var b=JSON.parse(window.localStorage.getItem("config"));null==b?(this.config=this.default_config,this.write()):this.config=b};this.write=function(){window.localStorage.setItem("config",
JSON.stringify(this.config))}}var b64s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function s2r(b){var a,c,d,e="",f=0,g=0,h=b.length;for(d=0;d<h;d++)c=b.charCodeAt(d),0==g?(e+=b64s.charAt(c>>2&63),a=(c&3)<<4):1==g?(e+=b64s.charAt(a|c>>4&15),a=(c&15)<<2):2==g&&(e+=b64s.charAt(a|c>>6&3),f+=1,0==f%60&&(e+="\n"),e+=b64s.charAt(c&63)),f+=1,0==f%60&&(e+="\n"),g+=1,3==g&&(g=0);0<g&&(e+=b64s.charAt(a),f+=1,0==f%60&&(e+="\n"),e+="=",f+=1);1==g&&(0==f%60&&(e+="\n"),e+="=");return e}
function r2s(b){var a,c,d="",e=0,f=0,g=b.length;for(c=0;c<g;c++)a=b64s.indexOf(b.charAt(c)),0<=a&&(e&&(d+=String.fromCharCode(f|a>>6-e&255)),e=e+2&7,f=a<<e&255);return d}
function openpgp_encoding_deArmor(b){var b=b.replace(/\r/g,""),b=b.replace(/\n\s+\n/,"\n\n"),a=openpgp_encoding_get_type(b);if(2!=a){b=b.split("-----");a={openpgp:openpgp_encoding_base64_decode(b[2].split("\n\n")[1].split("\n=")[0].replace(/\n- /g,"\n")),type:a};if(verifyCheckSum(a.openpgp,b[2].split("\n\n")[1].split("\n=")[1].split("\n")[0]))return a;util.print_error("Ascii armor integrity check on message failed: '"+b[2].split("\n\n")[1].split("\n=")[1].split("\n")[0]+"' should be '"+getCheckSum(a));
@ -464,8 +464,8 @@ function openpgp_type_s2k(){this.read=function(b,a){var c=a;this.type=b[c++].cha
a){b=util.encode_utf8(b);if(0==this.type)return openpgp_crypto_hashData(this.hashAlgorithm,b);if(1==this.type)return openpgp_crypto_hashData(this.hashAlgorithm,this.saltValue+b);if(3==this.type){var c=[];for(c[0]=this.saltValue+b;c.length*(this.saltValue+b).length<this.count;)c.push(this.saltValue+b);c=c.join("");c.length>this.count&&(c=c.substr(0,this.count));return a&&(24==a||32==a)?openpgp_crypto_hashData(this.hashAlgorithm,c)+openpgp_crypto_hashData(this.hashAlgorithm,String.fromCharCode(0)+c):
openpgp_crypto_hashData(this.hashAlgorithm,c)}return null}}
var Util=function(){this.emailRegEx=/[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;this.hexdump=function(a){for(var b=[],e=a.length,f=0,g,h=0;f<e;){for(g=a.charCodeAt(f++).toString(16);2>g.length;)g="0"+g;b.push(" "+g);h++;0==h%32&&b.push("\n ")}return b.join("")};this.hexstrdump=function(a){if(null==a)return"";for(var b=[],e=a.length,f=0,g;f<e;){for(g=a[f++].charCodeAt().toString(16);2>g.length;)g=
"0"+g;b.push(""+g)}return b.join("")};this.hex2bin=function(a){for(var b="",e=0;e<a.length;e+=2)b+=String.fromCharCode(parseInt(a.substr(e,2),16));return b};this.hexidump=function(a){for(var b=[],e=a.length,f=0,g;f<e;){for(g=a[f++].toString(16);2>g.length;)g="0"+g;b.push(""+g)}return b.join("")};this.encode_utf8=function(a){return unescape(encodeURIComponent(a))};this.decode_utf8=function(a){return decodeURIComponent(escape(a))};var b=function(a,b){for(var e=0;e<a.length;e++)b[e]=a.charCodeAt(e);
return b},a=function(a){for(var b=[],e=0;e<a.length;e++)b.push(String.fromCharCode(a[e]));return b.join("")};this.str2bin=function(a){return b(a,Array(a.length))};this.bin2str=a;this.str2Uint8Array=function(a){return b(a,new Uint8Array(new ArrayBuffer(a.length)))};this.Uint8Array2str=a;this.calc_checksum=function(a){for(var b={s:0,add:function(a){this.s=(this.s+a)%65536}},e=0;e<a.length;e++)b.add(a.charCodeAt(e));return b.s};this.print_debug=function(a){openpgp.config.debug&&(a=openpgp_encoding_html_encode(a),
"0"+g;b.push(""+g)}return b.join("")};this.hex2bin=function(a){for(var b="",e=0;e<a.length;e+=2)b+=String.fromCharCode(parseInt(a.substr(e,2),16));return b};this.hexidump=function(a){for(var b=[],e=a.length,f=0,g;f<e;){for(g=a[f++].toString(16);2>g.length;)g="0"+g;b.push(""+g)}return b.join("")};this.encode_utf8=function(a){return unescape(encodeURIComponent(a))};this.decode_utf8=function(a){try{return decodeURIComponent(escape(a))}catch(b){return a}};var b=function(a,b){for(var e=0;e<a.length;e++)b[e]=
a.charCodeAt(e);return b},a=function(a){for(var b=[],e=0;e<a.length;e++)b.push(String.fromCharCode(a[e]));return b.join("")};this.str2bin=function(a){return b(a,Array(a.length))};this.bin2str=a;this.str2Uint8Array=function(a){return b(a,new Uint8Array(new ArrayBuffer(a.length)))};this.Uint8Array2str=a;this.calc_checksum=function(a){for(var b={s:0,add:function(a){this.s=(this.s+a)%65536}},e=0;e<a.length;e++)b.add(a.charCodeAt(e));return b.s};this.print_debug=function(a){openpgp.config.debug&&(a=openpgp_encoding_html_encode(a),
showMessages('<tt><p style="background-color: #ffffff; width: 652px; word-break: break-word; padding: 5px; border-bottom: 1px solid black;">'+a.replace(/\n/g,"<br>")+"</p></tt>"))};this.print_debug_hexstr_dump=function(a,b){openpgp.config.debug&&(a+=this.hexstrdump(b),a=openpgp_encoding_html_encode(a),showMessages('<tt><p style="background-color: #ffffff; width: 652px; word-break: break-word; padding: 5px; border-bottom: 1px solid black;">'+a.replace(/\n/g,"<br>")+"</p></tt>"))};this.print_error=
function(a){a=openpgp_encoding_html_encode(a);showMessages('<p style="font-size: 80%; background-color: #FF8888; margin:0; width: 652px; word-break: break-word; padding: 5px; border-bottom: 1px solid black;"><span style="color: #888;"><b>ERROR:</b></span>\t'+a.replace(/\n/g,"<br>")+"</p>")};this.print_info=function(a){a=openpgp_encoding_html_encode(a);showMessages('<p style="font-size: 80%; background-color: #88FF88; margin:0; width: 652px; word-break: break-word; padding: 5px; border-bottom: 1px solid black;"><span style="color: #888;"><b>INFO:</b></span>\t'+
a.replace(/\n/g,"<br>")+"</p>")};this.print_warning=function(a){a=openpgp_encoding_html_encode(a);showMessages('<p style="font-size: 80%; background-color: #FFAA88; margin:0; width: 652px; word-break: break-word; padding: 5px; border-bottom: 1px solid black;"><span style="color: #888;"><b>WARNING:</b></span>\t'+a.replace(/\n/g,"<br>")+"</p>")};this.getLeftNBits=function(a,b){var e=b%8;return 0==e?a.substring(0,b/8):this.shiftRight(a.substring(0,(b-e)/8+1),8-e)};this.shiftRight=function(a,b){var e=

View File

@ -102,7 +102,11 @@ var Util = function() {
* @return {String} A native javascript string
*/
this.decode_utf8 = function(utf8) {
return decodeURIComponent(escape(utf8));
try {
return decodeURIComponent(escape(utf8));
} catch (e) {
return utf8;
}
};
var str2bin = function(str, result) {