diff --git a/androiddoubleratchet/build.gradle b/androiddoubleratchet/build.gradle index e1fd570..29dc0e5 100644 --- a/androiddoubleratchet/build.gradle +++ b/androiddoubleratchet/build.gradle @@ -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 @@ -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' @@ -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 + } + } + } +} \ No newline at end of file diff --git a/androiddoubleratchet/src/main/java/com/ticeapp/androiddoubleratchet/MessageKeyCache.kt b/androiddoubleratchet/src/main/java/com/ticeapp/androiddoubleratchet/MessageKeyCache.kt index 1141629..bab5dfa 100644 --- a/androiddoubleratchet/src/main/java/com/ticeapp/androiddoubleratchet/MessageKeyCache.kt +++ b/androiddoubleratchet/src/main/java/com/ticeapp/androiddoubleratchet/MessageKeyCache.kt @@ -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) @@ -49,4 +50,13 @@ internal class MessageKeyCache { } typealias MessageKeyCacheState = ArrayList -data class MessageKeyCacheEntry(val publicKey: Key, val messageNumber: Int, val messageKey: Key) \ No newline at end of file + +@Serializable +data class MessageKeyCacheEntry(@Serializable(with = KeySerializer::class) val publicKey: Key, val messageNumber: Int, @Serializable(with = KeySerializer::class) val messageKey: Key) + +class KeySerializer: KSerializer { //SerializationStrategy, DeserializationStrategy { + 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) +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 2e6f10e..847d686 100644 --- a/build.gradle +++ b/build.gradle @@ -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