Skip to content

Commit dc0a2a2

Browse files
authored
Add convenience constructor to E2EEOptions for shared key encryption (#917)
1 parent be63804 commit dc0a2a2

3 files changed

Lines changed: 22 additions & 10 deletions

File tree

.changeset/lemon-bees-perform.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"client-sdk-android": patch
3+
---
4+
5+
Add convenience constructor to E2EEOptions for shared key encryption

livekit-android-sdk/src/main/java/io/livekit/android/e2ee/E2EEOptions.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal const val defaultKeyRingSize = 16
2727
internal const val defaultDiscardFrameWhenCryptorNotReady = false
2828
internal val defaultKeyDerivationAlgorithm = FrameCryptorKeyDerivationAlgorithm.PBKDF2
2929

30-
class E2EEOptions(
30+
data class E2EEOptions(
3131
var keyProvider: KeyProvider = BaseKeyProvider(
3232
defaultRatchetSalt,
3333
defaultMagicBytes,
@@ -38,11 +38,18 @@ class E2EEOptions(
3838
defaultDiscardFrameWhenCryptorNotReady,
3939
defaultKeyDerivationAlgorithm,
4040
),
41-
encryptionType: Encryption.Type = Encryption.Type.GCM,
41+
var encryptionType: Encryption.Type = Encryption.Type.GCM,
4242
) {
43-
var encryptionType: Encryption.Type = Encryption.Type.NONE
44-
45-
init {
46-
this.encryptionType = encryptionType
43+
constructor(
44+
/**
45+
* The shared encryption key for the room.
46+
*/
47+
sharedKey: String,
48+
/**
49+
* The encryption type to use. Defaults to GCM.
50+
*/
51+
encryptionType: Encryption.Type = Encryption.Type.GCM,
52+
) : this(encryptionType = encryptionType) {
53+
this.keyProvider.setSharedKey(sharedKey)
4754
}
4855
}

sample-app-common/src/main/java/io/livekit/android/sample/CallViewModel.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ class CallViewModel(
7777
) : AndroidViewModel(application) {
7878

7979
private fun getE2EEOptions(): E2EEOptions? {
80-
var e2eeOptions: E2EEOptions? = null
81-
if (e2ee && e2eeKey != null) {
82-
e2eeOptions = E2EEOptions()
80+
var e2eeOptions = if (e2ee && e2eeKey != null) {
81+
E2EEOptions(sharedKey = e2eeKey)
82+
} else {
83+
null
8384
}
84-
e2eeOptions?.keyProvider?.setSharedKey(e2eeKey!!)
8585
return e2eeOptions
8686
}
8787

0 commit comments

Comments
 (0)