format: ktlint

This commit is contained in:
Andrei Vereha 2021-03-06 11:10:19 +01:00
parent c71433ad1a
commit 4046828567
15 changed files with 37 additions and 37 deletions

View file

@ -86,7 +86,7 @@ class OmnipodDashBleManagerImpl @Inject constructor(
val keys = sessionKeys val keys = sessionKeys
val mIO = msgIO val mIO = msgIO
if (keys == null || mIO == null) { if (keys == null || mIO == null) {
//TODO handle reconnects // TODO handle reconnects
throw Exception("Not connected") throw Exception("Not connected")
} }
emitter.onNext(PodEvent.CommandSending(cmd)) emitter.onNext(PodEvent.CommandSending(cmd))

View file

@ -35,4 +35,4 @@ open class BleCommand(val data: ByteArray) {
override fun hashCode(): Int { override fun hashCode(): Int {
return data.contentHashCode() return data.contentHashCode()
} }
} }

View file

@ -17,4 +17,4 @@ class CryptSequence(var sqn: Long) {
} }
return ret return ret
} }
} }

View file

@ -22,12 +22,13 @@ class EnDecrypt(private val aapsLogger: AAPSLogger, private val nonce: Nonce, pr
aapsLogger.debug(LTag.PUMPBTCOMM, "Decrypt header ${header.toHex()} payload: ${payload.toHex()}") aapsLogger.debug(LTag.PUMPBTCOMM, "Decrypt header ${header.toHex()} payload: ${payload.toHex()}")
aapsLogger.debug(LTag.PUMPBTCOMM, "Decrypt NONCE ${n.toHex()}") aapsLogger.debug(LTag.PUMPBTCOMM, "Decrypt NONCE ${n.toHex()}")
cipher.init( cipher.init(
false, AEADParameters( false,
KeyParameter(ck), AEADParameters(
MAC_SIZE * 8, // in bits KeyParameter(ck),
n, MAC_SIZE * 8, // in bits
header n,
) header
)
) )
val decryptedPayload = ByteArray(payload.size - MAC_SIZE) val decryptedPayload = ByteArray(payload.size - MAC_SIZE)
cipher.processPacket(payload, 0, payload.size, decryptedPayload, 0) cipher.processPacket(payload, 0, payload.size, decryptedPayload, 0)
@ -44,12 +45,13 @@ class EnDecrypt(private val aapsLogger: AAPSLogger, private val nonce: Nonce, pr
val encryptedPayload = ByteArray(payload.size + MAC_SIZE) val encryptedPayload = ByteArray(payload.size + MAC_SIZE)
cipher.init( cipher.init(
true, AEADParameters( true,
KeyParameter(ck), AEADParameters(
MAC_SIZE * 8, // in bits KeyParameter(ck),
n, MAC_SIZE * 8, // in bits
header n,
) header
)
) )
cipher.processPacket(payload, 0, payload.size, encryptedPayload, 0) cipher.processPacket(payload, 0, payload.size, encryptedPayload, 0)
@ -60,4 +62,4 @@ class EnDecrypt(private val aapsLogger: AAPSLogger, private val nonce: Nonce, pr
private val MAC_SIZE = 8 private val MAC_SIZE = 8
} }
} }

View file

@ -20,4 +20,4 @@ data class Nonce(val prefix: ByteArray, var sqn: Long) {
} }
return prefix + ret return prefix + ret
} }
} }

View file

