-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78a7a35
commit 60c2100
Showing
3 changed files
with
14 additions
and
19 deletions.
There are no files selected for viewing
14 changes: 13 additions & 1 deletion
14
tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/Crypto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
package dev.inmo.tgbotapi.utils | ||
|
||
import dev.inmo.micro_utils.crypto.SourceBytes | ||
import dev.inmo.micro_utils.crypto.SourceString | ||
|
||
internal expect fun SourceString.hmacSha256(key: String): String | ||
private val HEX_ARRAY = "0123456789abcdef".toCharArray() | ||
|
||
internal expect fun SourceString.hex(): String | ||
internal fun SourceBytes.hex(): String { | ||
val hexChars = CharArray(size * 2) | ||
for (j in indices) { | ||
val v: Int = this[j].toInt() and 0xFF | ||
hexChars[j * 2] = HEX_ARRAY[v ushr 4] | ||
hexChars[j * 2 + 1] = HEX_ARRAY[v and 0x0F] | ||
} | ||
return hexChars.concatToString() | ||
} | ||
|
||
internal fun SourceString.hex(): String = encodeToByteArray().hex() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters