Skip to content

Commit

Permalink
unit test of padding empty buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
tugrul committed Sep 28, 2024
1 parent 1393bc5 commit 30060bb
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/padding/ansi-x923.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ describe('ansi-x923', () => {

});


it('should pad empty buffer', () => {
const padder = new padding.AnsiX923(8);
const padded = padder.pad(Buffer.alloc(0))

assert(padded.equals(Buffer.from('0000000000000008', 'hex')));
});
});


Expand All @@ -53,6 +60,14 @@ describe('ansi-x923', () => {

});

it('should unpad only padding data', () => {

const padder = new padding.AnsiX923(8);
const unpadded = padder.unpad(Buffer.from('0000000000000008', 'hex'));

assert(unpadded.length === 0);
});

});


Expand Down
15 changes: 15 additions & 0 deletions test/padding/iso-10126.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ describe('iso-10126', () => {

});

it('should pad empty buffer', () => {
const padder = new padding.Iso10126(8);
const padded = padder.pad(Buffer.alloc(0))

assert(padded.length === 8 && padded[7] === 8);
});

});


Expand All @@ -51,6 +58,14 @@ describe('iso-10126', () => {

});

it('should unpad only padding data', () => {

const padder = new padding.Iso10126(8);
const unpadded = padder.unpad(Buffer.from('1ad227c97c515608', 'hex'));

assert(unpadded.length === 0);
});

});


Expand Down
15 changes: 15 additions & 0 deletions test/padding/iso-7816.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ describe('iso-7816', () => {

});

it('should pad empty buffer', () => {
const padder = new padding.Iso7816(8);
const padded = padder.pad(Buffer.alloc(0))

assert(padded.equals(Buffer.from('8000000000000000', 'hex')));
});

});


Expand All @@ -49,6 +56,14 @@ describe('iso-7816', () => {

});

it('should unpad only padding data', () => {

const padder = new padding.Iso7816(8);
const unpadded = padder.unpad(Buffer.from('8000000000000000', 'hex'));

assert(unpadded.length === 0);
});

});


Expand Down
15 changes: 15 additions & 0 deletions test/padding/null.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ describe('null', () => {

});

it('should pad empty buffer', () => {
const padder = new padding.Null(8);
const padded = padder.pad(Buffer.alloc(0))

assert(padded.equals(Buffer.from('0000000000000000', 'hex')));
});

});


Expand All @@ -50,6 +57,14 @@ describe('null', () => {

});

it('should unpad only padding data', () => {

const padder = new padding.Null(8);
const unpadded = padder.unpad(Buffer.from('0000000000000000', 'hex'));

assert(unpadded.length === 0);
});

});


Expand Down
15 changes: 15 additions & 0 deletions test/padding/pkcs5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ describe('pkcs5', () => {

});

it('should pad empty buffer', () => {
const padder = new padding.Pkcs5(8);
const padded = padder.pad(Buffer.alloc(0))

assert(padded.equals(Buffer.from('0808080808080808', 'hex')));
});

});


Expand All @@ -57,6 +64,14 @@ describe('pkcs5', () => {

});

it('should unpad only padding data', () => {

const padder = new padding.Pkcs5(8);
const unpadded = padder.unpad(Buffer.from('0808080808080808', 'hex'));

assert(unpadded.length === 0);
});

});


Expand Down
31 changes: 31 additions & 0 deletions test/padding/pkcs7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ describe('pkcs7', () => {

});

it('should pad empty buffer of blockSize 8', () => {
const padder = new padding.Pkcs7(8);
const padded = padder.pad(Buffer.alloc(0))

assert(padded.equals(Buffer.from('0808080808080808', 'hex')));
});


it('should pad empty buffer of blockSize 16', () => {
const padder = new padding.Pkcs7(16);
const padded = padder.pad(Buffer.alloc(0))

assert(padded.equals(Buffer.from('10101010101010101010101010101010', 'hex')));
});

});


Expand All @@ -54,6 +69,22 @@ describe('pkcs7', () => {

});

it('should unpad only padding data of blockSize 8', () => {

const padder = new padding.Pkcs7(8);
const unpadded = padder.unpad(Buffer.from('0808080808080808', 'hex'));

assert(unpadded.length === 0);
});

it('should unpad only padding data of blockSize 16', () => {

const padder = new padding.Pkcs7(16);
const unpadded = padder.unpad(Buffer.from('10101010101010101010101010101010', 'hex'));

assert(unpadded.length === 0);
});

});


Expand Down
15 changes: 15 additions & 0 deletions test/padding/space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ describe('space', () => {

});

it('should pad empty buffer', () => {
const padder = new padding.Space(8);
const padded = padder.pad(Buffer.alloc(0))

assert(padded.equals(Buffer.from('2020202020202020', 'hex')));
});

});


Expand All @@ -50,6 +57,14 @@ describe('space', () => {

});

it('should unpad only padding data', () => {

const padder = new padding.Space(8);
const unpadded = padder.unpad(Buffer.from('2020202020202020', 'hex'));

assert(unpadded.length === 0);
});

});


Expand Down

0 comments on commit 30060bb

Please sign in to comment.