clean and add some docs

main
dece 2 years ago
parent cd1732c599
commit 59e664ec5c

@ -13,15 +13,18 @@ class UriUtilsTest {
fun joinUrls() {
assertEquals(
"gemini://dece.space/some-file.gmi",
dev.lowrespalmtree.comet.utils.joinUrls("gemini://dece.space/", "some-file.gmi").toString()
dev.lowrespalmtree.comet.utils.joinUrls("gemini://dece.space/", "some-file.gmi")
.toString()
)
assertEquals(
"gemini://dece.space/some-file.gmi",
dev.lowrespalmtree.comet.utils.joinUrls("gemini://dece.space/", "./some-file.gmi").toString()
dev.lowrespalmtree.comet.utils.joinUrls("gemini://dece.space/", "./some-file.gmi")
.toString()
)
assertEquals(
"gemini://dece.space/some-file.gmi",
dev.lowrespalmtree.comet.utils.joinUrls("gemini://dece.space/dir1", "/some-file.gmi").toString()
dev.lowrespalmtree.comet.utils.joinUrls("gemini://dece.space/dir1", "/some-file.gmi")
.toString()
)
assertEquals(
"gemini://dece.space/dir1/other-file.gmi",

@ -195,8 +195,8 @@ class PageViewModel(@Suppress("unused") private val savedStateHandle: SavedState
// We record the history entry here: it's nice because we have the main title available
// and we're already in a coroutine for database access.
History.record(uri.toString(), mainTitle)
event.postValue(SuccessEvent(uri.toString()))
History.record(uriString, mainTitle)
event.postValue(SuccessEvent(uriString))
state.postValue(State.IDLE)
}

@ -19,6 +19,12 @@ import javax.net.ssl.*
class Request(private val uri: Uri, private val keyManager: KeyManager? = null) {
private val port get() = if (uri.port > 0) uri.port else 1965
/**
* Open and return the TLS socket with the server.
*
* If the server certificate present is fine according to our TOFU settings, the app can
* continue by calling `proceed` which will retrieve the data.
*/
fun connect(protocol: String, connectionTimeout: Int, readTimeout: Int): SSLSocket {
Log.d(
TAG,
@ -34,6 +40,7 @@ class Request(private val uri: Uri, private val keyManager: KeyManager? = null)
return socket
}
/** Return a byte array channel carrying the data chunks sent by the server. */
fun proceed(socket: SSLSocket, scope: CoroutineScope): Channel<ByteArray> {
Log.d(TAG, "proceed")
socket.outputStream.write("$uri\r\n".toByteArray())
@ -63,6 +70,13 @@ class Request(private val uri: Uri, private val keyManager: KeyManager? = null)
return channel
}
/**
* Dummy KeyManager to be used when an client cert is to be used during the connection.
*
* This simply retrieves both the public cert and private key from the Android key store
* and implement dummy methods to return only this key pair. Some methods are left unimplemented
* because they should never be executed in the context we use the key manager in.
*/
class KeyManager(
private val alias: String,
private val cert: X509Certificate,

Loading…
Cancel
Save