mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Check that author and group names aren't empty.
This commit is contained in:
@@ -12,6 +12,7 @@ import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP;
|
||||
import static org.briarproject.api.messaging.MessagingConstants.MAX_GROUP_NAME_LENGTH;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -242,7 +243,8 @@ SelectContactsDialog.Listener {
|
||||
}
|
||||
|
||||
private boolean validateName() {
|
||||
if(nameEntry.getText().toString().equals("")) return false;
|
||||
int length = nameEntry.getText().length();
|
||||
if(length == 0 || length > MAX_GROUP_NAME_LENGTH) return false;
|
||||
// Hide the soft keyboard
|
||||
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
||||
((InputMethodManager) o).toggleSoftInput(HIDE_IMPLICIT_ONLY, 0);
|
||||
|
||||
@@ -12,6 +12,7 @@ import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP;
|
||||
import static org.briarproject.api.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
@@ -135,7 +136,8 @@ implements OnEditorActionListener, OnClickListener {
|
||||
}
|
||||
|
||||
private boolean validateNickname() {
|
||||
if(nicknameEntry.getText().toString().equals("")) return false;
|
||||
int length = nicknameEntry.getText().length();
|
||||
if(length == 0 || length > MAX_AUTHOR_NAME_LENGTH) return false;
|
||||
// Hide the soft keyboard
|
||||
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
||||
((InputMethodManager) o).toggleSoftInput(HIDE_IMPLICIT_ONLY, 0);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.briarproject.api;
|
||||
|
||||
import static org.briarproject.api.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||
|
||||
/** A pseudonym for a user. */
|
||||
public class Author {
|
||||
|
||||
@@ -8,6 +10,8 @@ public class Author {
|
||||
private final byte[] publicKey;
|
||||
|
||||
public Author(AuthorId id, String name, byte[] publicKey) {
|
||||
if(name.length() == 0 || name.length() > MAX_AUTHOR_NAME_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.publicKey = publicKey;
|
||||
|
||||
@@ -10,7 +10,7 @@ public class TransportId {
|
||||
private final String id;
|
||||
|
||||
public TransportId(String id) {
|
||||
if(id.length() > MAX_TRANSPORT_ID_LENGTH || id.equals(""))
|
||||
if(id.length() == 0 || id.length() > MAX_TRANSPORT_ID_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package org.briarproject.api.messaging;
|
||||
|
||||
import static org.briarproject.api.messaging.MessagingConstants.GROUP_SALT_LENGTH;
|
||||
import static org.briarproject.api.messaging.MessagingConstants.MAX_GROUP_NAME_LENGTH;
|
||||
|
||||
/** A group to which users may subscribe. */
|
||||
public class Group {
|
||||
|
||||
@@ -8,6 +11,10 @@ public class Group {
|
||||
private final byte[] salt;
|
||||
|
||||
public Group(GroupId id, String name, byte[] salt) {
|
||||
if(name.length() == 0 || name.length() > MAX_GROUP_NAME_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
if(salt.length != GROUP_SALT_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.salt = salt;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>();
|
||||
|
||||
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user