@ -29,7 +29,7 @@ class PayloadJoiner(private val firstPacket: ByteArray) {
firstPacket.size < FirstBlePacket.HEADER_SIZE_WITHOUT_MIDDLE_PACKETS -> firstPacket.size < FirstBlePacket.HEADER_SIZE_WITHOUT_MIDDLE_PACKETS ->
throw IncorrectPacketException(0, firstPacket) throw IncorrectPacketException(0, firstPacket)
fullFragments == 0 -> { fullFragments == 0 -> {
crc = ByteBuffer.wrap(firstPacket.copyOfRange(2, 6)).int.toUnsignedLong() crc = ByteBuffer.wrap(firstPacket.copyOfRange(2, 6)).int.toUnsignedLong()
val rest = firstPacket[6] val rest = firstPacket[6]
val end = min(rest + FirstBlePacket.HEADER_SIZE_WITHOUT_MIDDLE_PACKETS, BlePacket.MAX_SIZE) val end = min(rest + FirstBlePacket.HEADER_SIZE_WITHOUT_MIDDLE_PACKETS, BlePacket.MAX_SIZE)
@ -41,10 +41,10 @@ class PayloadJoiner(private val firstPacket: ByteArray) {
} }
// With middle packets // With middle packets
firstPacket.size < BlePacket.MAX_SIZE -> firstPacket.size < BlePacket.MAX_SIZE ->
throw IncorrectPacketException(0, firstPacket) throw IncorrectPacketException(0, firstPacket)
else -> { else -> {
fragments.add( fragments.add(
firstPacket.copyOfRange( firstPacket.copyOfRange(
FirstBlePacket.HEADER_SIZE_WITH_MIDDLE_PACKETS, FirstBlePacket.HEADER_SIZE_WITH_MIDDLE_PACKETS,
@ -65,7 +65,7 @@ class PayloadJoiner(private val firstPacket: ByteArray) {
} }
expectedIndex++ expectedIndex++
when { when {
idx < fullFragments -> { // this is a middle fragment idx < fullFragments -> { // this is a middle fragment
if (packet.size < BlePacket.MAX_SIZE) { if (packet.size < BlePacket.MAX_SIZE) {
throw IncorrectPacketException(idx.toByte(), packet) throw IncorrectPacketException(idx.toByte(), packet)
} }
@ -86,7 +86,7 @@ class PayloadJoiner(private val firstPacket: ByteArray) {
fragments.add(packet.copyOfRange(LastBlePacket.HEADER_SIZE, packet.size)) fragments.add(packet.copyOfRange(LastBlePacket.HEADER_SIZE, packet.size))
} }
idx > fullFragments -> { // this is the extra fragment idx > fullFragments -> { // this is the extra fragment
val size = packet[1].toInt() val size = packet[1].toInt()
if (packet.size < LastOptionalPlusOneBlePacket.HEADER_SIZE + size) { if (packet.size < LastOptionalPlusOneBlePacket.HEADER_SIZE + size) {
throw IncorrectPacketException(idx.toByte(), packet) throw IncorrectPacketException(idx.toByte(), packet)

View file

@ -18,15 +18,15 @@ class StringLengthPrefixEncoding {
var remaining = payload var remaining = payload
for ((index, key) in keys.withIndex()) { for ((index, key) in keys.withIndex()) {
when { when {
remaining.size < key.length -> remaining.size < key.length ->
throw MessageIOException("Payload too short: ${payload.toHex()} for key: $key") throw MessageIOException("Payload too short: ${payload.toHex()} for key: $key")
!(remaining.copyOfRange(0, key.length).decodeToString() == key) -> !(remaining.copyOfRange(0, key.length).decodeToString() == key) ->
throw MessageIOException("Key not found: $key in ${payload.toHex()}") throw MessageIOException("Key not found: $key in ${payload.toHex()}")
// last key can be empty, no length // last key can be empty, no length
index == keys.size - 1 && remaining.size == key.length -> index == keys.size - 1 && remaining.size == key.length ->
return ret return ret
remaining.size < key.length + LENGTH_BYTES -> remaining.size < key.length + LENGTH_BYTES ->
throw MessageIOException("Length not found: for $key in ${payload.toHex()}") throw MessageIOException("Length not found: for $key in ${payload.toHex()}")
} }
remaining = remaining.copyOfRange(key.length, remaining.size) remaining = remaining.copyOfRange(key.length, remaining.size)

View file

@ -44,7 +44,7 @@ sealed class EapAkaAttribute {
ret.add(EapAkaAttributeRes.parse(tail.copyOfRange(2, size))) ret.add(EapAkaAttributeRes.parse(tail.copyOfRange(2, size)))
EapAkaAttributeType.AT_CUSTOM_IV -> EapAkaAttributeType.AT_CUSTOM_IV ->
ret.add(EapAkaAttributeCustomIV.parse(tail.copyOfRange(2, size))) ret.add(EapAkaAttributeCustomIV.parse(tail.copyOfRange(2, size)))
else -> else ->
throw MessageIOException("Could not parse EAP attributes: ${payload.toHex()}. Expecting only AT_RES or CUSTOM_IV attribute types from the POD") throw MessageIOException("Could not parse EAP attributes: ${payload.toHex()}. Expecting only AT_RES or CUSTOM_IV attribute types from the POD")
} }
tail = tail.copyOfRange(size, tail.size) tail = tail.copyOfRange(size, tail.size)

View file

@ -15,4 +15,4 @@ class EapSqn(var sqn: Long) {
.array() .array()
.copyOfRange(2, 8) .copyOfRange(2, 8)
} }
} }

View file

@ -93,6 +93,5 @@ class Session(
private const val COMMAND_PREFIX = "S0.0=" private const val COMMAND_PREFIX = "S0.0="
private const val COMMAND_SUFFIX = ",G0.0" private const val COMMAND_SUFFIX = ",G0.0"
private const val RESPONSE_PREFIX = "0.0=" private const val RESPONSE_PREFIX = "0.0="
} }
} }

View file

@ -36,12 +36,12 @@ class SessionEstablisher(
fun negotiateSessionKeys(): SessionKeys { fun negotiateSessionKeys(): SessionKeys {
// send EAP-AKA challenge // send EAP-AKA challenge
sequenceNumber++ //TODO: get from pod state. This only works for activating a new pod sequenceNumber++ // TODO: get from pod state. This only works for activating a new pod
var challenge = eapAkaChallenge() var challenge = eapAkaChallenge()
msgIO.sendMessage(challenge) msgIO.sendMessage(challenge)
val challengeResponse = msgIO.receiveMessage() val challengeResponse = msgIO.receiveMessage()
processChallengeResponse(challengeResponse) //TODO: what do we have to answer if challenge response does not validate? processChallengeResponse(challengeResponse) // TODO: what do we have to answer if challenge response does not validate?
sequenceNumber++ sequenceNumber++
var success = eapSuccess() var success = eapSuccess()
@ -93,7 +93,7 @@ class SessionEstablisher(
} }
is EapAkaAttributeCustomIV -> is EapAkaAttributeCustomIV ->
nodeIV = attr.payload.copyOfRange(0, IV_SIZE) nodeIV = attr.payload.copyOfRange(0, IV_SIZE)
else -> else ->
throw SessionEstablishmentException("Unknown attribute received: $attr") throw SessionEstablishmentException("Unknown attribute received: $attr")
} }
} }

View file

@ -18,5 +18,5 @@ sealed class PodEvent {
/* Message exchange events */ /* Message exchange events */
class CommandSending(val command: Command) : PodEvent() class CommandSending(val command: Command) : PodEvent()
class CommandSent(val command: Command) : PodEvent() class CommandSent(val command: Command) : PodEvent()
class ResponseReceived(val response:Response) : PodEvent() class ResponseReceived(val response: Response) : PodEvent()
} }

View file

@ -13,7 +13,7 @@ class ProgramInsulinCommand internal constructor(
multiCommandFlag: Boolean, multiCommandFlag: Boolean,
nonce: Int, nonce: Int,
insulinProgramElements: insulinProgramElements:
List<ShortInsulinProgramElement>, List<ShortInsulinProgramElement>,
private val checksum: Short, private val checksum: Short,
private val byte9: Byte, private val byte9: Byte,
private val byte10And11: Short, private val byte10And11: Short,

View file

@ -35,7 +35,7 @@ class AlertConfiguration(
trigger.thresholdInMicroLiters trigger.thresholdInMicroLiters
} }
is AlertTrigger.TimerTrigger -> { is AlertTrigger.TimerTrigger -> {
trigger.offsetInMinutes trigger.offsetInMinutes
} }
} }

View file

@ -54,6 +54,5 @@ class EnDecryptTest {
val encrypted = enDecrypt.encrypt(msg) val encrypted = enDecrypt.encrypt(msg)
Assert.assertEquals(encryptedMessage.toHex(), encrypted.asByteArray().toHex()) Assert.assertEquals(encryptedMessage.toHex(), encrypted.asByteArray().toHex())
} }
} }