WIP: Broken code
This commit is contained in:
parent
b49435da99
commit
f2f96e183f
8 changed files with 37 additions and 47 deletions
|
|
@ -1,8 +1,7 @@
|
|||
package pgp.hkp
|
||||
|
||||
import pgp.hkp.operation.Get
|
||||
import java.net.http.HttpClient
|
||||
|
||||
import pgp.hkp.operation.Get
|
||||
|
||||
open class HKPApi(
|
||||
val http: HttpClient,
|
||||
|
|
@ -25,4 +24,4 @@ open class HKPApi(
|
|||
}
|
||||
|
||||
fun get() = Get(http, service, openpgp)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,5 +4,4 @@ import java.net.URI
|
|||
|
||||
data class HKPServerInfo(
|
||||
val serviceUri: URI,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,10 @@ package pgp.hkp
|
|||
|
||||
import java.net.http.HttpClient
|
||||
|
||||
class HockeypuckApi(
|
||||
http: HttpClient,
|
||||
service: HKPServerInfo,
|
||||
openpgp: OpenPgpImplementation
|
||||
) : HKPApi(http, service, openpgp) {
|
||||
class HockeypuckApi(http: HttpClient, service: HKPServerInfo, openpgp: OpenPgpImplementation) :
|
||||
HKPApi(http, service, openpgp) {
|
||||
companion object {
|
||||
const val REQUEST_PATH_DELETE = "$REQUEST_PATH_PREFIX/delete"
|
||||
const val REQUEST_PATH_REPLACE = "$REQUEST_PATH_PREFIX/replace"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,4 +5,4 @@ abstract class OpenPgpImplementation {
|
|||
abstract fun hexKeyId(keyId: Long): CharSequence
|
||||
|
||||
abstract fun hexFingerprint(fingerprint: ByteArray): CharSequence
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,12 +2,9 @@ package pgp.hkp
|
|||
|
||||
import java.net.http.HttpClient
|
||||
|
||||
class SKSApi(
|
||||
http: HttpClient,
|
||||
service: HKPServerInfo,
|
||||
openpgp: OpenPgpImplementation
|
||||
) : HKPApi(http, service, openpgp) {
|
||||
class SKSApi(http: HttpClient, service: HKPServerInfo, openpgp: OpenPgpImplementation) :
|
||||
HKPApi(http, service, openpgp) {
|
||||
companion object {
|
||||
const val REQUEST_PATH_HASHQUERY = "$REQUEST_PATH_PREFIX/hashquery"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
package pgp.hkp.operation
|
||||
|
||||
import java.net.http.HttpClient
|
||||
import pgp.hkp.HKPApi.Companion.OP_GET
|
||||
import pgp.hkp.HKPServerInfo
|
||||
import pgp.hkp.OpenPgpImplementation
|
||||
import java.net.http.HttpClient
|
||||
|
||||
class Get(val http: HttpClient,
|
||||
val service: HKPServerInfo,
|
||||
val openpgp: OpenPgpImplementation) {
|
||||
class Get(val http: HttpClient, val service: HKPServerInfo, val openpgp: OpenPgpImplementation) {
|
||||
|
||||
fun byKeyId(keyId: Long): LookupRequest {
|
||||
return LookupRequest(http, service, OP_GET, "0x${openpgp.hexKeyId(keyId)}")
|
||||
|
|
@ -27,4 +25,4 @@ class Get(val http: HttpClient,
|
|||
fun byUserId(userId: CharSequence): LookupRequest {
|
||||
return LookupRequest(http, service, OP_GET, userId.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
package pgp.hkp.operation
|
||||
|
||||
import pgp.hkp.HKPApi.Companion.REQUEST_PATH_LOOKUP
|
||||
import pgp.hkp.HKPApi.Companion.VAR_OP
|
||||
import pgp.hkp.HKPApi.Companion.VAR_SEARCH
|
||||
import pgp.hkp.HKPServerInfo
|
||||
import java.net.URI
|
||||
import java.net.http.HttpClient
|
||||
import java.net.http.HttpRequest
|
||||
import java.net.http.HttpResponse
|
||||
import java.net.http.HttpResponse.BodySubscribers
|
||||
import pgp.hkp.HKPApi.Companion.REQUEST_PATH_LOOKUP
|
||||
import pgp.hkp.HKPApi.Companion.VAR_OP
|
||||
import pgp.hkp.HKPServerInfo
|
||||
|
||||
class LookupRequest(
|
||||
val http: HttpClient,
|
||||
|
|
@ -21,14 +20,14 @@ class LookupRequest(
|
|||
get() = "$REQUEST_PATH_LOOKUP?search=$search&op=$op"
|
||||
|
||||
fun execute() {
|
||||
val request = HttpRequest.newBuilder(URIBuilder()URI.create("${service.serviceUri}$REQUEST_PATH_LOOKUP"))
|
||||
.GET()
|
||||
.(VAR_SEARCH, search.toString())
|
||||
.header(VAR_OP, op.toString())
|
||||
.build()
|
||||
val request =
|
||||
HttpRequest.newBuilder(URI.create("${service.serviceUri}$REQUEST_PATH_LOOKUP"))
|
||||
.GET()
|
||||
.header(VAR_OP, op.toString())
|
||||
.build()
|
||||
|
||||
println(request.toString())
|
||||
|
||||
http.send(request, HttpResponse.BodyHandler {it -> BodySubscribers.ofByteArray()})
|
||||
http.send(request, HttpResponse.BodyHandler { it -> BodySubscribers.ofByteArray() })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,28 @@
|
|||
package pgp.hkp
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.net.URI
|
||||
import java.net.http.HttpClient
|
||||
import java.util.HexFormat
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class HKPApiTest {
|
||||
|
||||
@Test
|
||||
fun test() {
|
||||
val api = HKPApi(HttpClient.newHttpClient(),
|
||||
HKPServerInfo(URI.create("http://keys.example.com:11371")),
|
||||
object : OpenPgpImplementation() {
|
||||
override fun hexKeyId(keyId: Long): CharSequence {
|
||||
return keyId.toString(16)
|
||||
}
|
||||
val api =
|
||||
HKPApi(
|
||||
HttpClient.newHttpClient(),
|
||||
HKPServerInfo(URI.create("http://keys.example.com:11371")),
|
||||
object : OpenPgpImplementation() {
|
||||
override fun hexKeyId(keyId: Long): CharSequence {
|
||||
return keyId.toString(16)
|
||||
}
|
||||
|
||||
override fun hexFingerprint(fingerprint: ByteArray): CharSequence {
|
||||
return HexFormat.of().formatHex(fingerprint)
|
||||
}
|
||||
}
|
||||
)
|
||||
override fun hexFingerprint(fingerprint: ByteArray): CharSequence {
|
||||
return HexFormat.of().formatHex(fingerprint)
|
||||
}
|
||||
})
|
||||
|
||||
api.get().byUserId("Alice").execute()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue