lightsword
Version:
LightSword Secure SOCKS5 Proxy / iOS VPN Server
66 lines (65 loc) • 1.39 kB
JavaScript
/*
* pkcs7.pad
* https://github.com/brightcove/pkcs7
*
* Copyright (c) 2014 Brightcove
* Licensed under the apache2 license.
*/
'use strict';
// Pre-define the padding values
const PADDING = [
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[]
];
function pad(plaintext) {
var padding = PADDING[(plaintext.length % 16) || 0], result = new Uint8Array(plaintext.length + padding.length);
result.set(plaintext);
result.set(padding, plaintext.length);
return result;
}
exports.pad = pad;
;
function unpad(padded) {
return padded.subarray(0, padded.length - padded[padded.length - 1]);
}
exports.unpad = unpad;
;
exports.PKCS7Size = 16;