This repository was archived by the owner on Oct 15, 2024. It is now read-only.
File tree 2 files changed +20
-20
lines changed
crypto-pgpainless/src/main/kotlin/dev/msfjarvis/aps/crypto
2 files changed +20
-20
lines changed Original file line number Diff line number Diff line change 5
5
6
6
package dev.msfjarvis.aps.crypto
7
7
8
+ import java.util.Locale
8
9
import java.util.regex.Pattern
9
10
10
11
public sealed class GpgIdentifier {
11
12
public data class KeyId (val id : Long ) : GpgIdentifier() {
12
13
override fun toString (): String {
13
- return java.lang.Long .toHexString(id)
14
+ return convertKeyIdToHex(id)
15
+ }
16
+
17
+ /* * Convert a [Long] key ID to a formatted string. */
18
+ private fun convertKeyIdToHex (keyId : Long ): String {
19
+ return convertKeyIdToHex32bit(keyId shr 32 ) + convertKeyIdToHex32bit(keyId)
20
+ }
21
+
22
+ /* *
23
+ * Converts [keyId] to an unsigned [Long] then uses [java.lang.Long.toHexString] to convert it
24
+ * to a lowercase hex ID.
25
+ */
26
+ private fun convertKeyIdToHex32bit (keyId : Long ): String {
27
+ var hexString = java.lang.Long .toHexString(keyId and 0xffffffffL ).lowercase(Locale .ENGLISH )
28
+ while (hexString.length < 8 ) {
29
+ hexString = " 0$hexString "
30
+ }
31
+ return hexString
14
32
}
15
33
}
16
34
public data class UserId (val email : String ) : GpgIdentifier() {
Original file line number Diff line number Diff line change @@ -8,7 +8,6 @@ package dev.msfjarvis.aps.crypto
8
8
import com.github.michaelbull.result.get
9
9
import com.github.michaelbull.result.runCatching
10
10
import dev.msfjarvis.aps.crypto.GpgIdentifier.KeyId
11
- import java.util.Locale
12
11
import org.bouncycastle.openpgp.PGPKeyRing
13
12
import org.pgpainless.PGPainless
14
13
@@ -33,23 +32,6 @@ public object KeyUtils {
33
32
/* * Parses a [PGPKeyRing] from the given [key] and calculates its long key ID */
34
33
public fun tryGetId (key : PGPKey ): KeyId ? {
35
34
val keyRing = tryParseKeyring(key) ? : return null
36
- return KeyId (convertKeyIdToHex(keyRing.publicKey.keyID).toLong(radix = 16 ))
37
- }
38
-
39
- /* * Convert a [Long] key ID to a formatted string. */
40
- private fun convertKeyIdToHex (keyId : Long ): String {
41
- return convertKeyIdToHex32bit(keyId shr 32 ) + convertKeyIdToHex32bit(keyId)
42
- }
43
-
44
- /* *
45
- * Converts [keyId] to an unsigned [Long] then uses [java.lang.Long.toHexString] to convert it to
46
- * a lowercase hex ID.
47
- */
48
- private fun convertKeyIdToHex32bit (keyId : Long ): String {
49
- var hexString = java.lang.Long .toHexString(keyId and 0xffffffffL ).lowercase(Locale .ENGLISH )
50
- while (hexString.length < 8 ) {
51
- hexString = " 0$hexString "
52
- }
53
- return hexString
35
+ return KeyId (keyRing.publicKey.keyID)
54
36
}
55
37
}
You can’t perform that action at this time.
0 commit comments