Skip to content

Commit

Permalink
refactor internals module
Browse files Browse the repository at this point in the history
  • Loading branch information
iaik-jheher committed Dec 6, 2024
1 parent f53f502 commit b69d9d4
Show file tree
Hide file tree
Showing 30 changed files with 38 additions and 44 deletions.
6 changes: 3 additions & 3 deletions docs/docs/indispensable.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ It contains essentials such as:
* `CryptoPrivateKey` representing a private key. Currently, we support RSA and EC private keys on NIST curves. RSA keys always include the public key, EC keys may or may not contain a public key and/or curve.
* Has an additional specialization `CryptoPrivateKey.WithPublicKey` that always includes a public key
* Encodes to PKCS#8 by default
* RSA keys also support `pkcs1Encode()`
* EC keys also support `sec1Encode()`
* `Digest` containing an enumeration of supported
* RSA keys also support PKCS#1 encoding (`.asPKCS1`)
* EC keys also support SEC1 encoding (`.asSEC1`)
* `Digest` containing an enumeration of supported digests
* `ECCurve` representing an EC Curve
* `ECPoint` representing a point on an elliptic curve
* `CryptoSignatre` representing a cryptographic signature including descriptive information regarding the algorithms and signature data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlin.experimental.ExperimentalObjCName
import kotlin.native.ObjCName
import kotlin.reflect.typeOf

