Wei Lu
11 years ago
6 changed files with 63 additions and 63 deletions
@ -1,40 +1,27 @@ |
|||
var assert = require('assert') |
|||
var convert = require('../src/convert') |
|||
|
|||
describe('convert', function() { |
|||
describe('byte array and word array conversions', function(){ |
|||
var bytes, wordArray |
|||
|
|||
beforeEach(function(){ |
|||
bytes = [ |
|||
98, 233, 7, 177, 92, 191, 39, 213, 66, 83, |
|||
153, 235, 246, 240, 251, 80, 235, 184, 143, 24 |
|||
] |
|||
wordArray = { |
|||
words: [1659439025, 1556031445, 1112775147, -151979184, -340226280], |
|||
sigBytes: 20 |
|||
} |
|||
}) |
|||
var fixtures = require('./fixtures/convert') |
|||
|
|||
describe('bytesToWords', function() { |
|||
it('works', function() { |
|||
assert.deepEqual(convert.bytesToWordArray(bytes), wordArray) |
|||
}) |
|||
}) |
|||
describe('convert', function() { |
|||
describe('bufferToWordArray', function() { |
|||
fixtures.valid.forEach(function(f) { |
|||
it('converts ' + f.hex + ' correctly', function() { |
|||
var buffer = new Buffer(f.hex, 'hex') |
|||
var result = convert.bufferToWordArray(buffer) |
|||
|
|||
describe('bytesToWords', function() { |
|||
it('works', function() { |
|||
assert.deepEqual(convert.wordArrayToBytes(wordArray), bytes) |
|||
assert.deepEqual(result, f.wordArray) |
|||
}) |
|||
}) |
|||
}) |
|||
|
|||
describe('reverseEndian', function() { |
|||
it('works', function() { |
|||
var bigEndian = "6a4062273ac4f9ea4ffca52d9fd102b08f6c32faa0a4d1318e3a7b2e437bb9c7" |
|||
var littleEdian = "c7b97b432e7b3a8e31d1a4a0fa326c8fb002d19f2da5fc4feaf9c43a2762406a" |
|||
assert.deepEqual(convert.reverseEndian(bigEndian), littleEdian) |
|||
assert.deepEqual(convert.reverseEndian(littleEdian), bigEndian) |
|||
describe('wordArrayToBuffer', function() { |
|||
fixtures.valid.forEach(function(f) { |
|||
it('converts to ' + f.hex + ' correctly', function() { |
|||
var resultHex = convert.wordArrayToBuffer(f.wordArray).toString('hex') |
|||
|
|||
assert.deepEqual(resultHex, f.hex) |
|||
}) |
|||
}) |
|||
}) |
|||
}) |
|||
|
@ -0,0 +1,25 @@ |
|||
{ |
|||
"valid": [ |
|||
{ |
|||
"hex": "0000000000000000000000000000000000000000", |
|||
"wordArray": { |
|||
"words": [0, 0, 0, 0, 0], |
|||
"sigBytes": 20 |
|||
} |
|||
}, |
|||
{ |
|||
"hex": "62e907b15cbf27d5425399ebf6f0fb50ebb88f18", |
|||
"wordArray": { |
|||
"words": [1659439025, 1556031445, 1112775147, -151979184, -340226280], |
|||
"sigBytes": 20 |
|||
} |
|||
}, |
|||
{ |
|||
"hex": "ffffffffffffffffffffffffffffffffffffffff", |
|||
"wordArray": { |
|||
"words": [-1, -1, -1, -1, -1], |
|||
"sigBytes": 20 |
|||
} |
|||
} |
|||
] |
|||
} |
Loading…
Reference in new issue