bitcore/test/test.cbc.js

50 lines
1.2 KiB
JavaScript
Raw Normal View History

var should = require('chai').should();
var CBC = require('../lib/expmt/cbc');
describe('CBC', function() {
2014-08-24 20:51:56 -07:00
it('should return a new CBC', function() {
var cbc = new CBC();
should.exist(cbc);
})
it('should return a new CBC when called without "new"', function() {
var cbc = new CBC();
should.exist(cbc);
});
describe('@pkcs7pad', function() {
it('should pad this 32 bit buffer to 128 bits with the number 128/8 - 32/8', function() {
var buf = new Buffer(32 / 8);
buf.fill(0);
var padbuf = CBC.pkcs7pad(buf, 128);
padbuf.length.should.equal(128 / 8);
padbuf[32 / 8].should.equal(128 / 8 - 32 / 8);
padbuf[32 / 8 + 1].should.equal(128 / 8 - 32 / 8);
// ...
padbuf[32 / 8 + 128 / 8 - 32 / 8 - 1].should.equal(128 / 8 - 32 / 8);
});
});
2014-08-24 20:51:56 -07:00
describe('@xorbufs', function() {
it('should xor 1 and 0', function() {
var buf1 = new Buffer([1]);
var buf2 = new Buffer([0]);
var buf = CBC.xorbufs(buf1, buf2);
buf[0].should.equal(1);
});
it('should xor 1 and 1', function() {
var buf1 = new Buffer([1]);
var buf2 = new Buffer([1]);
var buf = CBC.xorbufs(buf1, buf2);
buf[0].should.equal(0);
});
});
});