@@ -67,7 +67,7 @@ export default abstract class BasePlatform {
6767 protected notificationCount = 0 ;
6868 protected errorDidOccur = false ;
6969
70- public constructor ( ) {
70+ protected constructor ( ) {
7171 dis . register ( this . onAction ) ;
7272 this . startUpdateCheck = this . startUpdateCheck . bind ( this ) ;
7373 }
@@ -365,14 +365,7 @@ export default abstract class BasePlatform {
365365 return null ;
366366 }
367367
368- const additionalData = new Uint8Array ( userId . length + deviceId . length + 1 ) ;
369- for ( let i = 0 ; i < userId . length ; i ++ ) {
370- additionalData [ i ] = userId . charCodeAt ( i ) ;
371- }
372- additionalData [ userId . length ] = 124 ; // "|"
373- for ( let i = 0 ; i < deviceId . length ; i ++ ) {
374- additionalData [ userId . length + 1 + i ] = deviceId . charCodeAt ( i ) ;
375- }
368+ const additionalData = this . getPickleAdditionalData ( userId , deviceId ) ;
376369
377370 try {
378371 const key = await crypto . subtle . decrypt (
@@ -387,6 +380,18 @@ export default abstract class BasePlatform {
387380 }
388381 }
389382
383+ private getPickleAdditionalData ( userId : string , deviceId : string ) : Uint8Array {
384+ const additionalData = new Uint8Array ( userId . length + deviceId . length + 1 ) ;
385+ for ( let i = 0 ; i < userId . length ; i ++ ) {
386+ additionalData [ i ] = userId . charCodeAt ( i ) ;
387+ }
388+ additionalData [ userId . length ] = 124 ; // "|"
389+ for ( let i = 0 ; i < deviceId . length ; i ++ ) {
390+ additionalData [ userId . length + 1 + i ] = deviceId . charCodeAt ( i ) ;
391+ }
392+ return additionalData ;
393+ }
394+
390395 /**
391396 * Create and store a pickle key for encrypting libolm objects.
392397 * @param {string } userId the user ID for the user that the pickle key is for.
@@ -408,15 +413,7 @@ export default abstract class BasePlatform {
408413 const iv = new Uint8Array ( 32 ) ;
409414 crypto . getRandomValues ( iv ) ;
410415
411- const additionalData = new Uint8Array ( userId . length + deviceId . length + 1 ) ;
412- for ( let i = 0 ; i < userId . length ; i ++ ) {
413- additionalData [ i ] = userId . charCodeAt ( i ) ;
414- }
415- additionalData [ userId . length ] = 124 ; // "|"
416- for ( let i = 0 ; i < deviceId . length ; i ++ ) {
417- additionalData [ userId . length + 1 + i ] = deviceId . charCodeAt ( i ) ;
418- }
419-
416+ const additionalData = this . getPickleAdditionalData ( userId , deviceId ) ;
420417 const encrypted = await crypto . subtle . encrypt ( { name : "AES-GCM" , iv, additionalData } , cryptoKey , randomArray ) ;
421418
422419 try {
0 commit comments