Compare commits
4 Commits
fec960065d
...
8065f15e3f
| Author | SHA1 | Date | |
|---|---|---|---|
|
8065f15e3f
|
|||
|
f147058b6c
|
|||
|
c075bbfa1e
|
|||
|
6f4d1c38a3
|
@@ -4,7 +4,7 @@ on:
|
||||
- main
|
||||
|
||||
env:
|
||||
GIT__TOKEN: ${{ secrets.TOKEN }}
|
||||
INFENDRO__TOKEN: ${{ secrets.TOKEN }}
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
|
||||
31
README.md
31
README.md
@@ -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.
|
||||
* [HMAC](https://en.wikipedia.org/wiki/HMAC)
|
||||
* Multiplatform support
|
||||
* JVM
|
||||
* JavaScript
|
||||
* Native (Linux)
|
||||
## Targets
|
||||
|
||||
| Target | Status |
|
||||
|------------------|---------------|
|
||||
| JVM | Supported |
|
||||
| JavaScript | Supported |
|
||||
| Native (Linux) | Supported |
|
||||
| Native (Windows) | Not Supported |
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -21,14 +24,14 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("com.infendro:mac:1.2.2")
|
||||
implementation("com.infendro:mac:1.2.0")
|
||||
}
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```kotlin
|
||||
import com.infendro.hash.SHA1
|
||||
import com.infendro.hash.sha1.SHA1
|
||||
import com.infendro.mac.HMAC
|
||||
|
||||
fun main() {
|
||||
@@ -36,8 +39,10 @@ fun main() {
|
||||
val hmac = HMAC(SHA1)
|
||||
|
||||
// generate MAC
|
||||
val key = "secret".encodeToByteArray()
|
||||
val value = "Hello World!".encodeToByteArray()
|
||||
val key = "secret"
|
||||
.encodeToByteArray().asUByteArray()
|
||||
val value = "Hello World!"
|
||||
.encodeToByteArray().asUByteArray()
|
||||
val mac = hmac.hash(key, value)
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import com.infendro.plugin.infendro
|
||||
import com.infendro.plugin.token
|
||||
|
||||
group = "com.infendro"
|
||||
version = "1.2.0"
|
||||
|
||||
repositories {
|
||||
maven("https://git.infendro.com/api/packages/Infendro/maven")
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.infendro)
|
||||
alias(libs.plugins.multiplatform)
|
||||
id("maven-publish")
|
||||
}
|
||||
@@ -18,6 +17,11 @@ kotlin {
|
||||
}
|
||||
linuxX64()
|
||||
|
||||
repositories {
|
||||
infendro()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
commonMain.dependencies {
|
||||
implementation(libs.hash)
|
||||
@@ -33,31 +37,6 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
publishing {
|
||||
repositories {
|
||||
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
|
||||
publishing.repositories {
|
||||
infendro(token)
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
[versions]
|
||||
kotlin = "2.1.20"
|
||||
infendro = "1.0.0"
|
||||
kotlin = "2.2.21"
|
||||
hash = "1.3.2"
|
||||
bytearray = "1.2.2"
|
||||
bytearray = "1.2.4"
|
||||
|
||||
[plugins]
|
||||
infendro = { id = "com.infendro.plugin", version.ref = "infendro" }
|
||||
multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
|
||||
|
||||
[libraries]
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
rootProject.name = "mac"
|
||||
|
||||
pluginManagement.repositories {
|
||||
maven("https://git.infendro.com/api/packages/Infendro/maven")
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.infendro.hash.HashFunction
|
||||
|
||||
class HMAC(
|
||||
val function: HashFunction,
|
||||
) : MAC() {
|
||||
) : MAC {
|
||||
override val bytes: Int
|
||||
get() = function.bytes
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.infendro.mac
|
||||
|
||||
abstract class MAC {
|
||||
abstract val bytes: Int
|
||||
interface MAC {
|
||||
val bytes: Int
|
||||
val bits: Int
|
||||
get() = bytes * 8
|
||||
|
||||
abstract fun hash(
|
||||
fun hash(
|
||||
key: UByteArray,
|
||||
value: UByteArray,
|
||||
): UByteArray
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.infendro.mac
|
||||
|
||||
import com.infendro.bytearray.encodeToUByteArray
|
||||
import com.infendro.hash.sha2.`SHA-256`
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertContentEquals
|
||||
@@ -28,8 +29,8 @@ class `HMAC Test` {
|
||||
0x2dU, 0x1aU, 0x3cU, 0xd8U,
|
||||
),
|
||||
hmac.hash(
|
||||
"key".encodeToByteArray().asUByteArray(),
|
||||
"The quick brown fox jumps over the lazy dog".encodeToByteArray().asUByteArray()
|
||||
"key".encodeToUByteArray(),
|
||||
"The quick brown fox jumps over the lazy dog".encodeToUByteArray()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user