pkcs7.unpad.js 759 B

123456789101112131415161718192021
  1. /*! @name pkcs7 @version 1.0.4 @license Apache-2.0 */
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  4. typeof define === 'function' && define.amd ? define(factory) :
  5. (global = global || self, (global.pkcs7 = global.pkcs7 || {}, global.pkcs7.unpad = factory()));
  6. }(this, function () { 'use strict';
  7. /**
  8. * Returns the subarray of a Uint8Array without PKCS#7 padding.
  9. *
  10. * @param padded {Uint8Array} unencrypted bytes that have been padded
  11. * @return {Uint8Array} the unpadded bytes
  12. * @see http://tools.ietf.org/html/rfc5652
  13. */
  14. function unpad(padded) {
  15. return padded.subarray(0, padded.byteLength - padded[padded.byteLength - 1]);
  16. }
  17. return unpad;
  18. }));