/**
* Base ASN.1 data class. Can either be a primitive (holding a value), or a structure (holding other ASN.1 elements)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CastingTest : FreeSpec({

Asn1.OctetStringEncapsulating { +Asn1.Null() }.let { it.asEncapsulatingOctetString() shouldBe it }
//Reinterpreting this way must always work
Asn1.OctetStringEncapsulating { +Asn1.Null() }.let { it.asPrimitiveOctetString() shouldBe it.asPrimitiveOctetString() }
Asn1.OctetStringEncapsulating { +Asn1.Null() }.let { it.asPrimitive() shouldBe it }
Asn1.OctetStringEncapsulating { +Asn1.Null() }.let { it.asStructure() shouldBe it }
}

Expand Down
1 change: 1 addition & 0 deletions indispensable-cosef/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ kotlin {
commonMain {
dependencies {
api(project(":indispensable"))
implementation(project(":internals"))
api(serialization("cbor"))
implementation(libs.multibase)
implementation(libs.bignum) //Intellij bug work-around
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions indispensable-josef/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ kotlin {
commonMain {
dependencies {
api(project(":indispensable"))
implementation(project(":internals"))
implementation(libs.okio)
api(libs.multibase)
implementation(libs.bignum) //Intellij bug work-around
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import at.asitplus.signum.indispensable.CryptoPublicKey
import at.asitplus.signum.indispensable.CryptoPublicKey.EC.Companion.fromUncompressed
import at.asitplus.signum.indispensable.ECCurve
import at.asitplus.signum.indispensable.asn1.Asn1Integer
import at.asitplus.signum.indispensable.misc.ensureSize
import at.asitplus.signum.indispensable.asn1.encoding.toTwosComplementByteArray
import at.asitplus.signum.indispensable.asn1.encoding.toUnsignedByteArray
import at.asitplus.signum.internals.ensureSize
import at.asitplus.signum.indispensable.asn1.toAsn1Integer
import io.kotest.core.spec.style.FreeSpec
import io.kotest.matchers.nulls.shouldNotBeNull
Expand Down
2 changes: 1 addition & 1 deletion indispensable/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ kotlin {
api(project(":indispensable-asn1"))
api(libs.multibase)
api(libs.bignum)
implementation(project(":indispensable-internals"))
implementation(project(":internals"))
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import at.asitplus.signum.indispensable.CryptoPublicKey.EC.Companion.asPublicKey
import at.asitplus.signum.indispensable.asn1.*
import at.asitplus.signum.indispensable.asn1.encoding.*
import at.asitplus.signum.indispensable.misc.ANSIECPrefix
import at.asitplus.signum.indispensable.misc.ensureSize
import at.asitplus.signum.internals.ensureSize
import com.ionspin.kotlin.bignum.integer.BigInteger
import com.ionspin.kotlin.bignum.integer.Sign

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import at.asitplus.catching
import at.asitplus.signum.indispensable.asn1.*
import at.asitplus.signum.indispensable.asn1.encoding.Asn1.BitString
import at.asitplus.signum.indispensable.asn1.encoding.Asn1.Null
import at.asitplus.signum.indispensable.io.ByteArrayBase64Serializer
import at.asitplus.signum.indispensable.misc.ANSIECPrefix
import at.asitplus.signum.indispensable.misc.ANSIECPrefix.Companion.hasPrefix
import at.asitplus.io.BaseN
Expand All @@ -14,7 +13,6 @@ import at.asitplus.io.UVarInt
import at.asitplus.io.multibaseDecode
import at.asitplus.io.multibaseEncode
import at.asitplus.signum.indispensable.asn1.encoding.*
import at.asitplus.signum.indispensable.misc.ensureSize
import com.ionspin.kotlin.bignum.integer.BigInteger
import com.ionspin.kotlin.bignum.integer.Sign
import kotlinx.serialization.SerialName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package at.asitplus.signum.indispensable
import at.asitplus.signum.indispensable.asn1.*
import at.asitplus.signum.indispensable.asn1.encoding.*
import at.asitplus.signum.indispensable.io.Base64Strict
import at.asitplus.signum.indispensable.misc.ensureSize
import at.asitplus.signum.internals.ensureSize
import at.asitplus.signum.indispensable.misc.BitLength
import at.asitplus.signum.indispensable.misc.max
import at.asitplus.signum.indispensable.internals.orLazy
import at.asitplus.signum.internals.orLazy
import at.asitplus.signum.indispensable.pki.X509Certificate
import com.ionspin.kotlin.bignum.integer.BigInteger
import com.ionspin.kotlin.bignum.integer.Sign
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package at.asitplus.signum.indispensable

import at.asitplus.signum.indispensable.misc.ensureSize
import at.asitplus.signum.internals.ensureSize
import at.asitplus.signum.indispensable.io.ByteArrayBase64Serializer
import at.asitplus.signum.indispensable.misc.compressY
import at.asitplus.signum.indispensable.misc.decompressY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package at.asitplus.signum.indispensable.asn1
import at.asitplus.catching
import at.asitplus.catchingUnwrapped
import at.asitplus.signum.indispensable.asn1.encoding.*
import at.asitplus.signum.indispensable.misc.ensureSize
import at.asitplus.signum.internals.ensureSize
import com.ionspin.kotlin.bignum.integer.BigInteger
import com.ionspin.kotlin.bignum.integer.Sign
import com.ionspin.kotlin.bignum.integer.util.fromTwosComplementByteArray
Expand Down
2 changes: 1 addition & 1 deletion indispensable/src/commonTest/kotlin/UtilTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package at.asitplus.signum.indispensable

import at.asitplus.signum.indispensable.misc.ensureSize
import at.asitplus.signum.internals.ensureSize
import at.asitplus.signum.indispensable.misc.BitLength
import at.asitplus.signum.indispensable.misc.max
import at.asitplus.signum.indispensable.misc.min
Expand Down
2 changes: 1 addition & 1 deletion indispensable/src/iosMain/kotlin/CommonCryptoExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import at.asitplus.catching
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.memScoped
import platform.Security.*
import at.asitplus.signum.indispensable.internals.*
import at.asitplus.signum.indispensable.internals.at.asitplus.signum.internals.*

val SignatureAlgorithm.secKeyAlgorithm: SecKeyAlgorithm
get() = when (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import at.asitplus.KmmResult
import at.asitplus.catching
import at.asitplus.signum.indispensable.asn1.toAsn1Integer
import at.asitplus.signum.indispensable.asn1.toJavaBigInteger
import at.asitplus.signum.indispensable.internals.isAndroid
import at.asitplus.signum.internals.isAndroid
import at.asitplus.signum.indispensable.pki.X509Certificate
import com.ionspin.kotlin.bignum.integer.base63.toJavaBigInteger
import kotlinx.coroutines.runBlocking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package at.asitplus.signum.indispensable.pki
import at.asitplus.signum.indispensable.*
import at.asitplus.signum.indispensable.asn1.*
import at.asitplus.signum.indispensable.asn1.encoding.encodeToAsn1Primitive
import at.asitplus.signum.indispensable.misc.ensureSize
import at.asitplus.signum.internals.ensureSize
import at.asitplus.signum.indispensable.asn1.encoding.parse
import io.kotest.assertions.withClue
import io.kotest.core.spec.style.FreeSpec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package at.asitplus.signum.indispensable.pki

import at.asitplus.signum.indispensable.*
import at.asitplus.signum.indispensable.asn1.*
import at.asitplus.signum.indispensable.misc.ensureSize
import at.asitplus.signum.internals.ensureSize
import at.asitplus.signum.indispensable.asn1.encoding.parse
import io.kotest.core.spec.style.FreeSpec
import io.kotest.matchers.nulls.shouldNotBeNull
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ kotlin {
}

exportIosFramework(
"Indispensable-Internals",
"Internals",
transitiveExports = false,
serialization("json"),
datetime(),
Expand All @@ -81,8 +81,8 @@ publishing {
withType<MavenPublication> {
if (this.name != "relocation") artifact(javadocJar)
pom {
name.set("Indispensable Internals")
description.set("Kotlin Multiplatform Crypto Core Library, Internal Shared Helpers")
name.set("Internals")
description.set("Kotlin Multiplatform Crypto Library, Internal Shared Helpers")
url.set("https://github.com/a-sit-plus/signum")
licenses {
license {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package at.asitplus.signum.indispensable.misc
package at.asitplus.signum.internals

/**
* Drops bytes at the start, or adds zero bytes at the start, until the [size] is reached
*/
infix fun <T: Any> T?.orLazy(block: ()->T) = if (this != null) lazyOf(this) else lazy(block)

