@ -115,13 +115,13 @@ define([
@@ -115,13 +115,13 @@ define([
return JSON . stringify ( data ) ;
} ;
var LocalStorageDataStore = function ( encryption ) {
var LocalStorageDataStore = function ( endToEndEn cryption ) {
this . e = $ ( { } ) ;
this . encryption = encryption ;
this . endToEndEn cryption = endToEndE ncryption ;
this . userid = null ;
this . id = encryption . api . sid ;
this . id = endToEndEn cryption . api . sid ;
this . anonymous _storage = { } ;
encryption . api . e . on ( "received.self" , _ . bind ( function ( event , data ) {
endToEndEn cryption . api . e . on ( "received.self" , _ . bind ( function ( event , data ) {
var userid = data . Suserid || null ;
if ( this . id === ( userid || data . Sid ) && this . userid === userid ) {
return ;
@ -132,7 +132,7 @@ define([
@@ -132,7 +132,7 @@ define([
this . userid = userid ;
this . anonymous _storage = { } ;
}
this . encryption . resetStore ( ) ;
this . endToEndEn cryption . resetStore ( ) ;
if ( initial ) {
this . e . triggerHandler ( "ready" ) ;
}
@ -231,7 +231,7 @@ define([
@@ -231,7 +231,7 @@ define([
return this . save ( "signed_pre_key_" + this . id + "_" + key . id , data ) ;
} ;
var Encryption = function ( api ) {
var EndToEndEn cryption = function ( api ) {
this . e = $ ( { } ) ;
this . api = api ;
// TODO(fancycode): Look into using IndexedDB as storage backend.
@ -271,11 +271,11 @@ define([
@@ -271,11 +271,11 @@ define([
this . resetStore ( ) ;
} ;
Encryption . prototype . isSupported = function ( ) {
EndToEndEn cryption . prototype . isSupported = function ( ) {
return ! ! this . store ;
} ;
Encryption . prototype . resetStore = function ( ) {
EndToEndEn cryption . prototype . resetStore = function ( ) {
// TODO(fancycode): We should process any pending messages before
// resetting everything.
this . identity _keypair = null ;
@ -292,11 +292,11 @@ define([
@@ -292,11 +292,11 @@ define([
}
} ;
Encryption . prototype . getIdentityFingerprint = function ( ) {
EndToEndEn cryption . prototype . getIdentityFingerprint = function ( ) {
return this . formatIdentityFingerprint ( this . identity _keypair . public ) ;
} ;
Encryption . prototype . formatIdentityFingerprint = function ( public _key ) {
EndToEndEn cryption . prototype . formatIdentityFingerprint = function ( public _key ) {
// TODO(jojo): Change this to be the SHA-1 hash of a three-byte key
// id and the public key.
// See https://github.com/WhisperSystems/TextSecure/blob/08ed90c5ece49c92e35c492afb4e60160983015a/src/org/thoughtcrime/securesms/crypto/PublicKey.java#L95
@ -309,7 +309,7 @@ define([
@@ -309,7 +309,7 @@ define([
return fingerprint . substr ( 2 ) ;
} ;
Encryption . prototype . storePeerIdentity = function ( peer , public _key ) {
EndToEndEn cryption . prototype . storePeerIdentity = function ( peer , public _key ) {
var fingerprint = this . formatIdentityFingerprint ( public _key ) ;
var existing = this . peer _identities [ peer ] ;
if ( existing === fingerprint ) {
@ -324,7 +324,7 @@ define([
@@ -324,7 +324,7 @@ define([
this . peer _identities [ peer ] = fingerprint ;
} ;
Encryption . prototype . getReadyPromise = function ( ) {
EndToEndEn cryption . prototype . getReadyPromise = function ( ) {
if ( ! this . ready _promise ) {
// Load/create initial objects
this . ready _promise = this . loadData ( ) . then ( _ . bind ( function ( ) {
@ -356,7 +356,7 @@ define([
@@ -356,7 +356,7 @@ define([
return this . ready _promise ;
} ;
Encryption . prototype . loadData = function ( ) {
EndToEndEn cryption . prototype . loadData = function ( ) {
var deferred = $q . defer ( ) ;
var doLoadData = _ . bind ( function ( ) {
this . identity _keypair = this . store . loadKeypair ( ) ;
@ -378,7 +378,7 @@ define([
@@ -378,7 +378,7 @@ define([
return deferred . promise ;
} ;
Encryption . prototype . getLocalIdentityKeyPair = function ( ) {
EndToEndEn cryption . prototype . getLocalIdentityKeyPair = function ( ) {
var deferred = $q . defer ( ) ;
_ . defer ( _ . bind ( function ( ) {
if ( this . identity _keypair ) {
@ -398,7 +398,7 @@ define([
@@ -398,7 +398,7 @@ define([
return deferred . promise ;
} ;
Encryption . prototype . getLocalRegistrationId = function ( ) {
EndToEndEn cryption . prototype . getLocalRegistrationId = function ( ) {
var deferred = $q . defer ( ) ;
_ . defer ( _ . bind ( function ( ) {
if ( this . registration _id ) {
@ -417,7 +417,7 @@ define([
@@ -417,7 +417,7 @@ define([
return deferred . promise ;
} ;
Encryption . prototype . getLastResortPreKey = function ( ) {
EndToEndEn cryption . prototype . getLastResortPreKey = function ( ) {
var deferred = $q . defer ( ) ;
_ . defer ( _ . bind ( function ( ) {
if ( this . last _resort _pre _key ) {
@ -437,7 +437,7 @@ define([
@@ -437,7 +437,7 @@ define([
return deferred . promise ;
} ;
Encryption . prototype . getLocalSignedPreKeyPair = function ( id ) {
EndToEndEn cryption . prototype . getLocalSignedPreKeyPair = function ( id ) {
var deferred = $q . defer ( ) ;
_ . defer ( _ . bind ( function ( ) {
var signed _pre _key ;
@ -451,7 +451,7 @@ define([
@@ -451,7 +451,7 @@ define([
return deferred . promise ;
} ;
Encryption . prototype . getSignedPreKey = function ( id ) {
EndToEndEn cryption . prototype . getSignedPreKey = function ( id ) {
if ( ! id ) {
id = this . next _signed _pre _key _id ;
this . next _signed _pre _key _id ++ ;
@ -475,7 +475,7 @@ define([
@@ -475,7 +475,7 @@ define([
return deferred . promise ;
} ;
Encryption . prototype . apiSend = function ( type , message ) {
EndToEndEn cryption . prototype . apiSend = function ( type , message ) {
var msg = {
"Type" : type
} ;
@ -483,7 +483,7 @@ define([
@@ -483,7 +483,7 @@ define([
this . api . send ( type , message ) ;
} ;
Encryption . prototype . register = function ( ) {
EndToEndEn cryption . prototype . register = function ( ) {
this . getReadyPromise ( ) . then ( _ . bind ( function ( ) {
var message = {
"RegistrationId" : this . registration _id ,
@ -500,7 +500,7 @@ define([
@@ -500,7 +500,7 @@ define([
} , this ) ) ;
} ;
Encryption . prototype . processPendingMessages = function ( peer ) {
EndToEndEn cryption . prototype . processPendingMessages = function ( peer ) {
var pending = this . pending _messages [ peer ] ;
if ( pending && pending . length > 0 ) {
var msg = pending . shift ( ) ;
@ -526,7 +526,7 @@ define([
@@ -526,7 +526,7 @@ define([
}
} ;
Encryption . prototype . requestKeyBundle = function ( peer ) {
EndToEndEn cryption . prototype . requestKeyBundle = function ( peer ) {
this . getSignedPreKey ( ) . then ( _ . bind ( function ( signed _pre _key ) {
var bundle = {
"To" : peer ,
@ -543,7 +543,7 @@ define([
@@ -543,7 +543,7 @@ define([
} , this ) ) ;
} ;
Encryption . prototype . receivedKeyBundle = function ( peer , data ) {
EndToEndEn cryption . prototype . receivedKeyBundle = function ( peer , data ) {
var bundle = {
"identityKey" : deserializePublicKey ( data . Identity ) ,
"preKeyId" : null ,
@ -571,7 +571,7 @@ define([
@@ -571,7 +571,7 @@ define([
} , this ) ) ;
} ;
Encryption . prototype . encrypt = function ( peer , type , message , callback ) {
EndToEndEn cryption . prototype . encrypt = function ( peer , type , message , callback ) {
var msg = { "Type" : type } ;
msg [ type ] = message ;
message = JSON . stringify ( msg ) ;
@ -599,7 +599,7 @@ define([
@@ -599,7 +599,7 @@ define([
this . encryptWithSession ( peer , session , message , callback ) ;
} ;
Encryption . prototype . encryptWithSession = function (
EndToEndEn cryption . prototype . encryptWithSession = function (
peer , session , message , callback ) {
var buffer = ByteBuffer . fromUTF8 ( message ) . toArrayBuffer ( ) ;
// TODO(fancycode): Add error handling.
@ -617,7 +617,7 @@ define([
@@ -617,7 +617,7 @@ define([
} , this ) ) ;
} ;
Encryption . prototype . decrypt = function ( peer , message , callback ) {
EndToEndEn cryption . prototype . decrypt = function ( peer , message , callback ) {
if ( this . is _processing _messages [ peer ] ) {
this . pending _messages [ peer ] . push ( {
"type" : "decrypt" ,
@ -632,7 +632,7 @@ define([
@@ -632,7 +632,7 @@ define([
this . decryptWithSession ( peer , session , message , callback ) ;
} ;
Encryption . prototype . decryptWithSession = function (
EndToEndEn cryption . prototype . decryptWithSession = function (
peer , session , message , callback ) {
var handle _decrypted = _ . bind ( function ( decrypted ) {
if ( decrypted . identityKey ) {
@ -662,38 +662,38 @@ define([
@@ -662,38 +662,38 @@ define([
}
} ;
var encryption ;
var endToEndEn cryption ;
// Only export limited public encryption API.
var encryptionApi = {
var endToEndEn cryptionApi = {
"initialize" : function ( api ) {
if ( encryption ) {
if ( endToEndEn cryption ) {
return true ;
}
encryption = new Encryption ( api ) ;
if ( ! encryption . isSupported ( ) ) {
encryption = null ;
endToEndEn cryption = new EndToEnd Encryption( api ) ;
if ( ! endToEndEn cryption . isSupported ( ) ) {
endToEndEn cryption = null ;
return false ;
}
return true ;
} ,
"encrypt" : function ( peer , type , message , callback ) {
if ( ! encryption ) {
if ( ! endToEndEn cryption ) {
callback ( type , message ) ;
return ;
}
encryption . encrypt ( peer , type , message , callback ) ;
endToEndEn cryption . encrypt ( peer , type , message , callback ) ;
} ,
"decrypt" : function ( peer , message , callback ) {
if ( ! encryption ) {
if ( ! endToEndEn cryption ) {
callback ( message ) ;
return ;
}
encryption . decrypt ( peer , message , callback ) ;
endToEndEn cryption . decrypt ( peer , message , callback ) ;
}
} ;
return encryptionApi ;
return endToEndEn cryptionApi ;
} ] ;