UNPKG

gnablib

Version:

A lean, zero dependency library to provide a useful base for your project.

2 lines 579 B
/*! Copyright 2023-2024 the gnablib contributors MPL-1.1 */ import{ContentError as r}from"../../error/ContentError.js";import{LengthError as t}from"../../error/LengthError.js";export class Iso7816_4{static padSize(r,t){return r<=t?t:0}static pad(r,e,o=0){const n=new Uint8Array(e),s=e-(r.length-o);if(s<=0)throw t.atMost(e,"input.length",e-s);return n.set(r.subarray(o)),n[e-s]=128,n}static unpad(t,e=0){for(0===e&&(e=t.length-1);e>=0&&0===t[e];)e--;if(e<0||128!==t[e])throw new r("expecting end-marker 128","input",t[e]);return t.subarray(0,e)}}export const Iso9797_1=Iso7816_4;