mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Moved some API classes into packages.
This commit is contained in:
52
briar-api/src/org/briarproject/api/identity/Author.java
Normal file
52
briar-api/src/org/briarproject/api/identity/Author.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package org.briarproject.api.identity;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/** A pseudonym for a user. */
|
||||
public class Author {
|
||||
|
||||
public enum Status { ANONYMOUS, UNKNOWN, UNVERIFIED, VERIFIED }
|
||||
|
||||
private final AuthorId id;
|
||||
private final String name;
|
||||
private final byte[] publicKey;
|
||||
|
||||
public Author(AuthorId id, String name, byte[] publicKey) {
|
||||
int length;
|
||||
try {
|
||||
length = name.getBytes("UTF-8").length;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if (length == 0 || length > AuthorConstants.MAX_AUTHOR_NAME_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.publicKey = publicKey;
|
||||
}
|
||||
|
||||
/** Returns the author's unique identifier. */
|
||||
public AuthorId getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/** Returns the author's name. */
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/** Returns the public key used to verify the pseudonym's signatures. */
|
||||
public byte[] getPublicKey() {
|
||||
return publicKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof Author && id.equals(((Author) o).id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.briarproject.api.identity;
|
||||
|
||||
public interface AuthorConstants {
|
||||
|
||||
/** The maximum length of an author's name in UTF-8 bytes. */
|
||||
int MAX_AUTHOR_NAME_LENGTH = 50;
|
||||
|
||||
/**
|
||||
* The maximum length of a public key in bytes.
|
||||
* <p>
|
||||
* Public keys use SEC1 format: 0x04 x y, where x and y are unsigned
|
||||
* big-endian integers.
|
||||
* <p>
|
||||
* For a 256-bit elliptic curve, the maximum length is 2 * 256 / 8 + 1.
|
||||
*/
|
||||
int MAX_PUBLIC_KEY_LENGTH = 65;
|
||||
|
||||
/**
|
||||
* The maximum length of a signature in bytes.
|
||||
* <p>
|
||||
* A signature is an ASN.1 DER sequence containing two integers, r and s.
|
||||
* The format is 0x30 len1 0x02 len2 r 0x02 len3 s, where len1 is
|
||||
* len(0x02 len2 r 0x02 len3 s) as a DER length, len2 is len(r) as a DER
|
||||
* length, len3 is len(s) as a DER length, and r and s are signed
|
||||
* big-endian integers of minimal length.
|
||||
* <p>
|
||||
* For a 256-bit elliptic curve, the lengths are one byte each, so the
|
||||
* maximum length is 2 * 256 / 8 + 8.
|
||||
*/
|
||||
int MAX_SIGNATURE_LENGTH = 72;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.briarproject.api.identity;
|
||||
|
||||
public interface AuthorFactory {
|
||||
|
||||
Author createAuthor(String name, byte[] publicKey);
|
||||
|
||||
LocalAuthor createLocalAuthor(String name, byte[] publicKey,
|
||||
byte[] privateKey);
|
||||
}
|
||||
23
briar-api/src/org/briarproject/api/identity/AuthorId.java
Normal file
23
briar-api/src/org/briarproject/api/identity/AuthorId.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package org.briarproject.api.identity;
|
||||
|
||||
import org.briarproject.api.UniqueId;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Type-safe wrapper for a byte array that uniquely identifies an
|
||||
* {@link Author}.
|
||||
*/
|
||||
public class AuthorId extends UniqueId {
|
||||
|
||||
public AuthorId(byte[] id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof AuthorId)
|
||||
return Arrays.equals(id, ((AuthorId) o).id);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.briarproject.api.identity;
|
||||
|
||||
import org.briarproject.api.AuthorId;
|
||||
import org.briarproject.api.LocalAuthor;
|
||||
import org.briarproject.api.db.DbException;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
24
briar-api/src/org/briarproject/api/identity/LocalAuthor.java
Normal file
24
briar-api/src/org/briarproject/api/identity/LocalAuthor.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package org.briarproject.api.identity;
|
||||
|
||||
/** A pseudonym for the local user. */
|
||||
public class LocalAuthor extends Author {
|
||||
|
||||
private final byte[] privateKey;
|
||||
private final long created;
|
||||
|
||||
public LocalAuthor(AuthorId id, String name, byte[] publicKey,
|
||||
byte[] privateKey, long created) {
|
||||
super(id, name, publicKey);
|
||||
this.privateKey = privateKey;
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
/** Returns the private key used to generate the pseudonym's signatures. */
|
||||
public byte[] getPrivateKey() {
|
||||
return privateKey;
|
||||
}
|
||||
|
||||
public long getTimeCreated() {
|
||||
return created;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user