Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 1x 141x 141x 139x 139x 694x 139x | import type { IPadding } from './IPadding';
export class ISOIEC7864Padding implements IPadding {
public addTo(data: Uint8Array, blockSize: number): Uint8Array {
const paddingLength = blockSize - data.length % blockSize;
return new Uint8Array([...data, 0x80, ...new Array<number>(paddingLength - 1).fill(0)]);
}
public removeFrom(data: Uint8Array): Uint8Array {
let index = data.length - 1;
while (data[index] !== 0x80)
index -= 1;
return data.slice(0, index);
}
}
|