summaryrefslogtreecommitdiff
path: root/alarm/node_modules/node-forge/nodejs/test/sha1.js
blob: 3ffd985dce3a87b44241c5623f29e8a6cd590d08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
(function() {

function Tests(ASSERT, SHA1, UTIL) {
  describe('sha1', function() {
    it('should digest the empty string', function() {
      var md = SHA1.create();
      ASSERT.equal(
        md.digest().toHex(), 'da39a3ee5e6b4b0d3255bfef95601890afd80709');
    });

    it('should digest "abc"', function() {
      var md = SHA1.create();
      md.update('abc');
      ASSERT.equal(
        md.digest().toHex(), 'a9993e364706816aba3e25717850c26c9cd0d89d');
    });

    it('should digest "The quick brown fox jumps over the lazy dog"', function() {
      var md = SHA1.create();
      md.update('The quick brown fox jumps over the lazy dog');
      ASSERT.equal(
        md.digest().toHex(), '2fd4e1c67a2d28fced849ee1bb76e7391b93eb12');
    });

    it('should digest "c\'\u00e8"', function() {
      var md = SHA1.create();
      md.update("c\'\u00e8", 'utf8');
      ASSERT.equal(
        md.digest().toHex(), '98c9a3f804daa73b68a5660d032499a447350c0d');
    });

    it('should digest "THIS IS A MESSAGE"', function() {
      var md = SHA1.create();
      md.start();
      md.update('THIS IS ');
      md.update('A MESSAGE');
      // do twice to check continuing digest
      ASSERT.equal(
        md.digest().toHex(), '5f24f4d6499fd2d44df6c6e94be8b14a796c071d');
      ASSERT.equal(
        md.digest().toHex(), '5f24f4d6499fd2d44df6c6e94be8b14a796c071d');
    });

    it('should digest a long message', function() {
      // Note: might be too slow on old browsers
      var md = SHA1.create();
      md.update(UTIL.fillString('a', 1000000));
      ASSERT.equal(
        md.digest().toHex(), '34aa973cd4c4daa4f61eeb2bdbad27316534016f');
    });
  });
}

// check for AMD
if(typeof define === 'function') {
  define([
    'forge/sha1',
    'forge/util'
  ], function(SHA1, UTIL) {
    Tests(
      // Global provided by test harness
      ASSERT,
      SHA1(),
      UTIL()
    );
  });
} else if(typeof module === 'object' && module.exports) {
  // assume NodeJS
  Tests(
    require('assert'),
    require('../../js/sha1')(),
    require('../../js/util')());
}

})();