122
return (bufferOrValue >>> 0).toString(16).padStart(bitsize / 4, '0');
123
}
125
>
/**
126
>
* A SHA1 implementation that works with strings and does not allocate.
127
>
*
128
>
* Prefer to use {@link hashAsync} in async contexts
129
>
*/
130
>
export class StringSHA1 {
131
>
private static _bigBlock32 = new DataView(new ArrayBuffer(320)); // 80 * 4 = 320
132
>
133
>
private _h0 = 0x67452301;
134
>
private _h1 = 0xEFCDAB89;
135
>
private _h2 = 0x98BADCFE;
136
>
private _h3 = 0x10325476;
137
>
private _h4 = 0xC3D2E1F0;
138
>
139
>
private readonly _buff: Uint8Array;
140
>
private readonly _buffDV: DataView;
141
>
private _buffLen: number;
142
>
private _totalLen: number;
143
>
private _leftoverHighSurrogate: number;
144
>
private _finished: boolean;
145
>
146
>
constructor() {
147
this._buff = new Uint8Array(SHA1Constant.BLOCK_SIZE + 3 /* to fit any utf-8 */);
148
this._buffDV = new DataView(this._buff.buffer);