dash ble tests: ktlintFormat
This commit is contained in:
parent
a94d6ce652
commit
b71f065974
7 changed files with 24 additions and 29 deletions
|
@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.pair
|
||||||
|
|
||||||
import com.google.crypto.tink.subtle.X25519
|
import com.google.crypto.tink.subtle.X25519
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.AAPSLoggerTest
|
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.BuildConfig
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.BuildConfig
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions.MessageIOException
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions.MessageIOException
|
||||||
|
@ -12,10 +11,11 @@ import org.spongycastle.crypto.macs.CMac
|
||||||
import org.spongycastle.crypto.params.KeyParameter
|
import org.spongycastle.crypto.params.KeyParameter
|
||||||
import java.security.SecureRandom
|
import java.security.SecureRandom
|
||||||
|
|
||||||
class KeyExchange(private val aapsLogger: AAPSLogger,
|
class KeyExchange(
|
||||||
|
private val aapsLogger: AAPSLogger,
|
||||||
var pdmPrivate: ByteArray = X25519.generatePrivateKey(),
|
var pdmPrivate: ByteArray = X25519.generatePrivateKey(),
|
||||||
val pdmNonce: ByteArray = ByteArray(NONCE_SIZE)
|
val pdmNonce: ByteArray = ByteArray(NONCE_SIZE)
|
||||||
) {
|
) {
|
||||||
val pdmPublic = X25519.publicFromPrivate(pdmPrivate)
|
val pdmPublic = X25519.publicFromPrivate(pdmPrivate)
|
||||||
|
|
||||||
var podPublic = ByteArray(PUBLIC_KEY_SIZE)
|
var podPublic = ByteArray(PUBLIC_KEY_SIZE)
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message
|
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message
|
||||||
|
|
||||||
import android.app.Notification
|
|
||||||
import com.google.crypto.tink.subtle.Hex
|
import com.google.crypto.tink.subtle.Hex
|
||||||
import info.nightscout.androidaps.logging.AAPSLoggerTest
|
import info.nightscout.androidaps.logging.AAPSLoggerTest
|
||||||
import info.nightscout.androidaps.logging.LTag
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.Id
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.Id
|
||||||
import info.nightscout.androidaps.utils.extensions.toHex
|
import info.nightscout.androidaps.utils.extensions.toHex
|
||||||
import org.junit.Assert.*
|
import org.junit.Assert.*
|
||||||
|
@ -32,7 +30,7 @@ class MessagePacketTest {
|
||||||
assertEquals(msg.sas, true)
|
assertEquals(msg.sas, true)
|
||||||
assertEquals(msg.tfs, false)
|
assertEquals(msg.tfs, false)
|
||||||
assertEquals(msg.version, 0.toShort())
|
assertEquals(msg.version, 0.toShort())
|
||||||
assertEquals(msg.payload.toHex(), payload.substring(32, payload.length) )
|
assertEquals(msg.payload.toHex(), payload.substring(32, payload.length))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun testSerializeMessagePacket() {
|
@Test fun testSerializeMessagePacket() {
|
||||||
|
|
|
@ -18,5 +18,3 @@ class PayloadJoinerTest {
|
||||||
assertEquals(payload, actual.toHex())
|
assertEquals(payload, actual.toHex())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ class PayloadSplitterTest {
|
||||||
@Test fun testSplitter() {
|
@Test fun testSplitter() {
|
||||||
val f1 = "00,01,54,57,10,23,03,00,00,c0,ff,ff,ff,fe,08,20,2e,a8,50,30".replace(",", "")
|
val f1 = "00,01,54,57,10,23,03,00,00,c0,ff,ff,ff,fe,08,20,2e,a8,50,30".replace(",", "")
|
||||||
val f2 = "01,04,bc,20,1f,f6,3d,00,01,a5,ff,ff,ff,fe,08,20,2e,a8,50,30".replace(",", "")
|
val f2 = "01,04,bc,20,1f,f6,3d,00,01,a5,ff,ff,ff,fe,08,20,2e,a8,50,30".replace(",", "")
|
||||||
val payload = Hex.decode("54,57,10,23,03,00,00,c0,ff,ff,ff,fe,08,20,2e,a8,50,30,3d,00,01,a5".replace(",",""))
|
val payload = Hex.decode("54,57,10,23,03,00,00,c0,ff,ff,ff,fe,08,20,2e,a8,50,30,3d,00,01,a5".replace(",", ""))
|
||||||
|
|
||||||
val splitter = PayloadSplitter(payload)
|
val splitter = PayloadSplitter(payload)
|
||||||
val packets = splitter.splitInPackets()
|
val packets = splitter.splitInPackets()
|
||||||
|
@ -19,6 +19,6 @@ class PayloadSplitterTest {
|
||||||
assertEquals(f1, packets.get(0).asByteArray().toHex())
|
assertEquals(f1, packets.get(0).asByteArray().toHex())
|
||||||
val p2 = packets.get(1).asByteArray()
|
val p2 = packets.get(1).asByteArray()
|
||||||
assertTrue(p2.size >= 10)
|
assertTrue(p2.size >= 10)
|
||||||
assertEquals(f2.subSequence(0, 20),p2.copyOfRange(0, 10).toHex())
|
assertEquals(f2.subSequence(0, 20), p2.copyOfRange(0, 10).toHex())
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,7 +6,7 @@ import org.junit.Assert.*
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
class StringLengthPrefixEncodingTest {
|
class StringLengthPrefixEncodingTest {
|
||||||
private val p0Payload = Hex.decode("50,30,3d,00,01,a5".replace(",","")) // from logs
|
private val p0Payload = Hex.decode("50,30,3d,00,01,a5".replace(",", "")) // from logs
|
||||||
private val p0Content = Hex.decode("a5")
|
private val p0Content = Hex.decode("a5")
|
||||||
|
|
||||||
@Test fun testFormatKeysP0() {
|
@Test fun testFormatKeysP0() {
|
||||||
|
|
|
@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.pair
|
||||||
|
|
||||||
import info.nightscout.androidaps.logging.AAPSLoggerTest
|
import info.nightscout.androidaps.logging.AAPSLoggerTest
|
||||||
import info.nightscout.androidaps.utils.extensions.toHex
|
import info.nightscout.androidaps.utils.extensions.toHex
|
||||||
import org.junit.Assert
|
|
||||||
import org.junit.Assert.*
|
import org.junit.Assert.*
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.spongycastle.util.encoders.Hex
|
import org.spongycastle.util.encoders.Hex
|
||||||
|
@ -12,12 +11,12 @@ class KeyExchangeTest {
|
||||||
val aapsLogger = AAPSLoggerTest()
|
val aapsLogger = AAPSLoggerTest()
|
||||||
val ke = KeyExchange(
|
val ke = KeyExchange(
|
||||||
aapsLogger,
|
aapsLogger,
|
||||||
pdmPrivate= Hex.decode("27ec94b71a201c5e92698d668806ae5ba00594c307cf5566e60c1fc53a6f6bb6"),
|
pdmPrivate = Hex.decode("27ec94b71a201c5e92698d668806ae5ba00594c307cf5566e60c1fc53a6f6bb6"),
|
||||||
pdmNonce= Hex.decode("edfdacb242c7f4e1d2bc4d93ca3c5706")
|
pdmNonce = Hex.decode("edfdacb242c7f4e1d2bc4d93ca3c5706")
|
||||||
)
|
)
|
||||||
val podPublicKey = Hex.decode("2fe57da347cd62431528daac5fbb290730fff684afc4cfc2ed90995f58cb3b74")
|
val podPublicKey = Hex.decode("2fe57da347cd62431528daac5fbb290730fff684afc4cfc2ed90995f58cb3b74")
|
||||||
val podNonce = Hex.decode("00000000000000000000000000000000")
|
val podNonce = Hex.decode("00000000000000000000000000000000")
|
||||||
ke.updatePodPublicData(podPublicKey+podNonce)
|
ke.updatePodPublicData(podPublicKey + podNonce)
|
||||||
assertEquals(ke.pdmPublic.toHex(), "f2b6940243aba536a66e19fb9a39e37f1e76a1cd50ab59b3e05313b4fc93975e")
|
assertEquals(ke.pdmPublic.toHex(), "f2b6940243aba536a66e19fb9a39e37f1e76a1cd50ab59b3e05313b4fc93975e")
|
||||||
assertEquals(ke.pdmConf.toHex(), "5fc3b4da865e838ceaf1e9e8bb85d1ac")
|
assertEquals(ke.pdmConf.toHex(), "5fc3b4da865e838ceaf1e9e8bb85d1ac")
|
||||||
ke.validatePodConf(Hex.decode("af4f10db5f96e5d9cd6cfc1f54f4a92f"))
|
ke.validatePodConf(Hex.decode("af4f10db5f96e5d9cd6cfc1f54f4a92f"))
|
||||||
|
|
Loading…
Reference in a new issue