Daniel Cousens
10 years ago
6 changed files with 2 additions and 100 deletions
@ -1,32 +0,0 @@ |
|||
var assert = require('assert') |
|||
var Crypto = require('crypto-js') |
|||
var WordArray = Crypto.lib.WordArray |
|||
|
|||
function bufferToWordArray(buffer) { |
|||
assert(Buffer.isBuffer(buffer), 'Expected Buffer, got', buffer) |
|||
|
|||
var words = [] |
|||
for (var i = 0, b = 0; i < buffer.length; i++, b += 8) { |
|||
words[b >>> 5] |= buffer[i] << (24 - b % 32) |
|||
} |
|||
|
|||
return new WordArray.init(words, buffer.length) |
|||
} |
|||
|
|||
function wordArrayToBuffer(wordArray) { |
|||
assert(Array.isArray(wordArray.words), 'Expected WordArray, got' + wordArray) |
|||
|
|||
var words = wordArray.words |
|||
var buffer = new Buffer(words.length * 4) |
|||
|
|||
words.forEach(function(value, i) { |
|||
buffer.writeInt32BE(value & -1, i * 4) |
|||
}) |
|||
|
|||
return buffer |
|||
} |
|||
|
|||
module.exports = { |
|||
bufferToWordArray: bufferToWordArray, |
|||
wordArrayToBuffer: wordArrayToBuffer |
|||
} |
@ -1,27 +0,0 @@ |
|||
var assert = require('assert') |
|||
var convert = require('../src/convert') |
|||
|
|||
var fixtures = require('./fixtures/convert') |
|||
|
|||
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) |
|||
|
|||
assert.deepEqual(result, f.wordArray) |
|||
}) |
|||
}) |
|||
}) |
|||
|
|||
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) |
|||
}) |
|||
}) |
|||
}) |
|||
}) |
@ -1,25 +0,0 @@ |
|||
{ |
|||
"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