Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ captures/
# IntelliJ
*.iml
.idea/
.kotlin/

# Android Studio 3 in .gitignore file.
.idea/caches
Expand Down
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
![badge-support-js-ir]
![badge-support-linux-arm]

<!--
![badge-platform-wasm]
-->

Configurable, streamable, efficient and extensible Encoding/Decoding for Kotlin Multiplatform.

**Base16 (a.k.a. "hex")**
Expand All @@ -39,8 +35,6 @@ Configurable, streamable, efficient and extensible Encoding/Decoding for Kotlin
- Default [RFC 4648 section 4](https://www.ietf.org/rfc/rfc4648.html#section-4)
- UrlSafe [RFC 4648 section 5](https://www.ietf.org/rfc/rfc4648.html#section-5)

A full list of `kotlin-components` projects can be found [HERE](https://kotlin-components.matthewnelson.io)

### Usage

**Configure `EncoderDecoder`(s) to your needs**
Expand All @@ -56,7 +50,7 @@ val base16 = Base16 {
// Use lowercase instead of uppercase characters when encoding
encodeToLowercase = true

// Use constant-time operations for sensitive data
// Use constant-time operations when encoding/decoding sensitive data
isConstantTime = true
}

Expand Down
5 changes: 5 additions & 0 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@

See [KotlinCrypto/documentation/RELEASING.md][url-kotlincrypto-releasing]

Additionally, publish dokka documentation updates
```bash
./gh-pages/publish.sh
```

[url-kotlincrypto-releasing]: https://github.com/KotlinCrypto/documentation/blob/master/RELEASING.md
1 change: 1 addition & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ plugins {
}

dependencies {
implementation(libs.gradle.dokka)
implementation(libs.gradle.kmp.configuration)
implementation(libs.gradle.kotlin)
implementation(libs.gradle.publish.maven)
Expand Down
2 changes: 1 addition & 1 deletion build-logic/src/main/kotlin/-KmpConfigurationExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fun KmpConfigurationExtension.configureShared(
mingwAll()

common {
if (publish) pluginIds("publication")
if (publish) pluginIds("publication", "dokka")

sourceSetTest {
dependencies {
Expand Down
42 changes: 42 additions & 0 deletions build-logic/src/main/kotlin/dokka.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2024 Matthew Nelson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
import org.jetbrains.dokka.DokkaConfiguration.Visibility
import org.jetbrains.dokka.gradle.DokkaTaskPartial
import java.net.URI

plugins {
id("org.jetbrains.dokka")
}

tasks.withType<DokkaTaskPartial>().configureEach {
suppressInheritedMembers = true

dokkaSourceSets.configureEach {
includes.from("README.md")
noStdlibLink = true

sourceLink {
localDirectory = rootDir
remoteUrl = URI("https://github.com/05nelsonm/encoding/tree/master").toURL()
remoteLineSuffix = "#L"
}

documentedVisibilities.set(setOf(
Visibility.PUBLIC,
Visibility.PROTECTED,
))
}
}
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension

plugins {
alias(libs.plugins.dokka)
alias(libs.plugins.binary.compat)
alias(libs.plugins.multiplatform) apply(false)
}
Expand Down
34 changes: 34 additions & 0 deletions gh-pages/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
# Copyright (c) 2023 Matthew Nelson
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e

readonly DIR_SCRIPT="$( cd "$( dirname "$0" )" >/dev/null && pwd )"

trap 'rm -rf "$DIR_SCRIPT/encoding"' EXIT

cd "$DIR_SCRIPT"
git clone -b gh-pages --single-branch https://github.com/05nelsonm/encoding.git
rm -rf "$DIR_SCRIPT/encoding/"*
echo "encoding.matthewnelson.io" > "$DIR_SCRIPT/encoding/CNAME"

cd ..
./gradlew clean -DKMP_TARGETS_ALL
./gradlew dokkaHtmlMultiModule -DKMP_TARGETS_ALL
cp -aR build/dokka/htmlMultiModule/* gh-pages/encoding

cd "$DIR_SCRIPT/encoding"
git add --all
git commit -S --message "Update dokka docs"
git push
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
[versions]
gradle-binary-compat = "0.16.3"
gradle-dokka = "1.9.20"
gradle-kmp-configuration = "0.3.2"
gradle-kotlin = "1.9.24"
gradle-publish-maven = "0.29.0"

immutable = "0.1.4"

[libraries]
gradle-dokka = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "gradle-dokka" }
gradle-kmp-configuration = { module = "io.matthewnelson:gradle-kmp-configuration-plugin", version.ref = "gradle-kmp-configuration" }
gradle-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "gradle-kotlin" }
gradle-publish-maven = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "gradle-publish-maven" }
Expand All @@ -15,4 +17,5 @@ immutable-collections = { module = "io.matthewnelson.immutable:collections", ver

[plugins]
binary-compat = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "gradle-binary-compat" }
dokka = { id = "org.jetbrains.dokka", version.ref = "gradle-dokka" }
multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "gradle-kotlin" }
5 changes: 5 additions & 0 deletions library/base16/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Module base16

Base16 (a.k.a. "hex") encoding/decoding in accordance with [RFC 4648 section 8][url-rfc]

[url-rfc]: https://www.ietf.org/rfc/rfc4648.html#section-8
7 changes: 7 additions & 0 deletions library/base32/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Module base32

Base32 encoding/decoding in accordance with [Crockford][url-crockford], [RFC 4648 section 6][url-rfc-6], [RFC 4648 section 6][url-rfc-7]

[url-crockford]: https://www.crockford.com/base32.html
[url-rfc-6]: https://www.ietf.org/rfc/rfc4648.html#section-6
[url-rfc-7]: https://www.ietf.org/rfc/rfc4648.html#section-7
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import io.matthewnelson.encoding.core.Encoder.Companion.encodeToCharArray
import io.matthewnelson.encoding.core.Encoder.Companion.encodeToString
import kotlin.jvm.JvmOverloads

/** @suppress */
@Deprecated(
message = "Replaced by EncoderDecoder. Will be removed in future versions.",
replaceWith = ReplaceWith(
Expand Down
6 changes: 6 additions & 0 deletions library/base64/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Module base64

Base64 encoding/decoding in accordance with [RFC 4648 section 4][url-rfc-4], [RFC 4648 section 5][url-rfc-5]

[url-rfc-4]: https://www.ietf.org/rfc/rfc4648.html#section-4
[url-rfc-5]: https://www.ietf.org/rfc/rfc4648.html#section-5
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import io.matthewnelson.encoding.core.Encoder.Companion.encodeToCharArray
import io.matthewnelson.encoding.core.Encoder.Companion.encodeToString
import kotlin.jvm.JvmOverloads

/** @suppress */
@Deprecated(
message = "Replaced by EncoderDecoder. Will be removed in future versions.",
replaceWith = ReplaceWith(
Expand Down
4 changes: 4 additions & 0 deletions library/core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Module core

Core primitives for encoding/decoding operations, serving as the foundation to other
higher level implementations.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public sealed class Decoder<C: EncoderDecoder.Config>(public val config: C) {

public final override fun close() { isClosed = true }
public final override fun isClosed(): Boolean = isClosed
/** @suppress */
public final override fun toString(): String = "${this@Decoder}.Decoder.Feed@${hashCode()}"

@Throws(EncodingException::class)
Expand Down Expand Up @@ -221,6 +222,7 @@ public sealed class Decoder<C: EncoderDecoder.Config>(public val config: C) {
*
* @see [decodeToByteArrayOrNull]
* @throws [EncodingException] if decoding failed.
* @suppress
* */
@JvmStatic
@Throws(EncodingException::class)
Expand All @@ -231,6 +233,7 @@ public sealed class Decoder<C: EncoderDecoder.Config>(public val config: C) {
}
}

/** @suppress */
@JvmStatic
@Deprecated(message = "Should not utilize. Underlying Byte to Char conversion can produce incorrect results")
public fun ByteArray.decodeToByteArrayOrNull(decoder: Decoder<*>): ByteArray? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public sealed class Encoder<C: EncoderDecoder.Config>(config: C): Decoder<C>(con

public final override fun close() { isClosed = true }
public final override fun isClosed(): Boolean = isClosed
/** @suppress */
public final override fun toString(): String = "${this@Encoder}.Encoder.Feed@${hashCode()}"

protected abstract fun consumeProtected(input: Byte)
Expand Down Expand Up @@ -199,6 +200,7 @@ public sealed class Encoder<C: EncoderDecoder.Config>(config: C): Decoder<C>(con
* data, but is something that can occur with Base16 (hex)
* as it produces 2 characters of output for every 1 byte
* of input.
* @suppress
* */
@JvmStatic
@Throws(EncodingSizeException::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,28 +302,34 @@ public abstract class EncoderDecoder<C: EncoderDecoder.Config>(config: C): Encod
@JvmField
public val name: String = name.trim()

/** @suppress */
override fun equals(other: Any?): Boolean {
return other is Setting
&& other.name == name
}

/** @suppress */
override fun hashCode(): Int {
return 17 * 31 + name.hashCode()
}

/** @suppress */
override fun toString(): String = "$name: $value"
}

/** @suppress */
final override fun equals(other: Any?): Boolean {
return other is Config
&& other::class == this::class
&& other.toString() == toString()
}

/** @suppress */
final override fun hashCode(): Int {
return 17 * 31 + toString().hashCode()
}

/** @suppress */
final override fun toString(): String {
return StringBuilder().apply {
append("EncoderDecoder.Config [")
Expand Down Expand Up @@ -488,20 +494,23 @@ public abstract class EncoderDecoder<C: EncoderDecoder.Config>(config: C): Encod
* */
protected abstract fun name(): String

/** @suppress */
final override fun equals(other: Any?): Boolean {
return other is EncoderDecoder<*>
&& other::class == this::class
&& other.name() == name()
&& other.config.hashCode() == config.hashCode()
}

/** @suppress */
final override fun hashCode(): Int {
var result = 17
result = result * 31 + name().hashCode()
result = result * 31 + config.hashCode()
return result
}

/** @suppress */
final override fun toString(): String {
return "EncoderDecoder[${name()}]@${hashCode()}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ package io.matthewnelson.encoding.core.internal
* the following compiler argument:
*
* -Xopt-in=io.matthewnelson.encoding.core.internal.InternalEncodingApi
*
* @suppress
* */
@RequiresOptIn
@MustBeDocumented
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import kotlin.jvm.JvmField
public fun interface DecoderAction {

/**
* Convert decoder input character to its bitwise integer
* Convert decoder input character to its bitwise integer value.
* */
public fun convert(input: Char): Int

Expand All @@ -49,7 +49,7 @@ public fun interface DecoderAction {
*
* val bits = "48656C6C6F20576F726C6421".map { char ->
* parser.parse(char, isConstantTime = true)
* ?: error("Invalid Char[$char])
* ?: error("Invalid Char[$char]")
* }
*
* @param [action] Pairs of character ranges and their associated [DecoderAction]
Expand Down