mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 12:19:54 +01:00
Convert to and from UTF-8 without catching impossible exceptions.
All JVMs must support UTF-8 encoding.
This commit is contained in:
@@ -2,7 +2,7 @@ package org.briarproject.api;
|
||||
|
||||
import static org.briarproject.api.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/** A pseudonym for a user. */
|
||||
public class Author {
|
||||
@@ -14,13 +14,9 @@ public class Author {
|
||||
private final byte[] publicKey;
|
||||
|
||||
public Author(AuthorId id, String name, byte[] publicKey) {
|
||||
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);
|
||||
}
|
||||
int length = name.getBytes(Charset.forName("UTF-8")).length;
|
||||
if(length == 0 || length > MAX_AUTHOR_NAME_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.publicKey = publicKey;
|
||||
|
||||
@@ -3,7 +3,7 @@ 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;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/** A group to which users may subscribe. */
|
||||
public class Group {
|
||||
@@ -13,13 +13,9 @@ public class Group {
|
||||
private final byte[] salt;
|
||||
|
||||
public Group(GroupId id, String name, byte[] salt) {
|
||||
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);
|
||||
}
|
||||
int length = name.getBytes(Charset.forName("UTF-8")).length;
|
||||
if(length == 0 || length > MAX_GROUP_NAME_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
if(salt.length != GROUP_SALT_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
this.id = id;
|
||||
|
||||
Reference in New Issue
Block a user