Skip to content

Commit b2c58ce

Browse files
author
Denis Trotsenko
committed
* Migrate to Ktlint 1.x
* Reformat code
1 parent 22d5764 commit b2c58ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+108
-91
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,23 @@ insert_final_newline = true
66
ij_continuation_indent_size = 4
77

88
[{*.kt,*.kts}]
9+
ktlint_standard_annotation = disabled
10+
ktlint_standard_property-naming = disabled
11+
ktlint_standard_function-naming = disabled
12+
ktlint_standard_multiline-expression-wrapping = disabled
13+
ktlint_standard_string-template-indent = disabled
14+
ktlint_standard_function-signature = disabled
15+
ktlint_standard_indent = disabled
16+
ktlint_standard_discouraged-comment-location = enabled
17+
ktlint_standard_no-empty-first-line-in-class-body = enabled
18+
ktlint_standard_blank-line-before-declaration = enabled
19+
ktlint_standard_if-else-bracing = enabled
20+
ktlint_standard_no-empty-file = enabled
21+
ktlint_standard_no-single-line-block-comment = enabled
22+
923
ij_kotlin_allow_trailing_comma = false
1024
ij_kotlin_allow_trailing_comma_on_call_site = false
1125
ij_kotlin_blank_lines_around_block_when_branches = 0
1226
ij_kotlin_name_count_to_use_star_import = 2147483647
1327
ij_kotlin_name_count_to_use_star_import_for_members = 2147483647
28+
ij_kotlin_packages_to_use_import_on_demand = unset

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ subprojects {
1616
target("**/*.kt")
1717
targetExclude("$buildDir/**/*.kt")
1818
targetExclude("bin/**/*.kt")
19-
ktlint(libs.versions.ktlint.get())
19+
ktlint()
2020
}
2121
}
2222
}

gradle/libs.versions.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
[versions]
22
kotlin = "1.8.22"
33
dokka = "1.9.10"
4-
ktlint = "0.48.2"
54
kotest = "5.6.1"
6-
spotless = "6.18.0"
5+
spotless = "6.24.0"
76
versions = "0.46.0"
87

98
[plugins]

kotpass/src/main/kotlin/app/keemobile/kotpass/builders/Entry.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import app.keemobile.kotpass.models.Entry
88
import app.keemobile.kotpass.models.EntryFields
99
import app.keemobile.kotpass.models.EntryValue
1010
import app.keemobile.kotpass.models.TimeData
11-
import java.util.*
11+
import java.util.UUID
1212

