mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 12:49:55 +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 java.util.logging.Level.WARNING;
|
||||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
|
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
|
||||||
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP;
|
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.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -242,7 +243,8 @@ SelectContactsDialog.Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean validateName() {
|
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
|
// Hide the soft keyboard
|
||||||
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
||||||
((InputMethodManager) o).toggleSoftInput(HIDE_IMPLICIT_ONLY, 0);
|
((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 java.util.logging.Level.WARNING;
|
||||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
|
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
|
||||||
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP;
|
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.concurrent.Executor;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@@ -135,7 +136,8 @@ implements OnEditorActionListener, OnClickListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean validateNickname() {
|
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
|
// Hide the soft keyboard
|
||||||
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
||||||
((InputMethodManager) o).toggleSoftInput(HIDE_IMPLICIT_ONLY, 0);
|
((InputMethodManager) o).toggleSoftInput(HIDE_IMPLICIT_ONLY, 0);
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package org.briarproject.api;
|
package org.briarproject.api;
|
||||||
|
|
||||||
|
import static org.briarproject.api.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||||
|
|
||||||
/** A pseudonym for a user. */
|
/** A pseudonym for a user. */
|
||||||
public class Author {
|
public class Author {
|
||||||
|
|
||||||
@@ -8,6 +10,8 @@ public class Author {
|
|||||||
private final byte[] publicKey;
|
private final byte[] publicKey;
|
||||||
|
|
||||||
public Author(AuthorId id, String name, 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.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.publicKey = publicKey;
|
this.publicKey = publicKey;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public class TransportId {
|
|||||||
private final String id;
|
private final String id;
|
||||||
|
|
||||||
public TransportId(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();
|
throw new IllegalArgumentException();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package org.briarproject.api.messaging;
|
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. */
|
/** A group to which users may subscribe. */
|
||||||
public class Group {
|
public class Group {
|
||||||
|
|
||||||
@@ -8,6 +11,10 @@ public class Group {
|
|||||||
private final byte[] salt;
|
private final byte[] salt;
|
||||||
|
|
||||||
public Group(GroupId id, String name, 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.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.salt = salt;
|
this.salt = salt;
|
||||||
|
|||||||
@@ -249,7 +249,7 @@ abstract class Connector extends Thread {
|
|||||||
r.readListStart();
|
r.readListStart();
|
||||||
while(!r.hasListEnd()) {
|
while(!r.hasListEnd()) {
|
||||||
String idString = r.readString(MAX_TRANSPORT_ID_LENGTH);
|
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);
|
TransportId id = new TransportId(idString);
|
||||||
Map<String, String> p = new HashMap<String, String>();
|
Map<String, String> p = new HashMap<String, String>();
|
||||||
r.readMapStart();
|
r.readMapStart();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import org.briarproject.api.Author;
|
import org.briarproject.api.Author;
|
||||||
import org.briarproject.api.AuthorId;
|
import org.briarproject.api.AuthorId;
|
||||||
|
import org.briarproject.api.FormatException;
|
||||||
import org.briarproject.api.crypto.CryptoComponent;
|
import org.briarproject.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.api.crypto.MessageDigest;
|
import org.briarproject.api.crypto.MessageDigest;
|
||||||
import org.briarproject.api.serial.DigestingConsumer;
|
import org.briarproject.api.serial.DigestingConsumer;
|
||||||
@@ -29,6 +30,7 @@ class AuthorReader implements StructReader<Author> {
|
|||||||
// Read and digest the data
|
// Read and digest the data
|
||||||
r.readStructStart(AUTHOR);
|
r.readStructStart(AUTHOR);
|
||||||
String name = r.readString(MAX_AUTHOR_NAME_LENGTH);
|
String name = r.readString(MAX_AUTHOR_NAME_LENGTH);
|
||||||
|
if(name.length() == 0) throw new FormatException();
|
||||||
byte[] publicKey = r.readBytes(MAX_PUBLIC_KEY_LENGTH);
|
byte[] publicKey = r.readBytes(MAX_PUBLIC_KEY_LENGTH);
|
||||||
r.readStructEnd();
|
r.readStructEnd();
|
||||||
// Reset the reader
|
// Reset the reader
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ class PacketReaderImpl implements PacketReader {
|
|||||||
public TransportAck readTransportAck() throws IOException {
|
public TransportAck readTransportAck() throws IOException {
|
||||||
r.readStructStart(TRANSPORT_ACK);
|
r.readStructStart(TRANSPORT_ACK);
|
||||||
String idString = r.readString(MAX_TRANSPORT_ID_LENGTH);
|
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);
|
TransportId id = new TransportId(idString);
|
||||||
long version = r.readInteger();
|
long version = r.readInteger();
|
||||||
if(version < 0) throw new FormatException();
|
if(version < 0) throw new FormatException();
|
||||||
@@ -233,7 +233,7 @@ class PacketReaderImpl implements PacketReader {
|
|||||||
r.readStructStart(TRANSPORT_UPDATE);
|
r.readStructStart(TRANSPORT_UPDATE);
|
||||||
// Read the transport ID
|
// Read the transport ID
|
||||||
String idString = r.readString(MAX_TRANSPORT_ID_LENGTH);
|
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);
|
TransportId id = new TransportId(idString);
|
||||||
// Read the transport properties
|
// Read the transport properties
|
||||||
Map<String, String> p = new HashMap<String, String>();
|
Map<String, String> p = new HashMap<String, String>();
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public class StringUtils {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public static boolean isNullOrEmpty(String s) {
|
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) {
|
public static String head(String s, int length) {
|
||||||
if(s.length() > length) return s.substring(0, 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) {
|
public static String tail(String s, int length) {
|
||||||
if(s.length() > length) return "..." + s.substring(s.length() - 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. */
|
/** Converts the given byte array to a hex character array. */
|
||||||
|
|||||||
Reference in New Issue
Block a user