All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.kafkacrypto.KafkaCryptoMessage Maven / Gradle / Ivy

Go to download

Java port of kafkacrypto, a lightweight and cross-platform/cross-language encryption library for Apache Kafka.

There is a newer version: 0.9.11.0
Show newest version
package org.kafkacrypto;

import org.kafkacrypto.msgs.KafkaCryptoWireMessage;
import org.kafkacrypto.msgs.KafkaPlainWireMessage;

import org.kafkacrypto.exceptions.KafkaCryptoMessageException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

public interface KafkaCryptoMessage
{
  static final Logger _logger = LoggerFactory.getLogger("kafkacrypto-java.kafkacryptomessage");
  public boolean isCleartext();
  public boolean isCleartext(boolean retry);
  public byte[] getMessage() throws KafkaCryptoMessageException;
  public byte[] toWire() throws IOException;

  public static KafkaCryptoMessage fromWire(byte[] wire)
  {
    if (wire == null || wire.length < 1) return null;
    byte[][] msgs = Utils.splitArray(wire,1);
    try {
      if (msgs[0][0] == 1)
        return new KafkaCryptoWireMessage().unpackb(msgs[1]);
      if (msgs[0][0] == 0)
        return new KafkaPlainWireMessage().unpackb(msgs[1]);
    } catch (IOException ioe) {
      KafkaCryptoMessage._logger.info("Error unpacking message", ioe);
    }
    return null;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy