Compare commits

...

4 Commits

Author SHA1 Message Date
8065f15e3f update README 2025-12-13 23:01:04 +01:00
f147058b6c fix workflow 2025-12-13 01:31:32 +01:00
c075bbfa1e use common plugin 2025-12-13 01:16:24 +01:00
6f4d1c38a3 convert MAC to interface 2025-12-12 14:15:16 +01:00
8 changed files with 46 additions and 54 deletions

View File

@@ -4,7 +4,7 @@ on:
- main - main
env: env:
GIT__TOKEN: ${{ secrets.TOKEN }} INFENDRO__TOKEN: ${{ secrets.TOKEN }}
jobs: jobs:
publish: publish:

View File

@@ -1,15 +1,18 @@
# Kotlin MAC # mac-kt
This library provides various [Message Authentication Code](https://en.wikipedia.org/wiki/Message_authentication_code) implementations in Kotlin Multiplatform. `mac-kt` is a Kotlin Multiplatform library that provides common MAC implementations.
## Features Supported MACs:
- HMAC
* Generate message authentication codes. ## Targets
* [HMAC](https://en.wikipedia.org/wiki/HMAC)
* Multiplatform support | Target | Status |
* JVM |------------------|---------------|
* JavaScript | JVM | Supported |
* Native (Linux) | JavaScript | Supported |
| Native (Linux) | Supported |
| Native (Windows) | Not Supported |
## Installation ## Installation
@@ -21,14 +24,14 @@ repositories {
} }
dependencies { dependencies {
implementation("com.infendro:mac:1.2.2") implementation("com.infendro:mac:1.2.0")
} }
``` ```
## Usage ## Usage
```kotlin ```kotlin
import com.infendro.hash.SHA1 import com.infendro.hash.sha1.SHA1
import com.infendro.mac.HMAC import com.infendro.mac.HMAC
fun main() { fun main() {
@@ -36,8 +39,10 @@ fun main() {
val hmac = HMAC(SHA1) val hmac = HMAC(SHA1)
// generate MAC // generate MAC
val key = "secret".encodeToByteArray() val key = "secret"
val value = "Hello World!".encodeToByteArray() .encodeToByteArray().asUByteArray()
val value = "Hello World!"
.encodeToByteArray().asUByteArray()
val mac = hmac.hash(key, value) val mac = hmac.hash(key, value)
} }
``` ```

View File

@@ -1,12 +1,11 @@
import com.infendro.plugin.infendro
import com.infendro.plugin.token
group = "com.infendro" group = "com.infendro"
version = "1.2.0" version = "1.2.0"
repositories {
maven("https://git.infendro.com/api/packages/Infendro/maven")
mavenCentral()
}
plugins { plugins {
alias(libs.plugins.infendro)
alias(libs.plugins.multiplatform) alias(libs.plugins.multiplatform)
id("maven-publish") id("maven-publish")
} }
@@ -18,6 +17,11 @@ kotlin {
} }
linuxX64() linuxX64()
repositories {
infendro()
mavenCentral()
}
sourceSets { sourceSets {
commonMain.dependencies { commonMain.dependencies {
implementation(libs.hash) implementation(libs.hash)
@@ -33,31 +37,6 @@ kotlin {
} }
} }
publishing { publishing.repositories {
repositories { infendro(token)
maven {
url = uri("https://git.infendro.com/api/packages/Infendro/maven")
authentication.create("header", HttpHeaderAuthentication::class)
credentials(HttpHeaderCredentials::class) {
val token = secret("git.token") ?: throw GradleException()
name = "Authorization"
value = "token $token"
}
}
}
}
fun secret(
key: String,
): String? {
val property = key
val environment = key
.uppercase()
.replace(".", "__")
val prop = properties[property] as String?
val env = System.getenv(environment)
return prop ?: env
} }

View File

@@ -1,9 +1,11 @@
[versions] [versions]
kotlin = "2.1.20" infendro = "1.0.0"
kotlin = "2.2.21"
hash = "1.3.2" hash = "1.3.2"
bytearray = "1.2.2" bytearray = "1.2.4"
[plugins] [plugins]
infendro = { id = "com.infendro.plugin", version.ref = "infendro" }
multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
[libraries] [libraries]

View File

@@ -1 +1,6 @@
rootProject.name = "mac" rootProject.name = "mac"
pluginManagement.repositories {
maven("https://git.infendro.com/api/packages/Infendro/maven")
mavenCentral()
}

View File

@@ -5,7 +5,7 @@ import com.infendro.hash.HashFunction
class HMAC( class HMAC(
val function: HashFunction, val function: HashFunction,
) : MAC() { ) : MAC {
override val bytes: Int override val bytes: Int
get() = function.bytes get() = function.bytes

View File

@@ -1,11 +1,11 @@
package com.infendro.mac package com.infendro.mac
abstract class MAC { interface MAC {
abstract val bytes: Int val bytes: Int
val bits: Int val bits: Int
get() = bytes * 8 get() = bytes * 8
abstract fun hash( fun hash(
key: UByteArray, key: UByteArray,
value: UByteArray, value: UByteArray,
): UByteArray ): UByteArray

View File

@@ -1,5 +1,6 @@
package com.infendro.mac package com.infendro.mac
import com.infendro.bytearray.encodeToUByteArray
import com.infendro.hash.sha2.`SHA-256` import com.infendro.hash.sha2.`SHA-256`
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertContentEquals import kotlin.test.assertContentEquals
@@ -28,8 +29,8 @@ class `HMAC Test` {
0x2dU, 0x1aU, 0x3cU, 0xd8U, 0x2dU, 0x1aU, 0x3cU, 0xd8U,
), ),
hmac.hash( hmac.hash(
"key".encodeToByteArray().asUByteArray(), "key".encodeToUByteArray(),
"The quick brown fox jumps over the lazy dog".encodeToByteArray().asUByteArray() "The quick brown fox jumps over the lazy dog".encodeToUByteArray()
) )
) )
} }