org.kafkacrypto.msgs.CertPoison Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kafkacrypto-java Show documentation
Show all versions of kafkacrypto-java Show documentation
Java port of kafkacrypto, a lightweight and cross-platform/cross-language encryption library for Apache Kafka.
The newest version!
package org.kafkacrypto.msgs;
import org.kafkacrypto.msgs.msgpack;
import org.msgpack.value.Value;
import java.util.List;
import java.util.regex.Pattern;
import org.kafkacrypto.msgs.PathlenPoison;
import org.kafkacrypto.msgs.UsagesPoison;
import org.kafkacrypto.msgs.TopicsPoison;
import java.io.IOException;
public interface CertPoison
{
public String poisonName();
public boolean multimatch(String match);
public CertPoison intersect_poison(CertPoison c2, boolean same_pk);
public static CertPoison unpackb(List src) throws IOException
{
String poison = src.get(0).asStringValue().asString();
if (poison.equals("pathlen"))
return new PathlenPoison(src.get(1).asIntegerValue().asInt());
if (poison.equals("usages"))
return new UsagesPoison().unpackb(src.get(1).asArrayValue().list());
if (poison.equals("topics"))
return new TopicsPoison().unpackb(src.get(1).asArrayValue().list());
throw new IOException("Unknown poison value!");
}
public static boolean multimatch(String wanted, List choices)
{
for (String c : choices) {
if (c.equals("^.*$")) return true; // choices has a "match everything" regex
if (!wanted.startsWith("^")) {
// Wanted is a Literal
if (!c.startsWith("^")) {
// c is a literal
if (wanted.equals(c)) return true;
} else {
// c is a regex
if (Pattern.matches(c, wanted)) return true;
}
} else {
// Wanted is a regex.
if (wanted.equals(c)) return true;
}
}
// did not find it.
return false;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy