(plaintext: string)
| 70 | } |
| 71 | |
| 72 | function pad(plaintext: string): Buffer { |
| 73 | const unpadded = Buffer.from(plaintext, 'utf8') |
| 74 | const unpaddedLen = unpadded.length |
| 75 | if (unpaddedLen < MIN_PLAINTEXT_SIZE || unpaddedLen > MAX_PLAINTEXT_SIZE) { |
| 76 | throw new Error('invalid plaintext length') |
| 77 | } |
| 78 | const prefix = Buffer.alloc(2) |
| 79 | prefix.writeUInt16BE(unpaddedLen, 0) |
| 80 | const suffix = Buffer.alloc(calcPaddedLen(unpaddedLen) - unpaddedLen) |
| 81 | return Buffer.concat([prefix, unpadded, suffix]) |
| 82 | } |
| 83 | |
| 84 | function unpad(padded: Buffer): string { |
| 85 | const unpaddedLen = padded.readUInt16BE(0) |
no test coverage detected