@@ -76,6 +76,15 @@ type SnapshotLike = {
7676 data ?: SpreadsheetData ;
7777} ;
7878
79+ function parseGrantAlgorithm ( algorithm : string ) {
80+ try {
81+ const parsed = JSON . parse ( algorithm ) ;
82+ return parsed && typeof parsed === "object" ? parsed : ALGORITHMS ;
83+ } catch {
84+ return ALGORITHMS ;
85+ }
86+ }
87+
7988function parseSnapshot ( raw : string ) : SnapshotLike | null {
8089 try {
8190 const parsed = JSON . parse ( raw ) ;
@@ -168,9 +177,7 @@ async function decryptDocumentHeader(
168177 encryptedSymmetricKey : grant . encryptedSymmetricKey ,
169178 iv : grant . iv ,
170179 salt : grant . salt ,
171- algorithm : typeof grant . algorithm === "string"
172- ? JSON . parse ( grant . algorithm )
173- : ALGORITHMS ,
180+ algorithm : parseGrantAlgorithm ( grant . algorithm ) ,
174181 } ,
175182 identity . keyPair . encryption . privateKey ,
176183 grant . grantor [ 0 ] . encryptionPublicKey ,
@@ -335,9 +342,7 @@ export function useDocuments(identity: StoredIdentity | null) {
335342 encryptedSymmetricKey : grant . encryptedSymmetricKey ,
336343 iv : grant . iv ,
337344 salt : grant . salt ,
338- algorithm : typeof grant . algorithm === "string"
339- ? JSON . parse ( grant . algorithm )
340- : ALGORITHMS ,
345+ algorithm : parseGrantAlgorithm ( grant . algorithm ) ,
341346 } ,
342347 identity . keyPair . encryption . privateKey ,
343348 grant . grantor [ 0 ] . encryptionPublicKey ,
0 commit comments