unpad.js 505 B

12345678910111213141516171819
  1. /*
  2. * pkcs7.unpad
  3. * https://github.com/brightcove/pkcs7
  4. *
  5. * Copyright (c) 2014 Brightcove
  6. * Licensed under the apache2 license.
  7. */
  8. 'use strict';
  9. /**
  10. * Returns the subarray of a Uint8Array without PKCS#7 padding.
  11. * @param padded {Uint8Array} unencrypted bytes that have been padded
  12. * @return {Uint8Array} the unpadded bytes
  13. * @see http://tools.ietf.org/html/rfc5652
  14. */
  15. module.exports = function unpad(padded) {
  16. return padded.subarray(0, padded.byteLength - padded[padded.byteLength - 1]);
  17. };