diff options
Diffstat (limited to 'core/convenience.js')
-rw-r--r-- | core/convenience.js | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/core/convenience.js b/core/convenience.js index 2a7a3f2..d97f9df 100644 --- a/core/convenience.js +++ b/core/convenience.js @@ -58,7 +58,8 @@ /* do the encryption */ p.ct = sjcl.mode[p.mode].encrypt(prp, plaintext, p.iv, p.adata, p.tag); - return j.encode(j._subtract(p, j.defaults)); + //return j.encode(j._subtract(p, j.defaults)); + return j.encode(p); }, /** Simple decryption function. @@ -122,7 +123,7 @@ if (!i.match(/^[a-z0-9]+$/i)) { throw new sjcl.exception.invalid("json encode: invalid property name"); } - out += comma + i + ':'; + out += comma + '"' + i + '":'; comma = ','; switch (typeof obj[i]) { @@ -160,13 +161,13 @@ } var a = str.replace(/^\{|\}$/g, '').split(/,/), out={}, i, m; for (i=0; i<a.length; i++) { - if (!(m=a[i].match(/^([a-z][a-z0-9]*):(?:(\d+)|"([a-z0-9+\/%*_.@=\-]*)")$/i))) { + if (!(m=a[i].match(/^(?:(["']?)([a-z][a-z0-9]*)\1):(?:(\d+)|"([a-z0-9+\/%*_.@=\-]*)")$/i))) { throw new sjcl.exception.invalid("json decode: this isn't json!"); } - if (m[2]) { - out[m[1]] = parseInt(m[2],10); + if (m[3]) { + out[m[2]] = parseInt(m[3],10); } else { - out[m[1]] = m[1].match(/^(ct|salt|iv)$/) ? sjcl.codec.base64.toBits(m[3]) : unescape(m[3]); + out[m[2]] = m[2].match(/^(ct|salt|iv)$/) ? sjcl.codec.base64.toBits(m[4]) : unescape(m[4]); } } return out; @@ -196,7 +197,6 @@ /** Remove all elements of minus from plus. Does not modify plus. * @private - */ _subtract: function (plus, minus) { var out = {}, i; @@ -208,6 +208,7 @@ return out; }, + */ /** Return only the specified elements of src. * @private |