aboutsummaryrefslogtreecommitdiffstats
path: root/js/crypto.js
diff options
context:
space:
mode:
authorChristian Vogeley <christian.vogeley@hotmail.de>2013-12-22 14:31:27 +0100
committerChristian Vogeley <christian.vogeley@hotmail.de>2013-12-22 14:31:27 +0100
commit870df76463a1cc9823b364db0bfb387f3f46664f (patch)
treea8c7391bfe799703aa0a8f26b9ee788f1204e8be /js/crypto.js
parent25a533bd72c34e9775af71c010a39db6caf7b633 (diff)
parent7e7b5bfa4930493a8feae10b0550e29797956c70 (diff)
downloadvolse-hubzilla-870df76463a1cc9823b364db0bfb387f3f46664f.tar.gz
volse-hubzilla-870df76463a1cc9823b364db0bfb387f3f46664f.tar.bz2
volse-hubzilla-870df76463a1cc9823b364db0bfb387f3f46664f.zip
Merge remote-tracking branch 'upstream/master' into bootstrap
Conflicts: view/php/theme_init.php
Diffstat (limited to 'js/crypto.js')
-rw-r--r--js/crypto.js46
1 files changed, 33 insertions, 13 deletions
diff --git a/js/crypto.js b/js/crypto.js
index a7b278537..a144e03ea 100644
--- a/js/crypto.js
+++ b/js/crypto.js
@@ -18,6 +18,11 @@ function str_rot13 (str) {
}
+// Arrays for pluggable encryptors/decryptors
+
+var red_encryptors = new Array();
+var red_decryptors = new Array();
+
// We probably just want the element where the text is and find it ourself. e.g. if
// there is highlighted text use it, otherwise use the entire text.
// So the third element may be useless. Fix also in view/tpl/jot.tpl before
@@ -86,6 +91,13 @@ function red_encrypt(alg, elem,text) {
newdiv = "[crypt alg='3des' hint='" + enc_hint + "']" + encrypted + '[/crypt]';
}
+ if((red_encryptors.length) && (! newdiv.length)) {
+ for(var i = 0; i < red_encryptors.length; i ++) {
+ newdiv = red_encryptors[i](alg,text);
+ if(newdiv.length)
+ break;
+ }
+ }
enc_key = '';
@@ -118,22 +130,30 @@ function red_encrypt(alg, elem,text) {
function red_decrypt(alg,hint,text,elem) {
- var enc_text = '';
+ var dec_text = '';
if(alg == 'rot13' || alg == 'triple-rot13')
- enc_text = str_rot13(text);
+ dec_text = str_rot13(text);
+ else {
+ var enc_key = prompt((hint.length) ? hint : aStr['passphrase']);
+ }
if(alg == 'aes256') {
- var enc_key = prompt((hint.length) ? hint : aStr['passphrase']);
- enc_text = CryptoJS.AES.decrypt(text,enc_key);
+ dec_text = CryptoJS.AES.decrypt(text,enc_key);
}
if(alg == 'rabbit') {
- var enc_key = prompt((hint.length) ? hint : aStr['passphrase']);
- enc_text = CryptoJS.Rabbit.decrypt(text,enc_key);
+ dec_text = CryptoJS.Rabbit.decrypt(text,enc_key);
}
if(alg == '3des') {
- var enc_key = prompt((hint.length) ? hint : aStr['passphrase']);
- enc_text = CryptoJS.TripleDES.decrypt(text,enc_key);
+ dec_text = CryptoJS.TripleDES.decrypt(text,enc_key);
+ }
+
+ if((red_decryptors.length) && (! dec_text.length)) {
+ for(var i = 0; i < red_decryptors.length; i ++) {
+ dec_text = red_decryptors[i](alg,text,enc_key);
+ if(dec_text.length)
+ break;
+ }
}
enc_key = '';
@@ -144,16 +164,16 @@ function red_decrypt(alg,hint,text,elem) {
// wipe out the text and make you re-enter the key if it was in the
// conversation. For now we do that so you can read it.
- var enc_result = enc_text.toString(CryptoJS.enc.Utf8);
- delete enc_text;
+ var dec_result = dec_text.toString(CryptoJS.enc.Utf8);
+ delete dec_text;
// incorrect decryptions *usually* but don't always have zero length
// If the person typo'd let them try again without reloading the page
// otherwise they'll have no "padlock" to click to try again.
- if(enc_result.length) {
- $(elem).html(b2h(enc_result));
- enc_result = '';
+ if(dec_result.length) {
+ $(elem).html(b2h(dec_result));
+ dec_result = '';
}
}