mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-21 03:58:05 +01:00
Key transparency search and monitor endpoints
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2024 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.util;
|
||||
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public class CompletableFutureUtil {
|
||||
|
||||
public static <T> CompletableFuture<T> toCompletableFuture(final ListenableFuture<T> listenableFuture,
|
||||
final Executor callbackExecutor) {
|
||||
final CompletableFuture<T> completableFuture = new CompletableFuture<>();
|
||||
|
||||
Futures.addCallback(listenableFuture, new FutureCallback<T>() {
|
||||
@Override
|
||||
public void onSuccess(@Nullable final T result) {
|
||||
completableFuture.complete(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(final Throwable throwable) {
|
||||
completableFuture.completeExceptionally(throwable);
|
||||
}
|
||||
}, callbackExecutor);
|
||||
|
||||
return completableFuture;
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import javax.validation.Constraint;
|
||||
import javax.validation.ConstraintValidator;
|
||||
import javax.validation.ConstraintValidatorContext;
|
||||
@@ -25,7 +26,10 @@ import javax.validation.Payload;
|
||||
*/
|
||||
@Target({ FIELD, PARAMETER, METHOD })
|
||||
@Retention(RUNTIME)
|
||||
@Constraint(validatedBy = E164.Validator.class)
|
||||
@Constraint(validatedBy = {
|
||||
E164.Validator.class,
|
||||
E164.OptionalValidator.class
|
||||
})
|
||||
@Documented
|
||||
public @interface E164 {
|
||||
|
||||
@@ -53,4 +57,12 @@ public @interface E164 {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class OptionalValidator implements ConstraintValidator<E164, Optional<String>> {
|
||||
|
||||
@Override
|
||||
public boolean isValid(final Optional<String> value, final ConstraintValidatorContext context) {
|
||||
return value.map(s -> new Validator().isValid(s, context)).orElse(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2024 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.util;
|
||||
|
||||
import katie.FullTreeHead;
|
||||
|
||||
public class FullTreeHeadProtobufAdapter {
|
||||
|
||||
public static class Serializer extends ProtobufAdapter.Serializer<FullTreeHead> {}
|
||||
|
||||
public static class Deserializer extends ProtobufAdapter.Deserializer<FullTreeHead> {
|
||||
|
||||
public Deserializer() {
|
||||
super(FullTreeHead::newBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2024 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.util;
|
||||
|
||||
import katie.MonitorProof;
|
||||
|
||||
public class MonitorProofProtobufAdapter {
|
||||
|
||||
public static class Serializer extends ProtobufAdapter.Serializer<MonitorProof> {}
|
||||
|
||||
public static class Deserializer extends ProtobufAdapter.Deserializer<MonitorProof> {
|
||||
|
||||
public Deserializer() {
|
||||
super(MonitorProof::newBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2024 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.util;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.google.protobuf.Message;
|
||||
import com.google.protobuf.util.JsonFormat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ProtobufAdapter {
|
||||
|
||||
public static class Serializer<T extends Message> extends JsonSerializer<T> {
|
||||
|
||||
@Override
|
||||
public void serialize(T message, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
|
||||
throws IOException {
|
||||
jsonGenerator.writeString(JsonFormat.printer().print(message));
|
||||
}
|
||||
}
|
||||
|
||||
public static class Deserializer<T extends Message> extends JsonDeserializer<T> {
|
||||
|
||||
private final Supplier<Message.Builder> builderSupplier;
|
||||
|
||||
public Deserializer(Supplier<Message.Builder> builderSupplier) {
|
||||
this.builderSupplier = builderSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
|
||||
Message.Builder builder = builderSupplier.get();
|
||||
JsonFormat.parser().ignoringUnknownFields().merge(jsonParser.getValueAsString(), builder);
|
||||
return (T) builder.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2024 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.util;
|
||||
|
||||
import katie.SearchResponse;
|
||||
|
||||
public class SearchResponseProtobufAdapter {
|
||||
|
||||
public static class Serializer extends ProtobufAdapter.Serializer<SearchResponse> {}
|
||||
|
||||
public static class Deserializer extends ProtobufAdapter.Deserializer<SearchResponse> {
|
||||
|
||||
public Deserializer() {
|
||||
super(SearchResponse::newBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user