1313
internal class MutableEntry(
1414
var uuid: UUID,

kotpass/src/main/kotlin/app/keemobile/kotpass/builders/Group.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import app.keemobile.kotpass.models.CustomDataValue
66
import app.keemobile.kotpass.models.Entry
77
import app.keemobile.kotpass.models.Group
88
import app.keemobile.kotpass.models.TimeData
9-
import java.util.*
9+
import java.util.UUID
1010

1111
internal class MutableGroup(
1212
var uuid: UUID,

kotpass/src/main/kotlin/app/keemobile/kotpass/cryptography/AesEngine.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import javax.crypto.spec.IvParameterSpec
88
import javax.crypto.spec.SecretKeySpec
99

1010
internal object AesEngine {
11-
1211
fun encrypt(
1312
key: ByteArray,
1413
iv: ByteArray,

kotpass/src/main/kotlin/app/keemobile/kotpass/cryptography/AesKdf.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import javax.crypto.Cipher
99
import javax.crypto.spec.SecretKeySpec
1010

1111
internal object AesKdf {
12-
1312
fun transformKey(
1413
key: ByteArray,
1514
seed: ByteArray,

kotpass/src/main/kotlin/app/keemobile/kotpass/cryptography/Argon2Engine.kt

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ private const val Argon2PreHashDigestLength = 64
2929
private const val Argon2PreHashSeedLength = 72
3030
private const val Argon2SyncPoints = 4
3131

32-
/* Minimum and maximum digest size in bytes */
32+
// Minimum and maximum digest size in bytes
3333
private const val MinOutLen = 4
3434

35-
/* Minimum and maximum number of passes */
35+
// Minimum and maximum number of passes
3636
private const val M32L = 0xFFFFFFFFL
3737

3838
private val ZeroBytes = ByteArray(4)
@@ -70,16 +70,18 @@ internal class Argon2Engine(
7070
}
7171

7272
init {
73-
/* 2. Align memory size */
74-
/* Minimum memoryBlocks = 8L blocks, where L is the number of lanes */
73+
/**
74+
* 2. Align memory size
75+
* Minimum memoryBlocks = 8L blocks, where L is the number of lanes
76+
*/
7577
var memoryBlocks = memory
7678
if (memoryBlocks < 2 * Argon2SyncPoints * parallelism) {
7779
memoryBlocks = 2 * Argon2SyncPoints * parallelism
7880
}
7981
segmentLength = memoryBlocks / (parallelism * Argon2SyncPoints)
8082
laneLength = segmentLength * Argon2SyncPoints
8183

82-
/* Ensure that all segments have equal length */
84+
// Ensure that all segments have equal length
8385
memoryBlocks = segmentLength * (parallelism * Argon2SyncPoints)
8486

8587
blocks = Array(memoryBlocks) { Block() }
@@ -145,7 +147,7 @@ internal class Argon2Engine(
145147
val refLane = getRefLane(position, pseudoRandom)
146148
val refColumn = getRefColumn(position, index, pseudoRandom, refLane == position.lane)
147149

148-
/* 2 Creating a new block */
150+
// 2 Creating a new block
149151
val prevBlock = blocks[prevOffset]
150152
val refBlock = blocks[laneLength * refLane + refColumn]
151153
val currentBlock = blocks[currentOffset]
@@ -177,7 +179,7 @@ internal class Argon2Engine(
177179
inputBlock.v[5] = intToLong(type.id)
178180

179181
if (position.pass == 0 && position.slice == 0) {
180-
/* Don't forget to generate the first block of addresses: */
182+
// Don't forget to generate the first block of addresses:
181183
nextAddresses(filler, inputBlock, addressBlock)
182184
}
183185
}
@@ -188,10 +190,10 @@ internal class Argon2Engine(
188190

189191
private fun getPrevOffset(currentOffset: Int): Int {
190192
return if (currentOffset % laneLength == 0) {
191-
/* Last block in this lane */
193+
// Last block in this lane
192194
currentOffset + laneLength - 1
193195
} else {
194-
/* Previous block */
196+
// Previous block
195197
currentOffset - 1
196198
}
197199
}
@@ -202,8 +204,10 @@ internal class Argon2Engine(
202204
filler.fillBlock(addressBlock, addressBlock)
203205
}
204206

205-
/* 1.2 Computing the index of the reference block */
206-
/* 1.2.1 Taking pseudo-random value from the previous block */
207+
/**
208+
* 1.2 Computing the index of the reference block
209+
* 1.2.1 Taking pseudo-random value from the previous block
210+
*/
207211
private fun getPseudoRandom(
208212
filler: FillBlock,
209213
index: Int,
@@ -226,7 +230,7 @@ internal class Argon2Engine(
226230
private fun getRefLane(position: Position, pseudoRandom: Long): Int {
227231
var refLane = ((pseudoRandom ushr 32) % parallelism).toInt()
228232
if (position.pass == 0 && position.slice == 0) {
229-
/* Can not reference other lanes yet */
233+
// Can not reference other lanes yet
230234
refLane = position.lane
231235
}
232236
return refLane
@@ -244,10 +248,10 @@ internal class Argon2Engine(
244248
if (position.pass == 0) {
245249
startPosition = 0
246250
referenceAreaSize = if (sameLane) {
247-
/* The same lane => add current segment */
251+
// The same lane => add current segment
248252
position.slice * segmentLength + index - 1
249253
} else {
250-
/* pass == 0 && !sameLane => position.slice > 0*/
254+
// pass == 0 && !sameLane => position.slice > 0
251255
position.slice * segmentLength + if (index == 0) -1 else 0
252256
}
253257
} else {
@@ -268,7 +272,7 @@ internal class Argon2Engine(
268272
private fun digest(tmpBlockBytes: ByteArray, out: ByteArray, outOff: Int, outLen: Int) {
269273
val finalBlock = blocks[laneLength - 1]
270274

271-
/* XOR the last blocks */
275+
// XOR the last blocks
272276
for (i in 1 until parallelism) {
273277
val lastBlockInLane = i * laneLength + (laneLength - 1)
274278
finalBlock.xorWith(blocks[lastBlockInLane])
@@ -294,7 +298,7 @@ internal class Argon2Engine(
294298
var digest = Blake2bDigest(blake2bLength * 8)
295299
val outBuffer = ByteArray(blake2bLength)
296300

297-
/* V1 */
301+
// V1
298302
digest.update(outLenBytes, 0, outLenBytes.size)
299303
digest.update(input, 0, input.size)
300304
digest.doFinal(outBuffer, 0)
@@ -306,7 +310,7 @@ internal class Argon2Engine(
306310
var i = 2
307311

308312
while (i <= r) {
309-
/* V2 to Vr */
313+
// V2 to Vr
310314
digest.update(outBuffer, 0, outBuffer.size)
311315
digest.doFinal(outBuffer, 0)
312316
System.arraycopy(outBuffer, 0, out, outPos, halfLen)
@@ -315,7 +319,7 @@ internal class Argon2Engine(
315319
}
316320
val lastLength = outLen - 32 * r
317321

318-
/* Vr+1 */
322+
// Vr+1
319323
digest = Blake2bDigest(lastLength * 8)
320324
digest.update(outBuffer, 0, outBuffer.size)
321325
digest.doFinal(out, outPos)
@@ -375,9 +379,9 @@ internal class Argon2Engine(
375379

376380
private fun applyBlake() {
377381
/*
378-
* Apply Blake2 on columns of 64-bit words: (0,1,...,15),
379-
* then (16,17,..31)... finally (112,113,...127)
380-
*/
382+
* Apply Blake2 on columns of 64-bit words: (0,1,...,15),
383+
* then (16,17,..31)... finally (112,113,...127)
384+
*/
381385
for (i in 0..7) {
382386
val i16 = 16 * i
383387
roundFunction(
@@ -431,7 +435,7 @@ internal class Argon2Engine(
431435
private class Block {
432436
private val Size = Argon2QwordsInBlock
433437

434-
/* 128 * 8 Byte QWords */
438+
// 128 * 8 Byte QWords
435439
val v: LongArray = LongArray(Size)
436440

437441
fun fromBytes(input: ByteArray) {
@@ -488,7 +492,7 @@ internal class Argon2Engine(
488492

489493
private fun getStartingIndex(position: Position): Int {
490494
return if (position.pass == 0 && position.slice == 0) {
491-
2 /* we have already generated the first two blocks */
495+
2 // we have already generated the first two blocks
492496
} else {
493497
0
494498
}

kotpass/src/main/kotlin/app/keemobile/kotpass/cryptography/Argon2Kdf.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package app.keemobile.kotpass.cryptography
22

33
internal object Argon2Kdf {
4-
54
fun transformKey(
65
type: Argon2Engine.Type,
76
version: Argon2Engine.Version,

kotpass/src/main/kotlin/app/keemobile/kotpass/cryptography/Blake2bDigest.kt

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
*
44
* Copyright (c) 2000-2021 The Legion Of The Bouncy Castle Inc. (https://www.bouncycastle.org)
55
* <p>
6-
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7-
* and associated documentation files (the "Software"), to deal in the Software without restriction,
8-
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
9-
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
7+
* software and associated documentation files (the "Software"), to deal in the Software
8+
* without restriction, including without limitation the rights to use, copy, modify, merge,
9+
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
10+
* to whom the Software is furnished to do so,
1011
* subject to the following conditions:
1112
* <p>
12-
* The above copyright notice and this permission notice shall be included in all copies or substantial
13-
* portions of the Software.
13+
* The above copyright notice and this permission notice shall be included in all copies
14+
* or substantial portions of the Software.
1415
* <p>
1516
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
1617
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
@@ -47,17 +48,20 @@ internal class Blake2bDigest {
4748

4849
private var key: ByteArray? = null
4950

50-
// Tree hashing parameters:
51-
// Because this class does not implement the Tree Hashing Mode,
52-
// these parameters can be treated as constants (see init() function)
53-
/*
54-
* private int fanout = 1; // 0-255 private int depth = 1; // 1 - 255
55-
* private int leafLength= 0; private long nodeOffset = 0L; private int
56-
* nodeDepth = 0; private int innerHashLength = 0;
51+
/**
52+
* Tree hashing parameters:
53+
* Because this class does not implement the Tree Hashing Mode,
54+
* these parameters can be treated as constants (see init() function)
55+
*
56+
* private int fanout = 1;
57+
* 0-255 private int depth = 1;
58+
* 1-255 private int leafLength= 0;
59+
* private long nodeOffset = 0L;
60+
* private int nodeDepth = 0;
61+
* private int innerHashLength = 0;
62+
* whenever this buffer overflows, it will be processed in the compress() function.
63+
* For performance issues, long messages will not use this buffer.
5764
*/
58-
// whenever this buffer overflows, it will be processed
59-
// in the compress() function.
60-
// For performance issues, long messages will not use this buffer.
6165
private val buffer: ByteArray // new byte[BLOCK_LENGTH_BYTES];
6266

6367
// Position of last inserted byte:

kotpass/src/main/kotlin/app/keemobile/kotpass/cryptography/ContentEncryption.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package app.keemobile.kotpass.cryptography
33
import app.keemobile.kotpass.database.header.DatabaseHeader
44

55
internal object ContentEncryption {
6-
76
fun encrypt(
87
cipherId: DatabaseHeader.CipherId,
98
key: ByteArray,

kotpass/src/main/kotlin/app/keemobile/kotpass/cryptography/KeyTransform.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import app.keemobile.kotpass.extensions.sha256
1111
import app.keemobile.kotpass.extensions.sha512
1212

1313
internal object KeyTransform {
14-
1514
fun compositeKey(credentials: Credentials): ByteArray {
1615
val items = listOfNotNull(
1716
credentials.passphrase?.getBinary(),

kotpass/src/main/kotlin/app/keemobile/kotpass/database/Credentials.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class Credentials private constructor(
2424
val passphrase: EncryptedValue?,
2525
val key: EncryptedValue?
2626
) {
27-
2827
companion object {
2928
fun from(passphrase: EncryptedValue) = Credentials(
3029
passphrase = EncryptedValue.fromBinary(passphrase.getHash()),

kotpass/src/main/kotlin/app/keemobile/kotpass/database/KeePassDatabase.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import app.keemobile.kotpass.models.DatabaseElement
1010
import app.keemobile.kotpass.models.Entry
1111
import app.keemobile.kotpass.models.Group
1212
import app.keemobile.kotpass.models.Meta
13-
import java.util.*
13+
import java.util.UUID
1414

1515
/**
1616
* Main class which describes Keepass database.
@@ -25,7 +25,6 @@ sealed class KeePassDatabase {
2525
override val header: DatabaseHeader.Ver3x,
2626
override val content: DatabaseContent
2727
) : KeePassDatabase() {
28-
2928
companion object {
3029
/**
3130
* Creates blank database with default settings.
@@ -61,7 +60,6 @@ sealed class KeePassDatabase {
6160
override val content: DatabaseContent,
6261
val innerHeader: DatabaseInnerHeader
6362
) : KeePassDatabase() {
64-
6563
companion object {
6664
/**
6765
* Creates blank database with default settings.

kotpass/src/main/kotlin/app/keemobile/kotpass/database/header/DatabaseHeader.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import okio.BufferedSource
1515
import okio.ByteString
1616
import java.nio.ByteBuffer
1717
import java.security.SecureRandom
18-
import java.util.*
18+
import java.util.UUID
1919

2020
private val EndOfHeaderBytes = ByteString.of(0x0D, 0x0A, 0x0D, 0x0A)
2121

@@ -40,7 +40,6 @@ sealed class DatabaseHeader {
4040
val innerRandomStreamKey: ByteString,
4141
val streamStartBytes: ByteString
4242
) : DatabaseHeader() {
43-
4443
companion object {
4544
fun create() = with(SecureRandom()) {
4645
Ver3x(
@@ -70,7 +69,6 @@ sealed class DatabaseHeader {
7069
val kdfParameters: KdfParameters,
7170
val publicCustomData: Map<String, VariantItem>
7271
) : DatabaseHeader() {
73-
7472
companion object {
7573
fun create() = with(SecureRandom()) {
7674
Ver4x(

kotpass/src/main/kotlin/app/keemobile/kotpass/database/header/DatabaseInnerHeader.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ data class DatabaseInnerHeader(
2525
@PublishedApi
2626
internal val binaries: Map<ByteString, BinaryData> = linkedMapOf()
2727
) {
28-
2928
internal fun writeTo(sink: BufferedSink) = with(sink) {
3029
writeByte(InnerHeaderFieldId.StreamId)
3130
writeIntLe(Int.SIZE_BYTES)

kotpass/src/main/kotlin/app/keemobile/kotpass/database/header/Signature.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class Signature(
99
val base: ByteString,
1010
val secondary: ByteString
1111
) {
12-
1312
internal fun writeTo(sink: BufferedSink) = with(sink) {
1413
write(base)
1514
write(secondary)

0 commit comments

Comments
 (0)