aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/assets')
-rw-r--r--client/src/assets/player/p2p-media-loader/segment-validator.ts15
1 files changed, 11 insertions, 4 deletions
diff --git a/client/src/assets/player/p2p-media-loader/segment-validator.ts b/client/src/assets/player/p2p-media-loader/segment-validator.ts
index 0614f73d2..fa6e6df1d 100644
--- a/client/src/assets/player/p2p-media-loader/segment-validator.ts
+++ b/client/src/assets/player/p2p-media-loader/segment-validator.ts
@@ -41,7 +41,7 @@ function segmentValidatorFactory (segmentsSha256Url: string) {
41 throw new Error(`Unknown segment name ${filename}/${range} in segment validator`) 41 throw new Error(`Unknown segment name ${filename}/${range} in segment validator`)
42 } 42 }
43 43
44 const calculatedSha = bufferToEx(await sha256(segment.data)) 44 const calculatedSha = await sha256Hex(segment.data)
45 if (calculatedSha !== hashShouldBe) { 45 if (calculatedSha !== hashShouldBe) {
46 throw new Error( 46 throw new Error(
47 `Hashes does not correspond for segment ${filename}/${range}` + 47 `Hashes does not correspond for segment ${filename}/${range}` +
@@ -68,14 +68,21 @@ function fetchSha256Segments (url: string) {
68 }) 68 })
69} 69}
70 70
71function sha256 (data?: ArrayBuffer) { 71async function sha256Hex (data?: ArrayBuffer) {
72 if (!data) return undefined 72 if (!data) return undefined
73 73
74 return window.crypto.subtle.digest('SHA-256', data) 74 if (window.crypto.subtle) {
75 return window.crypto.subtle.digest('SHA-256', data)
76 .then(data => bufferToHex(data))
77 }
78
79 // Fallback for non HTTPS context
80 const shaModule = await import('sha.js')
81 return new shaModule.sha256().update(Buffer.from(data)).digest('hex')
75} 82}
76 83
77// Thanks: https://stackoverflow.com/a/53307879 84// Thanks: https://stackoverflow.com/a/53307879
78function bufferToEx (buffer?: ArrayBuffer) { 85function bufferToHex (buffer?: ArrayBuffer) {
79 if (!buffer) return '' 86 if (!buffer) return ''
80 87
81 let s = '' 88 let s = ''