Skip to content

Commit

Permalink
refactor:change some wildcard import
Browse files Browse the repository at this point in the history
  • Loading branch information
Leon406 committed Aug 31, 2021
1 parent 16be459 commit 8cccc5e
Show file tree
Hide file tree
Showing 22 changed files with 130 additions and 39 deletions.
2 changes: 1 addition & 1 deletion config/codeQuality.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ spotless {
}
kotlin {
target "src/**/*.kt"
ktfmt('0.27').kotlinlangStyle()
ktfmt('0.28').kotlinlangStyle()
}
}
2 changes: 1 addition & 1 deletion config/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,6 @@ style:
VarCouldBeVal:
active: true
WildcardImport:
active: false
active: true
excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**']
excludeImports: ''
3 changes: 2 additions & 1 deletion src/main/kotlin/me/leon/MyApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package me.leon

import javafx.scene.image.Image
import me.leon.view.Home
import tornadofx.*
import tornadofx.App
import tornadofx.addStageIcon

class MyApp : App(Home::class, Styles::class) {
init {
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/me/leon/base/Base16.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ fun String.base16() = toByteArray().base16()

fun String.base16Decode() =
toCharArray()
.joinToString("") { BASE16_MAP.indexOf(it).toString(2).padding("0", BASE16_BLOCK_SIZE, false) }
.joinToString("") {
BASE16_MAP.indexOf(it).toString(2).padding("0", BASE16_BLOCK_SIZE, false)
}
.chunked(BYTE_BITS)
.map { it.toInt(2).toByte() }
.filter { it.toInt() != 0 }
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/me/leon/base/Base32.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ fun String.base32() = toByteArray().base32()
fun String.base32Decode() =
toCharArray()
.filter { it != '=' }
.joinToString("") { BASE32_MAP.indexOf(it).toString(2).padding("0", BASE32_BLOCK_SIZE, false) }
.joinToString("") {
BASE32_MAP.indexOf(it).toString(2).padding("0", BASE32_BLOCK_SIZE, false)
}
.chunked(BYTE_BITS)
.map { it.toInt(2).toByte() }
.filter { it.toInt() != 0 }
Expand Down
11 changes: 7 additions & 4 deletions src/main/kotlin/me/leon/base/Base64.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ fun String.base64DecodeString() =
toCharArray()
.filter { it != '=' }
.joinToString("") {
BASE64_MAP.indexOf(it).toString(2)
.padding("0", BASE64_BLOCK_SIZE, false)
BASE64_MAP.indexOf(it).toString(2).padding("0", BASE64_BLOCK_SIZE, false)
}
.chunked(BYTE_BITS)
.filter { it.length == BYTE_BITS }
Expand All @@ -53,7 +52,9 @@ fun String.base64Decode() =
// Base64.getDecoder().decode(this)
toCharArray()
.filter { it != '=' }
.joinToString("") { BASE64_MAP.indexOf(it).toString(2).padding("0", BASE64_BLOCK_SIZE, false) }
.joinToString("") {
BASE64_MAP.indexOf(it).toString(2).padding("0", BASE64_BLOCK_SIZE, false)
}
.chunked(BYTE_BITS)
.filter { it.length == BYTE_BITS }
.map { (it.toInt(2) and BYTE_MASK).toByte() }
Expand All @@ -65,7 +66,9 @@ fun String.safeBase64Decode2() =
.replace("-", "+")
.toCharArray()
.filter { it != '=' }
.joinToString("") { BASE64_MAP.indexOf(it).toString(2).padding("0", BASE64_BLOCK_SIZE, false) }
.joinToString("") {
BASE64_MAP.indexOf(it).toString(2).padding("0", BASE64_BLOCK_SIZE, false)
}
.chunked(BYTE_BITS)
.filter { it.length == BYTE_BITS }
.map { it.toInt(2).toByte() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import java.security.cert.CertificateFactory
import java.security.spec.PKCS8EncodedKeySpec
import java.security.spec.X509EncodedKeySpec
import javax.crypto.Cipher
import me.leon.base.*
import me.leon.base.BYTE_BITS
import me.leon.base.base64
import me.leon.base.base64Decode
import me.leon.ext.stacktrace
import org.bouncycastle.jce.provider.BouncyCastleProvider
import tornadofx.*
import tornadofx.Controller

class AsymmetricCryptoController : Controller() {

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/me/leon/controller/DigestController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package me.leon.controller

import me.leon.Digests
import me.leon.ext.stacktrace
import tornadofx.*
import tornadofx.Controller

class DigestController : Controller() {
fun digest(method: String, data: String) =
Expand Down
28 changes: 24 additions & 4 deletions src/main/kotlin/me/leon/controller/EncodeController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,30 @@ package me.leon.controller

import java.net.URLDecoder
import java.net.URLEncoder
import java.util.*
import me.leon.base.*
import me.leon.ext.*
import tornadofx.*
import java.util.Base64
import me.leon.base.base16
import me.leon.base.base16Decode
import me.leon.base.base16Decode2String
import me.leon.base.base32
import me.leon.base.base32Decode
import me.leon.base.base32Decode2String
import me.leon.base.base58
import me.leon.base.base58Check
import me.leon.base.base58CheckDecode
import me.leon.base.base58CheckDecode2String
import me.leon.base.base58Decode
import me.leon.base.base58Decode2String
import me.leon.ext.EncodeType
import me.leon.ext.binary2Ascii
import me.leon.ext.binary2ByteArray
import me.leon.ext.hex2Ascii
import me.leon.ext.hex2ByteArray
import me.leon.ext.stacktrace
import me.leon.ext.toBinaryString
import me.leon.ext.toHex
import me.leon.ext.toUnicodeString
import me.leon.ext.unicode2String
import tornadofx.Controller

class EncodeController : Controller() {
fun encode2String(raw: String, type: EncodeType = EncodeType.Base64): String =
Expand Down
8 changes: 6 additions & 2 deletions src/main/kotlin/me/leon/controller/MacController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ package me.leon.controller
import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec
import me.leon.base.base64
import me.leon.ext.*
import me.leon.ext.GMac
import me.leon.ext.Poly1305Serial
import me.leon.ext.init
import me.leon.ext.stacktrace
import me.leon.ext.toHex
import org.bouncycastle.crypto.macs.KGMac
import tornadofx.*
import tornadofx.Controller

class MacController : Controller() {
fun mac(msg: String, hkey: String, alg: String, outputEncode: String) =
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/me/leon/controller/SignatureController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.security.spec.X509EncodedKeySpec
import me.leon.base.base64
import me.leon.base.base64Decode
import me.leon.ext.stacktrace
import tornadofx.*
import tornadofx.Controller

fun String.properKeyPairAlg() = takeUnless { it.equals("SM2", true) } ?: "EC"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package me.leon.controller

import java.io.File
import java.nio.charset.Charset
import java.util.*
import java.util.Base64
import javax.crypto.Cipher
import javax.crypto.CipherOutputStream
import javax.crypto.SecretKey
import javax.crypto.spec.IvParameterSpec
import javax.crypto.spec.SecretKeySpec
import me.leon.base.base64
import me.leon.ext.stacktrace
import tornadofx.*
import tornadofx.Controller

class SymmetricCryptoController : Controller() {
fun encrypt(
Expand Down
14 changes: 11 additions & 3 deletions src/main/kotlin/me/leon/ext/Converter.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package me.leon.ext

import java.math.BigInteger
import me.leon.base.BYTE_BITS
import me.leon.base.BYTE_MASK
import java.math.BigInteger

const val HEX_RADIX = 16
const val DECIMAL_RADIX = 10
Expand All @@ -12,7 +12,11 @@ fun ByteArray.toHex() = String.format("%02x", BigInteger(1, this))
fun String.hex2Ascii() = String(hex2ByteArray(), Charsets.UTF_8)

fun String.hex2ByteArray() =
toCharArray().toList().chunked(2).map { it.joinToString("").toInt(HEX_RADIX).toByte() }.toByteArray()
toCharArray()
.toList()
.chunked(2)
.map { it.joinToString("").toInt(HEX_RADIX).toByte() }
.toByteArray()

fun ByteArray.toBinaryString() =
joinToString("") {
Expand All @@ -27,7 +31,11 @@ fun String.toBinaryString() = toByteArray().toBinaryString()
fun String.binary2Ascii() = String(binary2ByteArray(), Charsets.UTF_8)

fun String.binary2ByteArray() =
toCharArray().toList().chunked(BYTE_BITS).map { it.joinToString("").toInt(2).toByte() }.toByteArray()
toCharArray()
.toList()
.chunked(BYTE_BITS)
.map { it.joinToString("").toInt(2).toByte() }
.toByteArray()

/** unicode编解码 */
fun String.toUnicodeString() =
Expand Down
12 changes: 11 additions & 1 deletion src/main/kotlin/me/leon/ext/GMac.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@ package me.leon.ext
import org.bouncycastle.crypto.BlockCipher
import org.bouncycastle.crypto.CipherParameters
import org.bouncycastle.crypto.Mac
import org.bouncycastle.crypto.engines.*
import org.bouncycastle.crypto.engines.AESEngine
import org.bouncycastle.crypto.engines.ARIAEngine
import org.bouncycastle.crypto.engines.CAST6Engine
import org.bouncycastle.crypto.engines.CamelliaEngine
import org.bouncycastle.crypto.engines.DSTU7624Engine
import org.bouncycastle.crypto.engines.NoekeonEngine
import org.bouncycastle.crypto.engines.RC6Engine
import org.bouncycastle.crypto.engines.SEEDEngine
import org.bouncycastle.crypto.engines.SM4Engine
import org.bouncycastle.crypto.engines.TnepresEngine
import org.bouncycastle.crypto.engines.TwofishEngine
import org.bouncycastle.crypto.macs.GMac
import org.bouncycastle.crypto.macs.KGMac
import org.bouncycastle.crypto.modes.GCMBlockCipher
Expand Down
11 changes: 10 additions & 1 deletion src/main/kotlin/me/leon/ext/Poly1305Serial.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ package me.leon.ext

import org.bouncycastle.crypto.BlockCipher
import org.bouncycastle.crypto.CipherParameters
import org.bouncycastle.crypto.engines.*
import org.bouncycastle.crypto.engines.AESEngine
import org.bouncycastle.crypto.engines.ARIAEngine
import org.bouncycastle.crypto.engines.CAST6Engine
import org.bouncycastle.crypto.engines.CamelliaEngine
import org.bouncycastle.crypto.engines.NoekeonEngine
import org.bouncycastle.crypto.engines.RC6Engine
import org.bouncycastle.crypto.engines.SEEDEngine
import org.bouncycastle.crypto.engines.SM4Engine
import org.bouncycastle.crypto.engines.TnepresEngine
import org.bouncycastle.crypto.engines.TwofishEngine
import org.bouncycastle.crypto.macs.Poly1305
import org.bouncycastle.crypto.params.KeyParameter
import org.bouncycastle.crypto.params.ParametersWithIV
Expand Down
10 changes: 8 additions & 2 deletions src/main/kotlin/me/leon/ext/Zxing.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package me.leon.ext

import com.google.zxing.*
import com.google.zxing.BarcodeFormat
import com.google.zxing.BinaryBitmap
import com.google.zxing.DecodeHintType
import com.google.zxing.EncodeHintType
import com.google.zxing.MultiFormatReader
import com.google.zxing.MultiFormatWriter
import com.google.zxing.NotFoundException
import com.google.zxing.client.j2se.BufferedImageLuminanceSource
import com.google.zxing.client.j2se.MatrixToImageWriter
import com.google.zxing.common.HybridBinarizer
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
import java.awt.image.BufferedImage
import java.io.File
import java.io.IOException
import java.util.*
import java.util.Hashtable
import javax.imageio.ImageIO

/** 识别二维码 */
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/me/leon/view/DigestView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import javafx.scene.control.TextArea
import javafx.scene.input.DragEvent
import me.leon.controller.DigestController
import me.leon.ext.DEFAULT_SPACING
import me.leon.ext.DEFAULT_SPACING_2X
import me.leon.ext.copy
import tornadofx.*

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/me/leon/view/EncodeTransferView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class EncodeTransferView : View("编码转换") {

tilepane {
paddingTop = DEFAULT_SPACING
hgap = DEFAULT_SPACING *2
hgap = DEFAULT_SPACING * 2
alignment = Pos.CENTER
button("转换") {
action { run() }
Expand Down
5 changes: 4 additions & 1 deletion src/main/kotlin/me/leon/view/EncodeView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import javafx.scene.control.RadioButton
import javafx.scene.control.TextArea
import javafx.scene.input.DragEvent
import me.leon.controller.EncodeController
import me.leon.ext.*
import me.leon.ext.DEFAULT_SPACING
import me.leon.ext.EncodeType
import me.leon.ext.copy
import me.leon.ext.encodeType
import tornadofx.*

class EncodeView : View("编解码") {
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/me/leon/view/Home.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package me.leon.view

import java.security.Security
import org.bouncycastle.jce.provider.BouncyCastleProvider
import tornadofx.*
import tornadofx.View
import tornadofx.tabpane

class Home : View("开发工具集 (ToolsFx) by Leon406 ") {
override val root = tabpane {
Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/me/leon/view/MacView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import javafx.beans.property.SimpleBooleanProperty
import javafx.beans.property.SimpleStringProperty
import javafx.event.EventHandler
import javafx.geometry.Pos
import javafx.scene.control.*
import javafx.scene.control.ComboBox
import javafx.scene.control.Label
import javafx.scene.control.RadioButton
import javafx.scene.control.TextArea
import javafx.scene.control.TextField
import javafx.scene.input.DragEvent
import me.leon.controller.MacController
import me.leon.ext.DEFAULT_SPACING
Expand Down
29 changes: 23 additions & 6 deletions src/main/kotlin/me/leon/view/QrcodeView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,33 @@ import javafx.scene.control.Label
import javafx.scene.control.TextArea
import javafx.scene.image.Image
import javafx.scene.image.ImageView
import javafx.scene.input.*
import javafx.scene.layout.*
import javafx.scene.input.KeyCode
import javafx.scene.input.KeyCombination
import javafx.scene.input.KeyEvent
import javafx.scene.input.MouseEvent
import javafx.scene.layout.AnchorPane
import javafx.scene.layout.Border
import javafx.scene.layout.BorderStroke
import javafx.scene.layout.BorderStrokeStyle
import javafx.scene.layout.BorderWidths
import javafx.scene.layout.HBox
import javafx.scene.paint.Paint
import javafx.stage.Stage
import javafx.stage.StageStyle
import kotlin.math.abs
import me.leon.ext.*
import me.leon.ext.DEFAULT_SPACING_20X
import me.leon.ext.DEFAULT_SPACING_2X
import me.leon.ext.DEFAULT_SPACING_3X
import me.leon.ext.DEFAULT_SPACING_4X
import me.leon.ext.clipboardImage
import me.leon.ext.clipboardText
import me.leon.ext.copy
import me.leon.ext.createQR
import me.leon.ext.fileChooser
import me.leon.ext.qrReader
import me.leon.ext.showToast
import me.leon.ext.toBufferImage
import me.leon.ext.toFxImg
import tornadofx.*

class QrcodeView : View("Qrcode") {
Expand Down Expand Up @@ -107,9 +127,6 @@ class QrcodeView : View("Qrcode") {
alignment = Pos.CENTER
iv = imageview()
}
val keyCombination: KeyCombination = KeyCombination.valueOf("ctrl+alt+p")
val mc = Mnemonic(bu, keyCombination)
scene?.addMnemonic(mc)
}

private fun show() {
Expand Down

0 comments on commit 8cccc5e

Please sign in to comment.