Skip to content

Commit

Permalink
Add serializer for message key cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio Tacke committed Apr 6, 2020
1 parent b2aab8c commit 85e0ee2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
23 changes: 22 additions & 1 deletion androiddoubleratchet/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlinx-serialization'
apply plugin: 'maven-publish'

def artifactId = 'AndroidDoubleRatchet'
def groupId = 'com.ticeapp.androiddoubleratchet'

android {
compileSdkVersion 29
Expand All @@ -10,7 +15,7 @@ android {
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
versionName "1.0.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
Expand All @@ -36,4 +41,20 @@ dependencies {
implementation "com.goterl.lazycode:lazysodium-android:4.1.0@aar"
implementation 'net.java.dev.jna:jna:5.5.0@aar'
implementation 'com.github.TICESoftware:AndroidHKDF:1.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0"
}

project.afterEvaluate {
publishing {
publications {
library(MavenPublication) {
setGroupId groupId
setArtifactId artifactId
version android.defaultConfig.versionName

artifact bundleReleaseAar
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ticeapp.androiddoubleratchet

import com.goterl.lazycode.lazysodium.utils.Key
import kotlinx.serialization.*

internal class MessageKeyCache {
data class MessageIndex(val publicKey: Key, val messageNumber: Int)
Expand Down Expand Up @@ -49,4 +50,13 @@ internal class MessageKeyCache {
}

typealias MessageKeyCacheState = ArrayList<MessageKeyCacheEntry>
data class MessageKeyCacheEntry(val publicKey: Key, val messageNumber: Int, val messageKey: Key)

@Serializable
data class MessageKeyCacheEntry(@Serializable(with = KeySerializer::class) val publicKey: Key, val messageNumber: Int, @Serializable(with = KeySerializer::class) val messageKey: Key)

class KeySerializer: KSerializer<Key> { //SerializationStrategy<Key>, DeserializationStrategy<Key> {
override val descriptor: SerialDescriptor = PrimitiveDescriptor("Key", PrimitiveKind.STRING)
override fun serialize(encoder: Encoder, value: Key) = encoder.encodeString(value.asHexString)
override fun deserialize(decoder: Decoder): Key = Key.fromHexString(decoder.decodeString())
override fun patch(decoder: Decoder, old: Key): Key = deserialize(decoder)
}
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ buildscript {
classpath 'com.android.tools.build:gradle:3.6.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down

0 comments on commit 85e0ee2

Please sign in to comment.