gnablib
Version:
A lean, zero dependency library to provide a useful base for your project.
2 lines • 403 B
JavaScript
/*! Copyright 2023-2024 the gnablib contributors MPL-1.1 */
import{LengthError as r}from"../../error/LengthError.js";export class Zero{static padSize(r,t){return r<t&&r>0?t:0}static pad(t,a,e=0){const n=new Uint8Array(a),s=a-(t.length-e);if(s<0)throw r.atMost(a,"input.length",a-s);return n.set(t.subarray(e)),n}static unpad(r,t=0){for(0==t&&(t=r.length-1);t>=0&&0===r[t];)t--;return r.subarray(0,t+1)}}