/** Drops bytes at the start, or adds zero bytes at the start, until the [size] is reached */
fun ByteArray.ensureSize(size: Int): ByteArray = (this.size - size).let { toDrop ->
when {
toDrop > 0 -> this.copyOfRange(toDrop, this.size)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@file:OptIn(ExperimentalForeignApi::class)

package at.asitplus.signum.indispensable.internals
package at.asitplus.signum.indispensable.internals.at.asitplus.signum.internals

import kotlinx.cinterop.*
import platform.CoreFoundation.CFDictionaryCreateMutable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package at.asitplus.signum.indispensable.internals
package at.asitplus.signum.internals

val isAndroid by lazy {
try {
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencyResolutionManagement {
}
}

include(":indispensable-internals")
include(":internals")
include(":indispensable-asn1")
include(":indispensable")
include(":indispensable-josef")
Expand Down
3 changes: 2 additions & 1 deletion supreme/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ kotlin {
iosSimulatorArm64()

sourceSets.commonMain.dependencies {
api(project(":indispensable"))
implementation(project(":internals"))
implementation(coroutines())
implementation(napier())
implementation(libs.securerandom)
api(project(":indispensable"))
}

sourceSets.androidMain.dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

package at.asitplus.signum.supreme

import at.asitplus.signum.indispensable.internals.SwiftException
import at.asitplus.signum.indispensable.internals.takeFromCF
import at.asitplus.signum.indispensable.internals.toNiceString
import at.asitplus.signum.indispensable.internals.at.asitplus.signum.internals.SwiftException
import at.asitplus.signum.indispensable.internals.at.asitplus.signum.internals.takeFromCF
import at.asitplus.signum.indispensable.internals.at.asitplus.signum.internals.toNiceString
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.cinterop.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package at.asitplus.signum.supreme.os
import at.asitplus.KmmResult
import at.asitplus.catching
import at.asitplus.signum.indispensable.*
import at.asitplus.signum.indispensable.internals.*
import at.asitplus.signum.indispensable.internals.at.asitplus.signum.internals.*
import at.asitplus.signum.supreme.swiftasync
import at.asitplus.signum.supreme.CFCryptoOperationFailed
import at.asitplus.signum.supreme.CryptoOperationFailed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import at.asitplus.catching
import at.asitplus.signum.indispensable.*
import at.asitplus.signum.supreme.*
import at.asitplus.signum.supreme.AutofreeVariable
import at.asitplus.signum.indispensable.internals.*
import at.asitplus.signum.indispensable.internals.at.asitplus.signum.internals.*
import kotlinx.cinterop.*
import platform.Foundation.NSData
import platform.Security.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package at.asitplus.signum.supreme.sign
import at.asitplus.KmmResult
import at.asitplus.signum.indispensable.*
import at.asitplus.signum.supreme.*
import at.asitplus.signum.indispensable.internals.*
import at.asitplus.signum.indispensable.internals.at.asitplus.signum.internals.*
import kotlinx.cinterop.ExperimentalForeignApi
import platform.Foundation.NSData
import platform.Security.SecKeyCreateSignature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import at.asitplus.signum.indispensable.CryptoPublicKey
import at.asitplus.signum.indispensable.CryptoSignature
import at.asitplus.signum.indispensable.ECCurve
import at.asitplus.signum.indispensable.SignatureAlgorithm
import at.asitplus.signum.indispensable.misc.ensureSize
import at.asitplus.signum.internals.ensureSize
import at.asitplus.signum.indispensable.iosEncoded
import at.asitplus.signum.indispensable.nativeDigest
import at.asitplus.signum.indispensable.secKeyAlgorithmPreHashed
import at.asitplus.signum.indispensable.internals.*
import at.asitplus.signum.indispensable.internals.at.asitplus.signum.internals.*
import at.asitplus.signum.supreme.dsl.DSL
import at.asitplus.signum.supreme.UnsupportedCryptoException
import kotlinx.cinterop.ExperimentalForeignApi
Expand Down

0 comments on commit b69d9d4

Please sign in to comment.