Check that author and group names aren't empty.

This commit is contained in:
akwizgran
2014-01-31 17:23:14 +00:00
parent 93890d56f6
commit cde4ca574f
9 changed files with 26 additions and 9 deletions

View File

@@ -249,7 +249,7 @@ abstract class Connector extends Thread {
r.readListStart();
while(!r.hasListEnd()) {
String idString = r.readString(MAX_TRANSPORT_ID_LENGTH);
if(idString.equals("")) throw new FormatException();
if(idString.length() == 0) throw new FormatException();
TransportId id = new TransportId(idString);
Map<String, String> p = new HashMap<String, String>();
r.readMapStart();

View File

@@ -8,6 +8,7 @@ import java.io.IOException;
import org.briarproject.api.Author;
import org.briarproject.api.AuthorId;
import org.briarproject.api.FormatException;
import org.briarproject.api.crypto.CryptoComponent;
import org.briarproject.api.crypto.MessageDigest;
import org.briarproject.api.serial.DigestingConsumer;
@@ -29,6 +30,7 @@ class AuthorReader implements StructReader<Author> {
// Read and digest the data
r.readStructStart(AUTHOR);
String name = r.readString(MAX_AUTHOR_NAME_LENGTH);
if(name.length() == 0) throw new FormatException();
byte[] publicKey = r.readBytes(MAX_PUBLIC_KEY_LENGTH);
r.readStructEnd();
// Reset the reader

View File

@@ -213,7 +213,7 @@ class PacketReaderImpl implements PacketReader {
public TransportAck readTransportAck() throws IOException {
r.readStructStart(TRANSPORT_ACK);
String idString = r.readString(MAX_TRANSPORT_ID_LENGTH);
if(idString.equals("")) throw new FormatException();
if(idString.length() == 0) throw new FormatException();
TransportId id = new TransportId(idString);
long version = r.readInteger();
if(version < 0) throw new FormatException();
@@ -233,7 +233,7 @@ class PacketReaderImpl implements PacketReader {
r.readStructStart(TRANSPORT_UPDATE);
// Read the transport ID
String idString = r.readString(MAX_TRANSPORT_ID_LENGTH);
if(idString.equals("")) throw new FormatException();
if(idString.length() == 0) throw new FormatException();
TransportId id = new TransportId(idString);
// Read the transport properties
Map<String, String> p = new HashMap<String, String>();

View File

@@ -8,7 +8,7 @@ public class StringUtils {
};
public static boolean isNullOrEmpty(String s) {
return s == null || s.equals("");
return s == null || s.length() == 0;
}
/**
@@ -17,7 +17,7 @@ public class StringUtils {
*/
public static String head(String s, int length) {
if(s.length() > length) return s.substring(0, length) + "...";
else return s;
return s;
}
/**
@@ -26,7 +26,7 @@ public class StringUtils {
*/
public static String tail(String s, int length) {
if(s.length() > length) return "..." + s.substring(s.length() - length);
else return s;
return s;
}
/** Converts the given byte array to a hex character array. */