From f61ba2552182b627ad2f43856f428d7a09a444d0 Mon Sep 17 00:00:00 2001 From: Levi Hoogenberg Date: Mon, 30 Sep 2024 16:26:20 +0200 Subject: [PATCH] FDP-2600: small readability improvement Signed-off-by: Levi Hoogenberg --- .../firmware/entity/FirmwarePacket.kt | 6 +----- .../firmware/repository/FirmwarePacketRepository.kt | 3 +-- .../gxf/crestdeviceservice/psk/service/PskService.kt | 10 ++++++---- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/components/firmware/src/main/kotlin/org/gxf/crestdeviceservice/firmware/entity/FirmwarePacket.kt b/components/firmware/src/main/kotlin/org/gxf/crestdeviceservice/firmware/entity/FirmwarePacket.kt index 09dc8e08..850d21e4 100644 --- a/components/firmware/src/main/kotlin/org/gxf/crestdeviceservice/firmware/entity/FirmwarePacket.kt +++ b/components/firmware/src/main/kotlin/org/gxf/crestdeviceservice/firmware/entity/FirmwarePacket.kt @@ -10,8 +10,4 @@ import jakarta.persistence.ManyToOne @Entity @IdClass(FirmwarePacketCompositeKey::class) -class FirmwarePacket( - @ManyToOne @Id val firmware: Firmware, - @Id val packetNumber: Int, - val packet: String -) +class FirmwarePacket(@ManyToOne @Id val firmware: Firmware, @Id val packetNumber: Int, val packet: String) diff --git a/components/firmware/src/main/kotlin/org/gxf/crestdeviceservice/firmware/repository/FirmwarePacketRepository.kt b/components/firmware/src/main/kotlin/org/gxf/crestdeviceservice/firmware/repository/FirmwarePacketRepository.kt index 53382f11..76ccb6de 100644 --- a/components/firmware/src/main/kotlin/org/gxf/crestdeviceservice/firmware/repository/FirmwarePacketRepository.kt +++ b/components/firmware/src/main/kotlin/org/gxf/crestdeviceservice/firmware/repository/FirmwarePacketRepository.kt @@ -8,5 +8,4 @@ import org.gxf.crestdeviceservice.firmware.entity.FirmwarePacketCompositeKey import org.springframework.data.repository.CrudRepository import org.springframework.stereotype.Repository -@Repository -interface FirmwarePacketRepository : CrudRepository +@Repository interface FirmwarePacketRepository : CrudRepository diff --git a/components/psk/src/main/kotlin/org/gxf/crestdeviceservice/psk/service/PskService.kt b/components/psk/src/main/kotlin/org/gxf/crestdeviceservice/psk/service/PskService.kt index eb3e6e81..6406c1e7 100644 --- a/components/psk/src/main/kotlin/org/gxf/crestdeviceservice/psk/service/PskService.kt +++ b/components/psk/src/main/kotlin/org/gxf/crestdeviceservice/psk/service/PskService.kt @@ -75,10 +75,12 @@ class PskService(private val pskRepository: PskRepository, private val pskConfig PreSharedKey(deviceId, newVersion, Instant.now(), newKey, previousPSK.secret, PreSharedKeyStatus.READY)) } - private fun generatePsk(): String = - secureRandom.ints(KEY_LENGTH, 0, ALLOWED_CHARACTERS.length).toArray().fold("") { acc, next -> - acc + ALLOWED_CHARACTERS[next] - } + private fun generatePsk() = + secureRandom + .ints(KEY_LENGTH, 0, ALLOWED_CHARACTERS.length) + .toArray() + .map { ALLOWED_CHARACTERS[it] } + .joinToString("") fun setPskToPendingForDevice(deviceId: String): PreSharedKey { val psk = getCurrentReadyPsk(deviceId) ?: throw NoExistingPskException("There is no new key ready to be set")