Skip to content

Commit aa4828f

Browse files
committed
Move crypto/pdfviewer to lib
1 parent ced2b70 commit aa4828f

37 files changed

Lines changed: 93 additions & 130 deletions

File tree

shared/src/commonMain/kotlin/com/ismartcoding/plain/crypto/ECDHKeyPair.kt renamed to shared-lib/src/commonMain/kotlin/com/ismartcoding/plain/lib/crypto/ECDHKeyPair.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ismartcoding.plain.crypto
1+
package com.ismartcoding.plain.lib.crypto
22

33
data class ECDHKeyPair(
44
val privateKeyEncoded: ByteArray,
@@ -12,4 +12,4 @@ data class ECDHKeyPair(
1212
}
1313

1414
override fun hashCode(): Int = privateKeyEncoded.contentHashCode() * 31 + publicKeyEncoded.contentHashCode()
15-
}
15+
}

shared/src/commonMain/kotlin/com/ismartcoding/plain/crypto/Sha1.kt renamed to shared-lib/src/commonMain/kotlin/com/ismartcoding/plain/lib/crypto/Sha1.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ismartcoding.plain.crypto
1+
package com.ismartcoding.plain.lib.crypto
22

33
/**
44
* Pure-Kotlin SHA-1 implementation returning raw 20-byte digest.
@@ -8,7 +8,7 @@ package com.ismartcoding.plain.crypto
88
* non-security uses (e.g. deriving a stable file path from a URL) where the
99
* digest is treated as an opaque key, not as a security guarantee.
1010
*/
11-
internal fun sha1(input: ByteArray): ByteArray {
11+
fun sha1(input: ByteArray): ByteArray {
1212
val h = intArrayOf(
1313
0x67452301, 0xEFCDAB89.toInt(), 0x98BADCFE.toInt(), 0x10325476, 0xC3D2E1F0.toInt(),
1414
)
@@ -26,15 +26,19 @@ internal fun sha1(input: ByteArray): ByteArray {
2626
for (block in padded.indices step 64) {
2727
for (i in 0 until 16) {
2828
w[i] = ((padded[block + i * 4].toInt() and 0xFF) shl 24) or
29-
((padded[block + i * 4 + 1].toInt() and 0xFF) shl 16) or
30-
((padded[block + i * 4 + 2].toInt() and 0xFF) shl 8) or
31-
(padded[block + i * 4 + 3].toInt() and 0xFF)
29+
((padded[block + i * 4 + 1].toInt() and 0xFF) shl 16) or
30+
((padded[block + i * 4 + 2].toInt() and 0xFF) shl 8) or
31+
(padded[block + i * 4 + 3].toInt() and 0xFF)
3232
}
3333
for (i in 16 until 80) {
3434
w[i] = rotateLeft(w[i - 3] xor w[i - 8] xor w[i - 14] xor w[i - 16], 1)
3535
}
3636

37-
var a = h[0]; var b = h[1]; var c = h[2]; var d = h[3]; var e = h[4]
37+
var a = h[0];
38+
var b = h[1];
39+
var c = h[2];
40+
var d = h[3];
41+
var e = h[4]
3842
for (i in 0 until 80) {
3943
val (f, k) = when (i) {
4044
in 0..19 -> ((b and c) or (b.inv() and d)) to 0x5A827999

shared/src/commonMain/kotlin/com/ismartcoding/plain/crypto/Sha256.kt renamed to shared-lib/src/commonMain/kotlin/com/ismartcoding/plain/lib/crypto/Sha256.kt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package com.ismartcoding.plain.crypto
1+
package com.ismartcoding.plain.lib.crypto
22

33
/**
44
* Pure-Kotlin SHA-256 implementation returning raw 32-byte digest.
55
* Used by pairing crypto on platforms without a native SHA-256 entry point
66
* (e.g. iOS Security framework exposes ECDH but not a raw SHA-256 on raw bytes).
77
*/
8-
internal fun sha256(input: ByteArray): ByteArray {
8+
fun sha256(input: ByteArray): ByteArray {
99
val h = intArrayOf(
1010
0x6a09e667, 0xbb67ae85.toInt(), 0x3c6ef372, 0xa54ff53a.toInt(),
1111
0x510e527f, 0x9b05688c.toInt(), 0x1f83d9ab, 0x5be0cd19,
@@ -40,17 +40,23 @@ internal fun sha256(input: ByteArray): ByteArray {
4040
for (block in padded.indices step 64) {
4141
for (i in 0 until 16) {
4242
w[i] = ((padded[block + i * 4].toInt() and 0xFF) shl 24) or
43-
((padded[block + i * 4 + 1].toInt() and 0xFF) shl 16) or
44-
((padded[block + i * 4 + 2].toInt() and 0xFF) shl 8) or
45-
(padded[block + i * 4 + 3].toInt() and 0xFF)
43+
((padded[block + i * 4 + 1].toInt() and 0xFF) shl 16) or
44+
((padded[block + i * 4 + 2].toInt() and 0xFF) shl 8) or
45+
(padded[block + i * 4 + 3].toInt() and 0xFF)
4646
}
4747
for (i in 16 until 64) {
4848
val s0 = rotateRight(w[i - 15], 7) xor rotateRight(w[i - 15], 18) xor (w[i - 15] ushr 3)
4949
val s1 = rotateRight(w[i - 2], 17) xor rotateRight(w[i - 2], 19) xor (w[i - 2] ushr 10)
5050
w[i] = w[i - 16] + s0 + w[i - 7] + s1
5151
}
52-
var a = h[0]; var b = h[1]; var c = h[2]; var d = h[3]
53-
var e = h[4]; var f = h[5]; var g = h[6]; var hh = h[7]
52+
var a = h[0];
53+
var b = h[1];
54+
var c = h[2];
55+
var d = h[3]
56+
var e = h[4];
57+
var f = h[5];
58+
var g = h[6];
59+
var hh = h[7]
5460
for (i in 0 until 64) {
5561
val s1 = rotateRight(e, 6) xor rotateRight(e, 11) xor rotateRight(e, 25)
5662
val ch = (e and f) xor (e.inv() and g)

shared/src/commonMain/kotlin/com/ismartcoding/plain/crypto/Sha512.kt renamed to shared-lib/src/commonMain/kotlin/com/ismartcoding/plain/lib/crypto/Sha512.kt

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ismartcoding.plain.crypto
1+
package com.ismartcoding.plain.lib.crypto
22

33
/**
44
* Pure-Kotlin SHA-512 implementation returning raw 64-byte digest.
@@ -8,7 +8,7 @@ package com.ismartcoding.plain.crypto
88
* cinterop bindings). Mirrors the algorithm of `sha256` but operates on
99
* 64-bit words with a 1024-bit block size per FIPS 180-4.
1010
*/
11-
internal fun sha512(input: ByteArray): ByteArray {
11+
fun sha512(input: ByteArray): ByteArray {
1212
val h = longArrayOf(
1313
0x6a09e667f3bcc908uL.toLong(), 0xbb67ae8584caa73buL.toLong(),
1414
0x3c6ef372fe94f82buL.toLong(), 0xa54ff53a5f1d36f1uL.toLong(),
@@ -75,22 +75,28 @@ internal fun sha512(input: ByteArray): ByteArray {
7575
for (i in 0 until 16) {
7676
val base = block + i * 8
7777
w[i] = ((padded[base].toLong() and 0xFF) shl 56) or
78-
((padded[base + 1].toLong() and 0xFF) shl 48) or
79-
((padded[base + 2].toLong() and 0xFF) shl 40) or
80-
((padded[base + 3].toLong() and 0xFF) shl 32) or
81-
((padded[base + 4].toLong() and 0xFF) shl 24) or
82-
((padded[base + 5].toLong() and 0xFF) shl 16) or
83-
((padded[base + 6].toLong() and 0xFF) shl 8) or
84-
(padded[base + 7].toLong() and 0xFF)
78+
((padded[base + 1].toLong() and 0xFF) shl 48) or
79+
((padded[base + 2].toLong() and 0xFF) shl 40) or
80+
((padded[base + 3].toLong() and 0xFF) shl 32) or
81+
((padded[base + 4].toLong() and 0xFF) shl 24) or
82+
((padded[base + 5].toLong() and 0xFF) shl 16) or
83+
((padded[base + 6].toLong() and 0xFF) shl 8) or
84+
(padded[base + 7].toLong() and 0xFF)
8585
}
8686
for (i in 16 until 80) {
8787
val s0 = rotateRight64(w[i - 15], 1) xor rotateRight64(w[i - 15], 8) xor (w[i - 15] ushr 7)
8888
val s1 = rotateRight64(w[i - 2], 19) xor rotateRight64(w[i - 2], 61) xor (w[i - 2] ushr 6)
8989
w[i] = w[i - 16] + s0 + w[i - 7] + s1
9090
}
9191

92-
var a = h[0]; var b = h[1]; var c = h[2]; var d = h[3]
93-
var e = h[4]; var f = h[5]; var g = h[6]; var hh = h[7]
92+
var a = h[0];
93+
var b = h[1];
94+
var c = h[2];
95+
var d = h[3]
96+
var e = h[4];
97+
var f = h[5];
98+
var g = h[6];
99+
var hh = h[7]
94100
for (i in 0 until 80) {
95101
val s1 = rotateRight64(e, 14) xor rotateRight64(e, 18) xor rotateRight64(e, 41)
96102
val ch = (e and f) xor (e.inv() and g)

shared/src/commonMain/kotlin/com/ismartcoding/plain/lib/pdfviewer/exception/PageRenderingException.kt renamed to shared-lib/src/commonMain/kotlin/com/ismartcoding/plain/lib/pdfviewer/exception/PageRenderingException.kt

File renamed without changes.

shared/src/commonMain/kotlin/com/ismartcoding/plain/lib/pdfviewer/listener/OnErrorListener.kt renamed to shared-lib/src/commonMain/kotlin/com/ismartcoding/plain/lib/pdfviewer/listener/OnErrorListener.kt

File renamed without changes.

shared/src/commonMain/kotlin/com/ismartcoding/plain/lib/pdfviewer/listener/OnLoadCompleteListener.kt renamed to shared-lib/src/commonMain/kotlin/com/ismartcoding/plain/lib/pdfviewer/listener/OnLoadCompleteListener.kt

File renamed without changes.

shared/src/commonMain/kotlin/com/ismartcoding/plain/lib/pdfviewer/listener/OnPageChangeListener.kt renamed to shared-lib/src/commonMain/kotlin/com/ismartcoding/plain/lib/pdfviewer/listener/OnPageChangeListener.kt

File renamed without changes.

shared/src/commonMain/kotlin/com/ismartcoding/plain/lib/pdfviewer/listener/OnPageErrorListener.kt renamed to shared-lib/src/commonMain/kotlin/com/ismartcoding/plain/lib/pdfviewer/listener/OnPageErrorListener.kt

File renamed without changes.

shared/src/commonMain/kotlin/com/ismartcoding/plain/lib/pdfviewer/listener/OnPageScrollListener.kt renamed to shared-lib/src/commonMain/kotlin/com/ismartcoding/plain/lib/pdfviewer/listener/OnPageScrollListener.kt

File renamed without changes.

0 commit comments

Comments
 (0)