~ubuntu-branches/ubuntu/trusty/enigmail/trusty-updates

« back to all changes in this revision

Viewing changes to services/crypto/tests/unit/test_crypto_random.js

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2011-06-07 14:35:53 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: package-import@ubuntu.com-20110607143553-fbgqhhvh8g8h6j1y
Tags: 2:1.2~a2~cvs20110606t2200-0ubuntu1
* Update to latest trunk snapshot for Thunderbird beta compat

* Remove build/pgo/profileserver.py from debian/clean. The new build
  system has a target depending on this
  - update debian/clean
* Drop debian/patches/autoconf.diff, just generate this at build time
* Refresh debian/patches/build_system_dont_link_libxul.diff
* libipc seems to be renamed to libipc-pipe. Fix genxpi and chrome.manifest
  to fix this 
  - add debian/patches/ipc-pipe_rename.diff
  - update debian/patches/series
* The makefiles in extensions/enigmail/ipc have an incorrect DEPTH
  attribute. Fix this so that they can find the rest of the build system
  - add debian/patches/makefile_depth.diff
  - update debian/patches/series
* Drop debian/patches/makefile-in-empty-xpcom-fix.diff - fixed in the
  current version
* Don't register a class ID multiple times, as this breaks enigmail entirely
  - add debian/patches/dont_register_cids_multiple_times.diff
  - update debian/patches/series
* Look for the Thunderbird 5 SDK
  - update debian/rules
  - update debian/control
* Run autoconf2.13 at build time
  - update debian/rules
  - update debian/control
* Add useless mesa-common-dev build-dep, just to satisfy the build system.
  We should just patch this out entirely really, but that's for another upload
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
let cryptoSvc;
 
2
try {
 
3
  Components.utils.import("resource://services-crypto/WeaveCrypto.js");
 
4
  cryptoSvc = new WeaveCrypto();
 
5
} catch (ex) {
 
6
  // Fallback to binary WeaveCrypto
 
7
  cryptoSvc = Cc["@labs.mozilla.com/Weave/Crypto;1"]
 
8
                .getService(Ci.IWeaveCrypto);
 
9
}
 
10
 
 
11
function run_test() {
 
12
  if (this.gczeal) {
 
13
    _("Running crypto random tests with gczeal(2).");
 
14
    gczeal(2);
 
15
  }
 
16
 
 
17
  // Test salt generation.
 
18
  var salt;
 
19
 
 
20
  salt = cryptoSvc.generateRandomBytes(0);
 
21
  do_check_eq(salt.length, 0);
 
22
  salt = cryptoSvc.generateRandomBytes(1);
 
23
  do_check_eq(salt.length, 4);
 
24
  salt = cryptoSvc.generateRandomBytes(2);
 
25
  do_check_eq(salt.length, 4);
 
26
  salt = cryptoSvc.generateRandomBytes(3);
 
27
  do_check_eq(salt.length, 4);
 
28
  salt = cryptoSvc.generateRandomBytes(4);
 
29
  do_check_eq(salt.length, 8);
 
30
  salt = cryptoSvc.generateRandomBytes(8);
 
31
  do_check_eq(salt.length, 12);
 
32
 
 
33
  // sanity check to make sure salts seem random
 
34
  var salt2 = cryptoSvc.generateRandomBytes(8);
 
35
  do_check_eq(salt2.length, 12);
 
36
  do_check_neq(salt, salt2);
 
37
 
 
38
  salt = cryptoSvc.generateRandomBytes(1024);
 
39
  do_check_eq(salt.length, 1368);
 
40
  salt = cryptoSvc.generateRandomBytes(16);
 
41
  do_check_eq(salt.length, 24);
 
42
 
 
43
 
 
44
  // Test random key generation
 
45
  var keydata, keydata2, iv;
 
46
 
 
47
  keydata  = cryptoSvc.generateRandomKey();
 
48
  do_check_eq(keydata.length, 44);
 
49
  keydata2 = cryptoSvc.generateRandomKey();
 
50
  do_check_neq(keydata, keydata2); // sanity check for randomness
 
51
  iv = cryptoSvc.generateRandomIV();
 
52
  do_check_eq(iv.length, 24);
 
53
 
 
54
  cryptoSvc.algorithm = Ci.IWeaveCrypto.AES_256_CBC;
 
55
  keydata  = cryptoSvc.generateRandomKey();
 
56
  do_check_eq(keydata.length, 44);
 
57
  keydata2 = cryptoSvc.generateRandomKey();
 
58
  do_check_neq(keydata, keydata2); // sanity check for randomness
 
59
  iv = cryptoSvc.generateRandomIV();
 
60
  do_check_eq(iv.length, 24);
 
61
 
 
62
  if (this.gczeal)
 
63
    gczeal(0);
 
64
}