2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-31 14:15:14 +00:00

Migrate RandomHelper to Kotlin

This commit is contained in:
TPJ Schikhof
2024-08-21 18:55:00 +00:00
committed by Albert Vaca Cintora
parent 5f18cb571d
commit 69495136da
2 changed files with 22 additions and 28 deletions

View File

@@ -1,28 +0,0 @@
/*
* SPDX-FileCopyrightText: 2023 Albert Vaca Cintora <albertvaka@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
package org.kde.kdeconnect.Helpers;
import java.security.SecureRandom;
public class RandomHelper {
public static final SecureRandom secureRandom = new SecureRandom();
private static final char[] symbols = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
"abcdefghijklmnopqrstuvwxyz" +
"1234567890").toCharArray();
public static String randomString(int length) {
char[] buffer = new char[length];
for (int idx = 0; idx < length; ++idx) {
buffer[idx] = symbols[secureRandom.nextInt(symbols.length)];
}
return new String(buffer);
}
}

View File

@@ -0,0 +1,22 @@
/*
* SPDX-FileCopyrightText: 2023 Albert Vaca Cintora <albertvaka@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
package org.kde.kdeconnect.Helpers
import java.security.SecureRandom
object RandomHelper {
@JvmField
val secureRandom: SecureRandom = SecureRandom()
private val symbols = (('A'..'Z').toList() + ('a'..'z').toList() + ('0'..'9').toList()).toCharArray()
fun randomString(length: Int): String {
val buffer = CharArray(length)
for (i in 0 until length) {
buffer[i] = symbols[secureRandom.nextInt(symbols.size)]
}
return String(buffer)
}
}