-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(keyset reader): impl JsonKeysetReader
- Loading branch information
Showing
10 changed files
with
81 additions
and
50 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
tink/src/androidMain/kotlin/io/github/ryunen344/tink/JsonKeysetReader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.github.ryunen344.tink | ||
|
||
typealias NativeJsonKeysetReader = com.google.crypto.tink.JsonKeysetReader | ||
|
||
actual class JsonKeysetReader actual constructor(bytes: ByteArray) : | ||
KeysetReader(NativeJsonKeysetReader.withBytes(bytes)) { | ||
actual constructor(json: String) : this(json.encodeToByteArray()) | ||
} |
3 changes: 3 additions & 0 deletions
3
tink/src/androidMain/kotlin/io/github/ryunen344/tink/exception/JsonException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package io.github.ryunen344.tink.exception | ||
|
||
actual typealias JsonException = com.google.gson.JsonParseException |
47 changes: 0 additions & 47 deletions
47
...src/androidUnitTest/kotlin/io/github/ryunen344/tink/daead/AndroidDeterministicAeadTest.kt
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
tink/src/commonMain/kotlin/io/github/ryunen344/tink/JsonKeysetReader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.github.ryunen344.tink | ||
|
||
import io.github.ryunen344.tink.exception.JsonException | ||
|
||
expect class JsonKeysetReader @Throws(JsonException::class) constructor(bytes: ByteArray) : KeysetReader { | ||
@Throws(JsonException::class) | ||
constructor(json: String) | ||
} | ||
|
3 changes: 3 additions & 0 deletions
3
tink/src/commonMain/kotlin/io/github/ryunen344/tink/exception/JsonException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package io.github.ryunen344.tink.exception | ||
|
||
expect class JsonException : RuntimeException |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
tink/src/iosMain/kotlin/io/github/ryunen344/tink/DarwinKeysetReader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
package io.github.ryunen344.tink | ||
|
||
actual typealias KeysetReader = com.google.crypto.tink.TINKKeysetReader | ||
import com.google.crypto.tink.TINKKeysetReader | ||
|
||
actual open class KeysetReader(val native: TINKKeysetReader) |
17 changes: 17 additions & 0 deletions
17
tink/src/iosMain/kotlin/io/github/ryunen344/tink/JsonKeysetReader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.github.ryunen344.tink | ||
|
||
import com.google.crypto.tink.TINKJSONKeysetReader | ||
import io.github.ryunen344.tink.exception.JsonException | ||
import io.github.ryunen344.tink.util.asThrowable | ||
import io.github.ryunen344.tink.util.memScopedInstance | ||
import io.github.ryunen344.tink.util.toNSData | ||
import kotlinx.cinterop.ptr | ||
|
||
actual class JsonKeysetReader actual constructor(bytes: ByteArray) : KeysetReader( | ||
native = memScopedInstance( | ||
block = { TINKJSONKeysetReader(serializedKeyset = bytes.toNSData(), error = it.ptr) }, | ||
onError = { throw JsonException(cause = it.asThrowable()) } | ||
) | ||
) { | ||
actual constructor(json: String) : this(json.encodeToByteArray()) | ||
} |
3 changes: 3 additions & 0 deletions
3
tink/src/iosMain/kotlin/io/github/ryunen344/tink/exception/JsonException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package io.github.ryunen344.tink.exception | ||
|
||
actual class JsonException(message: String? = null, cause: Throwable? = null) : RuntimeException(message, cause) |