mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
Maximum name length is specified in UTF-8 bytes, not characters.
This commit is contained in:
@@ -14,6 +14,7 @@ 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.io.UnsupportedEncodingException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.Executor;
|
||||
@@ -243,8 +244,13 @@ SelectContactsDialog.Listener {
|
||||
}
|
||||
|
||||
private boolean validateName() {
|
||||
int length = nameEntry.getText().length();
|
||||
if(length == 0 || length > MAX_GROUP_NAME_LENGTH) return false;
|
||||
if(nameEntry.getText().length() == 0) return false;
|
||||
try {
|
||||
byte[] b = nameEntry.getText().toString().getBytes("UTF-8");
|
||||
if(b.length > MAX_GROUP_NAME_LENGTH) return false;
|
||||
} catch(UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// Hide the soft keyboard
|
||||
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
||||
((InputMethodManager) o).toggleSoftInput(HIDE_IMPLICIT_ONLY, 0);
|
||||
|
||||
@@ -14,6 +14,7 @@ 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.io.UnsupportedEncodingException;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -136,8 +137,13 @@ implements OnEditorActionListener, OnClickListener {
|
||||
}
|
||||
|
||||
private boolean validateNickname() {
|
||||
int length = nicknameEntry.getText().length();
|
||||
if(length == 0 || length > MAX_AUTHOR_NAME_LENGTH) return false;
|
||||
if(nicknameEntry.getText().length() == 0) return false;
|
||||
try {
|
||||
byte[] b = nicknameEntry.getText().toString().getBytes("UTF-8");
|
||||
if(b.length > MAX_AUTHOR_NAME_LENGTH) return false;
|
||||
} catch(UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// Hide the soft keyboard
|
||||
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
||||
((InputMethodManager) o).toggleSoftInput(HIDE_IMPLICIT_ONLY, 0);
|
||||
|
||||
@@ -2,6 +2,8 @@ package org.briarproject.api;
|
||||
|
||||
import static org.briarproject.api.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/** A pseudonym for a user. */
|
||||
public class Author {
|
||||
|
||||
@@ -10,8 +12,13 @@ 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();
|
||||
if(name.length() == 0) throw new IllegalArgumentException();
|
||||
try {
|
||||
if(name.getBytes("UTF-8").length > MAX_AUTHOR_NAME_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
} catch(UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.publicKey = publicKey;
|
||||
|
||||
@@ -3,6 +3,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;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/** A group to which users may subscribe. */
|
||||
public class Group {
|
||||
|
||||
@@ -11,8 +13,13 @@ 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(name.length() == 0) throw new IllegalArgumentException();
|
||||
try {
|
||||
if(name.getBytes("UTF-8").length > MAX_GROUP_NAME_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
} catch(UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if(salt.length != GROUP_SALT_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
this.id = id;
|
||||
|
||||
Reference in New Issue
Block a user