mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +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;
|
||||
|
||||
Reference in New Issue
Block a user