diff --git a/library/xof/api/xof.api b/library/xof/api/xof.api index 56fd791..d8ece80 100644 --- a/library/xof/api/xof.api +++ b/library/xof/api/xof.api @@ -1,14 +1,26 @@ +public abstract interface class org/kotlincrypto/core/xof/ReKeyableXofAlgorithm : org/kotlincrypto/core/xof/XofAlgorithm { + public abstract fun reset ([B)V +} + public abstract class org/kotlincrypto/core/xof/Xof : org/kotlincrypto/core/Algorithm, org/kotlincrypto/core/Copyable, org/kotlincrypto/core/Resettable, org/kotlincrypto/core/Updatable { + public static final field Companion Lorg/kotlincrypto/core/xof/Xof$Companion; + protected final field delegate Lorg/kotlincrypto/core/xof/XofAlgorithm; + public synthetic fun (Lorg/kotlincrypto/core/xof/XofAlgorithm;Lkotlin/jvm/internal/DefaultConstructorMarker;)V protected abstract fun newReader ()Lorg/kotlincrypto/core/xof/Xof$Reader; public final fun reader ()Lorg/kotlincrypto/core/xof/Xof$Reader; public final fun reader (Z)Lorg/kotlincrypto/core/xof/Xof$Reader; public static synthetic fun reader$default (Lorg/kotlincrypto/core/xof/Xof;ZILjava/lang/Object;)Lorg/kotlincrypto/core/xof/Xof$Reader; + public static final fun reset (Lorg/kotlincrypto/core/xof/Xof;[B)V public final fun toString ()Ljava/lang/String; public final fun use (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public final fun use (ZLkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static synthetic fun use$default (Lorg/kotlincrypto/core/xof/Xof;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/Object; } +public final class org/kotlincrypto/core/xof/Xof$Companion { + public final fun reset (Lorg/kotlincrypto/core/xof/Xof;[B)V +} + public abstract class org/kotlincrypto/core/xof/Xof$Reader { public fun (Lorg/kotlincrypto/core/xof/Xof;)V public final fun bytesRead ()J @@ -43,7 +55,6 @@ protected abstract class org/kotlincrypto/core/xof/XofFactory$XofDelegate : org/ protected fun (Lorg/kotlincrypto/core/xof/XofFactory;Lorg/kotlincrypto/core/xof/XofAlgorithm;)V public fun algorithm ()Ljava/lang/String; public final fun equals (Ljava/lang/Object;)Z - protected final fun getDelegate ()Lorg/kotlincrypto/core/xof/XofAlgorithm; public final fun hashCode ()I protected final fun newReader ()Lorg/kotlincrypto/core/xof/Xof$Reader; protected abstract fun newReader (Lorg/kotlincrypto/core/xof/XofAlgorithm;)Lorg/kotlincrypto/core/xof/Xof$Reader; diff --git a/library/xof/api/xof.klib.api b/library/xof/api/xof.klib.api index 76cca6b..3ae2fbb 100644 --- a/library/xof/api/xof.klib.api +++ b/library/xof/api/xof.klib.api @@ -6,6 +6,10 @@ // - Show declarations: true // Library unique name: +abstract interface org.kotlincrypto.core.xof/ReKeyableXofAlgorithm : org.kotlincrypto.core.xof/XofAlgorithm { // org.kotlincrypto.core.xof/ReKeyableXofAlgorithm|null[0] + abstract fun reset(kotlin/ByteArray) // org.kotlincrypto.core.xof/ReKeyableXofAlgorithm.reset|reset(kotlin.ByteArray){}[0] +} + abstract interface org.kotlincrypto.core.xof/XofAlgorithm : org.kotlincrypto.core/Algorithm // org.kotlincrypto.core.xof/XofAlgorithm|null[0] abstract class <#A: org.kotlincrypto.core.xof/XofAlgorithm> org.kotlincrypto.core.xof/XofFactory { // org.kotlincrypto.core.xof/XofFactory|null[0] @@ -14,9 +18,6 @@ abstract class <#A: org.kotlincrypto.core.xof/XofAlgorithm> org.kotlincrypto.cor abstract inner class XofDelegate : org.kotlincrypto.core.xof/Xof<#A>, org.kotlincrypto.core/Algorithm, org.kotlincrypto.core/Resettable, org.kotlincrypto.core/Updatable { // org.kotlincrypto.core.xof/XofFactory.XofDelegate|null[0] constructor (#A) // org.kotlincrypto.core.xof/XofFactory.XofDelegate.|(2:0){}[0] - final val delegate // org.kotlincrypto.core.xof/XofFactory.XofDelegate.delegate|{}delegate[0] - final fun (): #A // org.kotlincrypto.core.xof/XofFactory.XofDelegate.delegate.|(){}[0] - abstract fun newReader(#A): org.kotlincrypto.core.xof/Xof.Reader<#A> // org.kotlincrypto.core.xof/XofFactory.XofDelegate.newReader|newReader(2:0){}[0] final fun equals(kotlin/Any?): kotlin/Boolean // org.kotlincrypto.core.xof/XofFactory.XofDelegate.equals|equals(kotlin.Any?){}[0] final fun hashCode(): kotlin/Int // org.kotlincrypto.core.xof/XofFactory.XofDelegate.hashCode|hashCode(){}[0] @@ -30,7 +31,10 @@ abstract class <#A: org.kotlincrypto.core.xof/XofAlgorithm> org.kotlincrypto.cor } sealed class <#A: org.kotlincrypto.core.xof/XofAlgorithm> org.kotlincrypto.core.xof/Xof : org.kotlincrypto.core/Algorithm, org.kotlincrypto.core/Copyable>, org.kotlincrypto.core/Resettable, org.kotlincrypto.core/Updatable { // org.kotlincrypto.core.xof/Xof|null[0] - constructor () // org.kotlincrypto.core.xof/Xof.|(){}[0] + constructor (#A) // org.kotlincrypto.core.xof/Xof.|(1:0){}[0] + + final val delegate // org.kotlincrypto.core.xof/Xof.delegate|{}delegate[0] + final fun (): #A // org.kotlincrypto.core.xof/Xof.delegate.|(){}[0] abstract fun newReader(): org.kotlincrypto.core.xof/Xof.Reader<#A> // org.kotlincrypto.core.xof/Xof.newReader|newReader(){}[0] final fun <#A1: kotlin/Any?> use(kotlin/Boolean =..., kotlin/Function1, #A1>): #A1 // org.kotlincrypto.core.xof/Xof.use|use(kotlin.Boolean;kotlin.Function1,0:0>){0§}[0] @@ -55,6 +59,10 @@ sealed class <#A: org.kotlincrypto.core.xof/XofAlgorithm> org.kotlincrypto.core. final fun toString(): kotlin/String // org.kotlincrypto.core.xof/Xof.Reader.toString|toString(){}[0] } + final object Companion { // org.kotlincrypto.core.xof/Xof.Companion|null[0] + final fun <#A2: org.kotlincrypto.core.xof/ReKeyableXofAlgorithm> (org.kotlincrypto.core.xof/Xof<#A2>).reset(kotlin/ByteArray) // org.kotlincrypto.core.xof/Xof.Companion.reset|reset@org.kotlincrypto.core.xof.Xof<0:0>(kotlin.ByteArray){0§}[0] + } + final object Utils { // org.kotlincrypto.core.xof/Xof.Utils|null[0] final fun leftEncode(kotlin/Int): kotlin/ByteArray // org.kotlincrypto.core.xof/Xof.Utils.leftEncode|leftEncode(kotlin.Int){}[0] final fun leftEncode(kotlin/Int, kotlin/Int): kotlin/ByteArray // org.kotlincrypto.core.xof/Xof.Utils.leftEncode|leftEncode(kotlin.Int;kotlin.Int){}[0] diff --git a/library/xof/src/commonMain/kotlin/org/kotlincrypto/core/xof/Xof.kt b/library/xof/src/commonMain/kotlin/org/kotlincrypto/core/xof/Xof.kt index 0c47215..f060fa9 100644 --- a/library/xof/src/commonMain/kotlin/org/kotlincrypto/core/xof/Xof.kt +++ b/library/xof/src/commonMain/kotlin/org/kotlincrypto/core/xof/Xof.kt @@ -18,6 +18,7 @@ package org.kotlincrypto.core.xof import org.kotlincrypto.core.* +import kotlin.jvm.JvmField import kotlin.jvm.JvmName import kotlin.jvm.JvmOverloads import kotlin.jvm.JvmStatic @@ -52,7 +53,22 @@ import kotlin.jvm.JvmStatic * @see [reader] * @see [Reader] * */ -public sealed class Xof: Algorithm, Copyable>, Resettable, Updatable { +public sealed class Xof( + @JvmField + protected val delegate: A, +): Algorithm, Copyable>, Resettable, Updatable { + + public companion object { + + /** + * Helper to provide access to the instance backing [Xof], if said instance + * can be re-keyed (such as a [org.kotlincrypto.core.mac.Mac]). + * + * @throws [IllegalArgumentException] if [newKey] is unacceptable. + * */ + @JvmStatic + public fun Xof.reset(newKey: ByteArray) { delegate.reset(newKey) } + } /** * Takes a snapshot of the current [Xof]'s state and produces @@ -298,5 +314,4 @@ public sealed class Xof: Algorithm, Copyable>, Resettabl /** @suppress */ public final override fun toString(): String = "Xof[${algorithm()}]@${hashCode()}" - } diff --git a/library/xof/src/commonMain/kotlin/org/kotlincrypto/core/xof/XofAlgorithm.kt b/library/xof/src/commonMain/kotlin/org/kotlincrypto/core/xof/XofAlgorithm.kt index b44845d..ed3da83 100644 --- a/library/xof/src/commonMain/kotlin/org/kotlincrypto/core/xof/XofAlgorithm.kt +++ b/library/xof/src/commonMain/kotlin/org/kotlincrypto/core/xof/XofAlgorithm.kt @@ -22,3 +22,22 @@ import org.kotlincrypto.core.Algorithm * which supports Extendable-Output Functions (XOFs). * */ public interface XofAlgorithm: Algorithm + +/** + * Extended functionality, specifically for a [Xof] who's backing instance + * is a [org.kotlincrypto.core.mac.Mac]. + * + * + * @see [Xof.Companion.reset] + * */ +public interface ReKeyableXofAlgorithm: XofAlgorithm { + + /** + * Resets and re-initializes the instance with the provided [newKey] + * + * This is useful if wanting to clear the key before de-referencing. + * + * @throws [IllegalArgumentException] if [newKey] is unacceptable. + * */ + public fun reset(newKey: ByteArray) +} diff --git a/library/xof/src/commonMain/kotlin/org/kotlincrypto/core/xof/XofFactory.kt b/library/xof/src/commonMain/kotlin/org/kotlincrypto/core/xof/XofFactory.kt index 96f968e..da89372 100644 --- a/library/xof/src/commonMain/kotlin/org/kotlincrypto/core/xof/XofFactory.kt +++ b/library/xof/src/commonMain/kotlin/org/kotlincrypto/core/xof/XofFactory.kt @@ -54,9 +54,7 @@ public abstract class XofFactory public constructor() { * */ protected abstract inner class XofDelegate @Throws(ClassCastException::class, IllegalArgumentException::class) - protected constructor( - protected val delegate: A, - ) : Xof(), + protected constructor(delegate: A) : Xof(delegate), Algorithm by delegate, Resettable by delegate as Resettable, Updatable by delegate as Updatable