format: ktlint
This commit is contained in:
parent
c71433ad1a
commit
4046828567
15 changed files with 37 additions and 37 deletions
|
@ -86,7 +86,7 @@ class OmnipodDashBleManagerImpl @Inject constructor(
|
|||
val keys = sessionKeys
|
||||
val mIO = msgIO
|
||||
if (keys == null || mIO == null) {
|
||||
//TODO handle reconnects
|
||||
// TODO handle reconnects
|
||||
throw Exception("Not connected")
|
||||
}
|
||||
emitter.onNext(PodEvent.CommandSending(cmd))
|
||||
|
|
|
@ -35,4 +35,4 @@ open class BleCommand(val data: ByteArray) {
|
|||
override fun hashCode(): Int {
|
||||
return data.contentHashCode()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,4 +17,4 @@ class CryptSequence(var sqn: Long) {
|
|||
}
|
||||
return ret
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 NONCE ${n.toHex()}")
|
||||
cipher.init(
|
||||
false, AEADParameters(
|
||||
KeyParameter(ck),
|
||||
MAC_SIZE * 8, // in bits
|
||||
n,
|
||||
header
|
||||
)
|
||||
false,
|
||||
AEADParameters(
|
||||
KeyParameter(ck),
|
||||
MAC_SIZE * 8, // in bits
|
||||
n,
|
||||
header
|
||||
)
|
||||
)
|
||||
val decryptedPayload = ByteArray(payload.size - MAC_SIZE)
|
||||
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)
|
||||
|
||||
cipher.init(
|
||||
true, AEADParameters(
|
||||
KeyParameter(ck),
|
||||
MAC_SIZE * 8, // in bits
|
||||
n,
|
||||
header
|
||||
)
|
||||
true,
|
||||
AEADParameters(
|
||||
KeyParameter(ck),
|
||||
MAC_SIZE * 8, // in bits
|
||||
n,
|
||||
header
|
||||
)
|
||||
)
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,4 +20,4 @@ data class Nonce(val prefix: ByteArray, var sqn: Long) {
|
|||
}
|
||||
return prefix + ret
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class PayloadJoiner(private val firstPacket: ByteArray) {
|
|||
firstPacket.size < FirstBlePacket.HEADER_SIZE_WITHOUT_MIDDLE_PACKETS ->
|
||||
throw IncorrectPacketException(0, firstPacket)
|
||||
|
||||
fullFragments == 0 -> {
|
||||
fullFragments == 0 -> {
|
||||
crc = ByteBuffer.wrap(firstPacket.copyOfRange(2, 6)).int.toUnsignedLong()
|
||||
val rest = firstPacket[6]
|
||||
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
|
||||
firstPacket.size < BlePacket.MAX_SIZE ->
|
||||
firstPacket.size < BlePacket.MAX_SIZE ->
|
||||
throw IncorrectPacketException(0, firstPacket)
|
||||
|
||||
else -> {
|
||||
else -> {
|
||||
fragments.add(
|
||||
firstPacket.copyOfRange(
|
||||
FirstBlePacket.HEADER_SIZE_WITH_MIDDLE_PACKETS,
|
||||
|
@ -65,7 +65,7 @@ class PayloadJoiner(private val firstPacket: ByteArray) {
|
|||
}
|
||||
expectedIndex++
|
||||
when {
|
||||
idx < fullFragments -> { // this is a middle fragment
|
||||
idx < fullFragments -> { // this is a middle fragment
|
||||
if (packet.size < BlePacket.MAX_SIZE) {
|
||||
throw IncorrectPacketException(idx.toByte(), packet)
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ class PayloadJoiner(private val firstPacket: ByteArray) {
|
|||
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()
|
||||
if (packet.size < LastOptionalPlusOneBlePacket.HEADER_SIZE + size) {
|
||||
throw IncorrectPacketException(idx.toByte(), packet)
|
||||
|
|
|
@ -18,15 +18,15 @@ class StringLengthPrefixEncoding {
|
|||
var remaining = payload
|
||||
for ((index, key) in keys.withIndex()) {
|
||||
when {
|
||||
remaining.size < key.length ->
|
||||
remaining.size < key.length ->
|
||||
throw MessageIOException("Payload too short: ${payload.toHex()} for key: $key")
|
||||
!(remaining.copyOfRange(0, key.length).decodeToString() == key) ->
|
||||
throw MessageIOException("Key not found: $key in ${payload.toHex()}")
|
||||
// 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
|
||||
|
||||
remaining.size < key.length + LENGTH_BYTES ->
|
||||
remaining.size < key.length + LENGTH_BYTES ->
|
||||
throw MessageIOException("Length not found: for $key in ${payload.toHex()}")
|
||||
}
|
||||
remaining = remaining.copyOfRange(key.length, remaining.size)
|
||||
|
|
|
@ -44,7 +44,7 @@ sealed class EapAkaAttribute {
|
|||
ret.add(EapAkaAttributeRes.parse(tail.copyOfRange(2, size)))
|
||||
EapAkaAttributeType.AT_CUSTOM_IV ->
|
||||
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")
|
||||
}
|
||||
tail = tail.copyOfRange(size, tail.size)
|
||||
|
|
|
@ -15,4 +15,4 @@ class EapSqn(var sqn: Long) {
|
|||
.array()
|
||||
.copyOfRange(2, 8)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,6 +93,5 @@ class Session(
|
|||
private const val COMMAND_PREFIX = "S0.0="
|
||||
private const val COMMAND_SUFFIX = ",G0.0"
|
||||
private const val RESPONSE_PREFIX = "0.0="
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,12 +36,12 @@ class SessionEstablisher(
|
|||
|
||||
fun negotiateSessionKeys(): SessionKeys {
|
||||
// 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()
|
||||
msgIO.sendMessage(challenge)
|
||||
|
||||
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++
|
||||
var success = eapSuccess()
|
||||
|
@ -93,7 +93,7 @@ class SessionEstablisher(
|
|||
}
|
||||
is EapAkaAttributeCustomIV ->
|
||||
nodeIV = attr.payload.copyOfRange(0, IV_SIZE)
|
||||
else ->
|
||||
else ->
|
||||
throw SessionEstablishmentException("Unknown attribute received: $attr")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,5 +18,5 @@ sealed class PodEvent {
|
|||
/* Message exchange events */
|
||||
class CommandSending(val command: Command) : PodEvent()
|
||||
class CommandSent(val command: Command) : PodEvent()
|
||||
class ResponseReceived(val response:Response) : PodEvent()
|
||||
class ResponseReceived(val response: Response) : PodEvent()
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ class ProgramInsulinCommand internal constructor(
|
|||
multiCommandFlag: Boolean,
|
||||
nonce: Int,
|
||||
insulinProgramElements:
|
||||
List<ShortInsulinProgramElement>,
|
||||
List<ShortInsulinProgramElement>,
|
||||
private val checksum: Short,
|
||||
private val byte9: Byte,
|
||||
private val byte10And11: Short,
|
||||
|
|
|
@ -35,7 +35,7 @@ class AlertConfiguration(
|
|||
trigger.thresholdInMicroLiters
|
||||
}
|
||||
|
||||
is AlertTrigger.TimerTrigger -> {
|
||||
is AlertTrigger.TimerTrigger -> {
|
||||
trigger.offsetInMinutes
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,6 +54,5 @@ class EnDecryptTest {
|
|||
val encrypted = enDecrypt.encrypt(msg)
|
||||
|
||||
Assert.assertEquals(encryptedMessage.toHex(), encrypted.asByteArray().toHex())
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue