it.auties.whatsapp.model.signal.message.SignalDistributionMessage Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of whatsappweb4j Show documentation
Show all versions of whatsappweb4j Show documentation
Standalone fully-featured Whatsapp Web API for Java and Kotlin
package it.auties.whatsapp.model.signal.message;
import it.auties.protobuf.base.ProtobufProperty;
import it.auties.whatsapp.util.BytesHelper;
import it.auties.whatsapp.util.Protobuf;
import it.auties.whatsapp.util.Spec;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NonNull;
import lombok.experimental.Accessors;
import lombok.extern.jackson.Jacksonized;
import java.util.Arrays;
import static it.auties.protobuf.base.ProtobufType.BYTES;
import static it.auties.protobuf.base.ProtobufType.UINT32;
@AllArgsConstructor
@Data
@Builder
@Jacksonized
@Accessors(fluent = true)
public final class SignalDistributionMessage implements SignalProtocolMessage {
/**
* The version of this message
*/
private int version;
/**
* The jid of the sender
*/
@ProtobufProperty(index = 1, type = UINT32)
private Integer id;
/**
* The iteration of the message
*/
@ProtobufProperty(index = 2, type = UINT32)
private Integer iteration;
/**
* The value key of the message
*/
@ProtobufProperty(index = 3, type = BYTES)
private byte @NonNull [] chainKey;
/**
* The signing key of the message
*/
@ProtobufProperty(index = 4, type = BYTES)
private byte @NonNull [] signingKey;
/**
* This message in a serialized form
*/
private byte[] serialized;
public SignalDistributionMessage(int id, int iteration, byte @NonNull [] chainKey, byte @NonNull [] signingKey) {
this.version = Spec.Signal.CURRENT_VERSION;
this.id = id;
this.iteration = iteration;
this.chainKey = chainKey;
this.signingKey = signingKey;
this.serialized = BytesHelper.concat(serializedVersion(), Protobuf.writeMessage(this));
}
public static SignalDistributionMessage ofSerialized(byte[] serialized) {
return Protobuf.readMessage(Arrays.copyOfRange(serialized, 1, serialized.length), SignalDistributionMessage.class)
.version(BytesHelper.bytesToVersion(serialized[0]))
.serialized(serialized);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy