parent
d2fad0bfff
commit
940e82f279
|
@ -4,7 +4,7 @@ plugins {
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "dev.usbharu"
|
group = "dev.usbharu"
|
||||||
version = "1.0.0"
|
version = "2.0.0-SNAPSHOT"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
package dev.usbharu.httpsignature.v2
|
||||||
|
|
||||||
|
interface Component {
|
||||||
|
val componentName: String
|
||||||
|
val componentIdentifier: String
|
||||||
|
get() = "\"$componentName\":$componentParameter"
|
||||||
|
val componentParameter: String
|
||||||
|
val componentValue: String
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
package dev.usbharu.httpsignature.v2
|
||||||
|
|
||||||
|
enum class SignatureAlgorithm(val value: String) {
|
||||||
|
;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package dev.usbharu.httpsignature.v2
|
||||||
|
|
||||||
|
class SignatureBase() {
|
||||||
|
|
||||||
|
private val list = mutableMapOf<String, Component>()
|
||||||
|
|
||||||
|
fun addComponent(component: Component) {
|
||||||
|
if (list[component.componentIdentifier] != null) {
|
||||||
|
throw IllegalArgumentException("Component with identifier ${component.componentIdentifier} already exists.")
|
||||||
|
}
|
||||||
|
list[component.componentIdentifier] = component
|
||||||
|
}
|
||||||
|
|
||||||
|
fun generateSignatureBase(signatureParameter: SignatureParameter): String {
|
||||||
|
val signatureBase =
|
||||||
|
list.values.joinToString(postfix = "\n") { component -> "${component.componentIdentifier}: ${component.componentValue}\n" }
|
||||||
|
|
||||||
|
val signatureParams = listOfNotNull(
|
||||||
|
list.keys.joinToString(" ", "(", ")"),
|
||||||
|
signatureParameter.algorithm?.let { algorithm -> "alg=\"${algorithm.value}\"" },
|
||||||
|
signatureParameter.keyId?.let { keyId -> "keyid=\"$keyId\"" },
|
||||||
|
signatureParameter.created?.let { created -> "created=$created" },
|
||||||
|
signatureParameter.expires?.let { expires -> "expires=$expires" },
|
||||||
|
signatureParameter.nonce?.let { nonce -> "nonce=\"$nonce\"" },
|
||||||
|
signatureParameter.tag?.let { tag -> "tag=\"$tag\"" },
|
||||||
|
).joinToString(";", prefix = "\"@signature-params\": ")
|
||||||
|
|
||||||
|
return signatureBase + signatureParams
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package dev.usbharu.httpsignature.v2
|
||||||
|
|
||||||
|
import java.time.Instant
|
||||||
|
|
||||||
|
data class SignatureParameter(
|
||||||
|
val algorithm: SignatureAlgorithm?,
|
||||||
|
val keyId: String?,
|
||||||
|
val created: Instant?,
|
||||||
|
val expires: Instant?,
|
||||||
|
val nonce: String?,
|
||||||
|
val tag: String?,
|
||||||
|
)
|
Loading…
Reference in New Issue