This repository has been archived by the owner on May 16, 2024. It is now read-only.
-
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.
Merge pull request #4 from Cerebellum-Network/feature/nacl
Migrate to NaCl
- Loading branch information
Showing
35 changed files
with
1,290 additions
and
340 deletions.
There are no files selected for viewing
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
21 changes: 0 additions & 21 deletions
21
src/main/kotlin/network/cere/ddc/crypto/v1/common/BaseCryptoService.kt
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
src/main/kotlin/network/cere/ddc/crypto/v1/decrypt/Decrypter.kt
This file was deleted.
Oops, something went wrong.
57 changes: 0 additions & 57 deletions
57
src/main/kotlin/network/cere/ddc/crypto/v1/encrypt/Encrypter.kt
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
src/main/kotlin/network/cere/ddc/crypto/v1/encrypt/EncryptionConfig.kt
This file was deleted.
Oops, something went wrong.
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,15 @@ | ||
package network.cere.ddc.crypto.v1 | ||
|
||
import org.apache.commons.codec.binary.Hex | ||
import java.security.Key | ||
|
||
private const val HEX_PREFIX = "0x" | ||
|
||
fun ByteArray.toHex(withPrefix: Boolean = true): String { | ||
val hex = Hex.encodeHexString(this, true) | ||
return if (withPrefix) """$HEX_PREFIX$hex""" else hex | ||
} | ||
|
||
fun String.hexToBytes(): ByteArray = Hex.decodeHex(this.removePrefix(HEX_PREFIX)) | ||
|
||
fun Key.toHex() = this.encoded.toHex() |
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,44 @@ | ||
package network.cere.ddc.crypto.v1 | ||
|
||
import com.fasterxml.jackson.databind.JsonNode | ||
import com.jayway.jsonpath.JsonPath | ||
import network.cere.ddc.crypto.v1.key.secret.CryptoSecretKey.Companion.ALL_PATHS | ||
import org.jsfr.json.JacksonParser | ||
import org.jsfr.json.JsonPathListener | ||
import org.jsfr.json.JsonSurfer | ||
import org.jsfr.json.ParsingContext | ||
import org.jsfr.json.provider.JacksonProvider | ||
|
||
internal inline fun <reified T> traverse( | ||
json: String, | ||
crossinline onMatch: (String, String) -> String, | ||
onSuccess: (String) -> T, | ||
onFailure: () -> T, | ||
jsonPathsToProcess: Iterable<String> = setOf(ALL_PATHS) | ||
): T { | ||
val surfer = JsonSurfer(JacksonParser.INSTANCE, JacksonProvider.INSTANCE) | ||
val toReplace = mutableMapOf<String, String>() | ||
val builder = surfer.configBuilder() | ||
|
||
jsonPathsToProcess.forEach { | ||
builder.bind(it, object : JsonPathListener { | ||
override fun onValue(value: Any, context: ParsingContext) { | ||
val node = value as JsonNode | ||
if (node.isValueNode) { | ||
val path = context.jsonPath | ||
toReplace[path] = onMatch(path, node.asText()) | ||
} | ||
} | ||
}) | ||
} | ||
return runCatching { | ||
builder.buildAndSurf(json) | ||
}.fold( | ||
{ | ||
val ctx = JsonPath.parse(json) | ||
toReplace.forEach { (p, v) -> ctx.set(p, v) } | ||
onSuccess(ctx.jsonString()) | ||
}, | ||
{ onFailure() } | ||
) | ||
} |
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,6 @@ | ||
package network.cere.ddc.crypto.v1.key | ||
|
||
import java.security.PrivateKey | ||
import java.security.PublicKey | ||
|
||
abstract class KeyPair<PK : PublicKey, SK : PrivateKey>(val publicKey: PK, val privateKey: SK) |
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/network/cere/ddc/crypto/v1/key/crypto/CryptoKeyPair.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 network.cere.ddc.crypto.v1.key.crypto | ||
|
||
import network.cere.ddc.crypto.v1.key.KeyPair | ||
|
||
class CryptoKeyPair(publicKey: CryptoPublicKey, privateKey: CryptoPrivateKey) : | ||
KeyPair<CryptoPublicKey, CryptoPrivateKey>(publicKey, privateKey) { | ||
|
||
constructor(publicKeyBytes: ByteArray, privateKeyBytes: ByteArray) : this( | ||
CryptoPublicKey(publicKeyBytes), | ||
CryptoPrivateKey(privateKeyBytes) | ||
) | ||
|
||
constructor(publicKeyHex: String, privateKeyHex: String) : this( | ||
CryptoPublicKey(publicKeyHex), | ||
CryptoPrivateKey(privateKeyHex) | ||
) | ||
} |
Oops, something went wrong.