Skip to content

Commit

Permalink
fix: Explicitly declare public API (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarea authored Aug 18, 2020
1 parent 0239ac9 commit 72fd858
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 17 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ java {
withSourcesJar()
}

kotlin {
explicitApi = 'strict'
}

tasks.withType(KotlinCompile).all {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/tech/relaycorp/poweb/PoWebClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import tech.relaycorp.poweb.handshake.NonceSigner
import tech.relaycorp.poweb.handshake.Response
import java.io.Closeable

class PoWebClient internal constructor(
public class PoWebClient internal constructor(
internal val hostName: String,
internal val port: Int,
internal val useTls: Boolean
Expand All @@ -27,7 +27,7 @@ class PoWebClient internal constructor(
}

@KtorExperimentalAPI
override fun close() = ktorClient.close()
override fun close(): Unit = ktorClient.close()

private val wsUrl = "ws${if (useTls) "s" else ""}://$hostName:$port"

Expand All @@ -37,14 +37,14 @@ class PoWebClient internal constructor(
block: suspend DefaultClientWebSocketSession.() -> Unit
) = ktorClient.webSocket("${wsUrl}$path", block = block)

companion object {
public companion object {
private const val defaultLocalPort = 276
private const val defaultRemotePort = 443

fun initLocal(port: Int = defaultLocalPort) =
public fun initLocal(port: Int = defaultLocalPort): PoWebClient =
PoWebClient("127.0.0.1", port, false)

fun initRemote(hostName: String, port: Int = defaultRemotePort) =
public fun initRemote(hostName: String, port: Int = defaultRemotePort): PoWebClient =
PoWebClient(hostName, port, true)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/tech/relaycorp/poweb/PoWebException.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package tech.relaycorp.poweb

class PoWebException(message: String, cause: Throwable? = null) : Exception(message, cause)
public class PoWebException(message: String, cause: Throwable? = null) : Exception(message, cause)
8 changes: 4 additions & 4 deletions src/main/kotlin/tech/relaycorp/poweb/handshake/Challenge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import com.google.protobuf.ByteString
import com.google.protobuf.InvalidProtocolBufferException
import tech.relaycorp.poweb.internal.protobuf_messages.handshake.Challenge as PBChallenge

class Challenge(val nonce: ByteArray) {
fun serialize(): ByteArray {
public class Challenge(public val nonce: ByteArray) {
public fun serialize(): ByteArray {
val pbChallenge = PBChallenge.newBuilder()
.setGatewayNonce(ByteString.copyFrom(nonce)).build()
return pbChallenge.toByteArray()
}

companion object {
fun deserialize(serialization: ByteArray): Challenge {
public companion object {
public fun deserialize(serialization: ByteArray): Challenge {
val pbChallenge = try {
PBChallenge.parseFrom(serialization)
} catch (_: InvalidProtocolBufferException) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package tech.relaycorp.poweb.handshake

class InvalidMessageException(message: String) : Exception(message)
public class InvalidMessageException(message: String) : Exception(message)
7 changes: 5 additions & 2 deletions src/main/kotlin/tech/relaycorp/poweb/handshake/NonceSigner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import tech.relaycorp.relaynet.messages.control.NonceSignature
import tech.relaycorp.relaynet.wrappers.x509.Certificate
import java.security.PrivateKey

class NonceSigner(internal val certificate: Certificate, private val privateKey: PrivateKey) {
fun sign(nonce: ByteArray): ByteArray {
public class NonceSigner(
internal val certificate: Certificate,
private val privateKey: PrivateKey
) {
public fun sign(nonce: ByteArray): ByteArray {
val signature = NonceSignature(nonce, certificate)
return signature.serialize(privateKey)
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/tech/relaycorp/poweb/handshake/Response.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import com.google.protobuf.ByteString
import com.google.protobuf.InvalidProtocolBufferException
import tech.relaycorp.poweb.internal.protobuf_messages.handshake.Response as PBResponse

class Response(val nonceSignatures: Array<ByteArray>) {
fun serialize(): ByteArray {
public class Response(public val nonceSignatures: Array<ByteArray>) {
public fun serialize(): ByteArray {
val pbResponse = PBResponse.newBuilder()
.addAllGatewayNonceSignatures(nonceSignatures.map { ByteString.copyFrom(it) })
.build()
return pbResponse.toByteArray()
}

companion object {
fun deserialize(serialization: ByteArray): Response {
public companion object {
public fun deserialize(serialization: ByteArray): Response {
val pbResponse = try {
PBResponse.parseFrom(serialization)
} catch (_: InvalidProtocolBufferException) {
Expand Down

0 comments on commit 72fd858

Please sign in to comment.