MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / digest

Method digest

packages/core/wgc/crypto/SubtleCrypto.ts:183–257  ·  view source on GitHub ↗
(algorithm: 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512', data: TypedArray | ArrayBuffer)

Source from the content-addressed store, hash-verified

181
182export class SubtleCrypto {
183 digest(algorithm: 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512', data: TypedArray | ArrayBuffer) {
184 return new Promise((resolve, reject) => {
185 let error: Error;
186 let mode: number;
187 switch (algorithm) {
188 case 'SHA-1':
189 mode = 0;
190 break;
191 case 'SHA-256':
192 mode = 1;
193 break;
194 case 'SHA-384':
195 mode = 2;
196 break;
197 case 'SHA-512':
198 mode = 3;
199 break;
200 default:
201 error = new Error('Operation is not supported');
202 break;
203 }
204 if (error !== undefined) {
205 reject(error);
206 return;
207 }
208
209 if (data instanceof ArrayBuffer || data instanceof Uint8Array || data instanceof Uint8ClampedArray) {
210 // noop
211 } else if (data?.BYTES_PER_ELEMENT !== 1) {
212 data = new Uint8Array(data.buffer, data.byteOffset);
213 } else {
214 reject(new TypeError('Argument 2 could not be converted to any of: ArrayBufferView, ArrayBuffer.'));
215 return;
216 }
217
218 if (__ANDROID__) {
219 //const instance = java.security.MessageDigest.getInstance(algorithm);
220
221 const buffer = (<any>org).nativescript.winter_tc.Crypto.digest(mode, data);
222 const ab = (<any>ArrayBuffer).from(buffer);
223
224 if (!ab) {
225 // todo throw failure
226 }
227
228 resolve(ab);
229
230 /* instance.update(data as any);
231 const digest = instance.digest();
232
233 const ab = new ArrayBuffer(digest.length);
234 (<any>org).nativescript.winter_tc.Utils.copyToBuffer(ab, digest);
235
236 resolve(ab);
237
238 */
239 }
240

Callers 6

shortHashFunction · 0.45
strategy.spec.tsFile · 0.45
configureServerFunction · 0.45
handleHotUpdateFunction · 0.45
hashKeyForDiskMethod · 0.45
digestMessageFunction · 0.45

Calls 1

resolveFunction · 0.50

Tested by

no test coverage detected