Fix crypto component to not mangle certain strings when doing 8/16 bit character conversion.

This commit is contained in:
Justin Dolske 2008-06-29 20:51:22 -07:00
parent dd7821e265
commit 777c82cf0b
2 changed files with 11 additions and 3 deletions

View File

@ -40,7 +40,7 @@
#include "nsISupports.idl" #include "nsISupports.idl"
[scriptable, uuid(d3b0f750-c976-46d0-be20-96b24f4684bc)] [scriptable, uuid(f4463043-315e-41f3-b779-82e900e6fffa)]
interface IWeaveCrypto : nsISupports interface IWeaveCrypto : nsISupports
{ {
/** /**
@ -80,7 +80,7 @@ interface IWeaveCrypto : nsISupports
* A base64-encoded initialization vector * A base64-encoded initialization vector
* @returns Encrypted data, base64 encoded * @returns Encrypted data, base64 encoded
*/ */
ACString encrypt(in ACString clearText, ACString encrypt(in AUTF8String clearText,
in ACString symmetricKey, in ACString iv); in ACString symmetricKey, in ACString iv);
/** /**
@ -95,7 +95,7 @@ interface IWeaveCrypto : nsISupports
* A base64-encoded initialization vector * A base64-encoded initialization vector
* @returns Decrypted data (not base64-encoded) * @returns Decrypted data (not base64-encoded)
*/ */
ACString decrypt(in ACString cipherText, AUTF8String decrypt(in ACString cipherText,
in ACString symmetricKey, in ACString iv); in ACString symmetricKey, in ACString iv);
/** /**

View File

@ -58,6 +58,14 @@ function run_test() {
do_check_eq(cipherText, "HeC7miVGDcpxae9RmiIKAw=="); do_check_eq(cipherText, "HeC7miVGDcpxae9RmiIKAw==");
do_check_eq(clearText, mySecret); do_check_eq(clearText, mySecret);
// Test non-ascii input
// ("testuser1" using similar-looking glyphs)
mySecret = String.fromCharCode(355, 277, 349, 357, 533, 537, 101, 345, 185);
cipherText = cryptoSvc.encrypt(mySecret, key, iv);
clearText = cryptoSvc.decrypt(cipherText, key, iv);
do_check_eq(cipherText, "Pj4ixByXoH3SU3JkOXaEKPgwRAWplAWFLQZkpJd5Kr4=");
do_check_eq(clearText, mySecret);
// Tests input spanning a block boundary (AES block size is 16 bytes) // Tests input spanning a block boundary (AES block size is 16 bytes)
mySecret = "123456789012345"; mySecret = "123456789012345";
cipherText = cryptoSvc.encrypt(mySecret, key, iv); cipherText = cryptoSvc.encrypt(mySecret, key, iv);