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(
|
||||||
var pdmPrivate: ByteArray = X25519.generatePrivateKey(),
|
private val aapsLogger: AAPSLogger,
|
||||||
val pdmNonce: ByteArray = ByteArray(NONCE_SIZE)
|
var pdmPrivate: ByteArray = X25519.generatePrivateKey(),
|
||||||
) {
|
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,24 +30,24 @@ 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() {
|
||||||
val msg = MessagePacket(
|
val msg = MessagePacket(
|
||||||
type = MessageType.ENCRYPTED,
|
type = MessageType.ENCRYPTED,
|
||||||
source = Id.fromLong(136326824),
|
source = Id.fromLong(136326824),
|
||||||
destination = Id.fromLong(136326825),
|
destination = Id.fromLong(136326825),
|
||||||
sequenceNumber = 7.toByte(),
|
sequenceNumber = 7.toByte(),
|
||||||
ackNumber = 0.toByte(),
|
ackNumber = 0.toByte(),
|
||||||
eqos = 1.toShort(),
|
eqos = 1.toShort(),
|
||||||
priority = false,
|
priority = false,
|
||||||
lastMessage = false,
|
lastMessage = false,
|
||||||
gateway = false,
|
gateway = false,
|
||||||
sas = true,
|
sas = true,
|
||||||
tfs = false,
|
tfs = false,
|
||||||
payload = Hex.decode(payload.substring(32, payload.length))
|
payload = Hex.decode(payload.substring(32, payload.length))
|
||||||
)
|
)
|
||||||
assertEquals(msg.asByteArray().toHex(), payload)
|
assertEquals(msg.asByteArray().toHex(), payload)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,5 +18,3 @@ class PayloadJoinerTest {
|
||||||
assertEquals(payload, actual.toHex())
|
assertEquals(payload, actual.toHex())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,4 +23,4 @@ class PayloadSplitJoinTest {
|
||||||
assertEquals(got.toHex(), payload.toHex())
|
assertEquals(got.toHex(), payload.toHex())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,15 +10,15 @@ 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()
|
||||||
|
|
||||||
assertEquals(packets.size, 2)
|
assertEquals(packets.size, 2)
|
||||||
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() {
|
||||||
|
@ -19,4 +19,4 @@ class StringLengthPrefixEncodingTest {
|
||||||
assertEquals(parsed.size, 1)
|
assertEquals(parsed.size, 1)
|
||||||
assertEquals(parsed[0].toHex(), p0Content.toHex())
|
assertEquals(parsed[0].toHex(), p0Content.toHex())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,15 +11,15 @@ 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"))
|
||||||
assertEquals(ke.ltk.toHex(), "341e16d13f1cbf73b19d1c2964fee02b")
|
assertEquals(ke.ltk.toHex(), "341e16d13f1cbf73b19d1c2964fee02b")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue