Skip to content

Commit 49de51a

Browse files
committed
Update docs.
1 parent cba59f6 commit 49de51a

13 files changed

Lines changed: 1216 additions & 744 deletions

File tree

README.md

Lines changed: 513 additions & 178 deletions
Large diffs are not rendered by default.

paseto/src/main/kotlin/net/aholbrook/paseto/Footer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ data class TaintedClaimFooter internal constructor(
7777
* @receiver A [PasetoFooter] instance to turn taint.
7878
* @return A [TaintedPasetoFooter] representation of the given [PasetoFooter].
7979
*/
80-
fun PasetoFooter.taint(): TaintedPasetoFooter? = when (this) {
80+
fun PasetoFooter.taint(): TaintedPasetoFooter = when (this) {
8181
is ClaimFooter -> TaintedClaimFooter(keyId, wrappedKey, claims)
8282
is StringFooter -> TaintedStringFooter(value)
8383
}

paseto/src/main/kotlin/net/aholbrook/paseto/TokenService.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ sealed interface TokenService {
9292
* @param [token] paseto token to decode the footer of.
9393
* @return [TaintedPasetoFooter] with the decoded footer contents.
9494
*/
95-
fun insecureGetFooter(token: String): TaintedPasetoFooter?
95+
fun insecureGetFooter(token: String): TaintedPasetoFooter
9696
}
9797

9898
internal class LocalTokenService internal constructor(
@@ -113,7 +113,7 @@ internal class LocalTokenService internal constructor(
113113
return paseto.encrypt(
114114
m = encoded.toByteArray(Charsets.UTF_8),
115115
key = keyProvider(),
116-
footer = encodedFooter ?: "",
116+
footer = encodedFooter,
117117
implicitAssertion = implicitAssertion,
118118
)
119119
}
@@ -136,7 +136,7 @@ internal class LocalTokenService internal constructor(
136136
return decoded
137137
}
138138

139-
override fun insecureGetFooter(token: String): TaintedPasetoFooter? =
139+
override fun insecureGetFooter(token: String): TaintedPasetoFooter =
140140
json.decodeFooter(footerOptions, extractFooter(token)).taint()
141141
}
142142

@@ -163,7 +163,7 @@ internal class PublicTokenService internal constructor(
163163
return paseto.sign(
164164
m = encoded.toByteArray(Charsets.UTF_8),
165165
secretKey = keyPair.secretKey,
166-
footer = encodedFooter ?: "",
166+
footer = encodedFooter,
167167
implicitAssertion = implicitAssertion,
168168
)
169169
}
@@ -187,6 +187,6 @@ internal class PublicTokenService internal constructor(
187187
return decoded
188188
}
189189

190-
override fun insecureGetFooter(token: String): TaintedPasetoFooter? =
190+
override fun insecureGetFooter(token: String): TaintedPasetoFooter =
191191
json.decodeFooter(footerOptions, extractFooter(token)).taint()
192192
}

paseto/src/main/kotlin/net/aholbrook/paseto/crypto/ConstantTimeEquals.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import java.nio.charset.Charset
1515
* @param expected The expected byte array.
1616
* @return true if the arrays are equal, false if not.
1717
*/
18-
internal fun ByteArray.constantTimeEquals(expected: ByteArray): Boolean {
18+
fun ByteArray.constantTimeEquals(expected: ByteArray): Boolean {
1919
if (size != expected.size) {
2020
var result = 0
2121
for (i in indices) {
@@ -44,5 +44,5 @@ internal fun ByteArray.constantTimeEquals(expected: ByteArray): Boolean {
4444
* @param expected The expected byte array.
4545
* @return true if the arrays are equal, false if not.
4646
*/
47-
internal fun String.constantTimeEquals(expected: String, charset: Charset = Charsets.UTF_8): Boolean =
47+
fun String.constantTimeEquals(expected: String, charset: Charset = Charsets.UTF_8): Boolean =
4848
toByteArray(charset).constantTimeEquals(expected.toByteArray(charset))

paseto/src/main/kotlin/net/aholbrook/paseto/protocol/key/AsymmetricSecretKey.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class AsymmetricSecretKey private constructor(material: ByteArray, val version:
6262
else -> material
6363
}
6464
}
65+
66+
fun copy(): AsymmetricSecretKey = AsymmetricSecretKey(material.copyOf(), version)
6567

6668
fun toHex(): String {
6769
if (cleared) throw KeyReuseException()

paseto/src/main/kotlin/net/aholbrook/paseto/protocol/key/KeyPair.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import net.aholbrook.paseto.protocol.Version
1111
import java.io.FileInputStream
1212
import java.io.FileNotFoundException
1313
import java.io.IOException
14+
import java.security.Key
1415
import java.security.KeyStore
1516
import java.security.KeyStoreException
1617
import java.security.NoSuchAlgorithmException
@@ -33,6 +34,8 @@ class KeyPair(val secretKey: AsymmetricSecretKey?, val publicKey: AsymmetricPubl
3334

3435
val version: Version = publicKey.version
3536

37+
fun copy(): KeyPair = KeyPair(secretKey?.copy(), publicKey)
38+
3639
override fun equals(other: Any?): Boolean {
3740
if (this === other) {
3841
return true

paseto/src/main/kotlin/net/aholbrook/paseto/protocol/key/SymmetricKey.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class SymmetricKey private constructor(private val material: ByteArray, val vers
2020
}
2121
}
2222

23+
fun copy(): SymmetricKey = SymmetricKey(material.copyOf(), version)
24+
2325
fun toHex(): String {
2426
if (cleared) throw KeyReuseException()
2527
return Hex.toHexString(material)

0 commit comments

Comments
 (0)