forked from brix/crypto-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpad-iso10126-test.js
50 lines (38 loc) · 1.63 KB
/
pad-iso10126-test.js
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
YUI.add('pad-iso10126-test', function (Y) {
var C = CryptoJS;
Y.Test.Runner.add(new Y.Test.Case({
name: 'Iso10126',
setUp: function () {
this.data = {};
// Save original random method
this.data.random = C.lib.WordArray.random;
// Replace random method with one that returns a predictable value
C.lib.WordArray.random = function (nBytes) {
var words = [];
for (var i = 0; i < nBytes; i += 4) {
words.push([0x11223344]);
}
return C.lib.WordArray.create(words, nBytes);
};
},
tearDown: function () {
// Restore random method
C.lib.WordArray.random = this.data.random;
},
testPad: function () {
var data = C.lib.WordArray.create([0xdddddd00], 3);
C.pad.Iso10126.pad(data, 2);
Y.Assert.areEqual(C.lib.WordArray.create([0xdddddd11, 0x22334405]).toString(), data.toString());
},
testPadClamp: function () {
var data = C.lib.WordArray.create([0xdddddddd, 0xdddddddd], 3);
C.pad.Iso10126.pad(data, 2);
Y.Assert.areEqual(C.lib.WordArray.create([0xdddddd11, 0x22334405]).toString(), data.toString());
},
testUnpad: function () {
var data = C.lib.WordArray.create([0xdddddd11, 0x22334405]);
C.pad.Iso10126.unpad(data);
Y.Assert.areEqual(C.lib.WordArray.create([0xdddddd00], 3).toString(), data.toString());
}
}));
}, '$Rev$');