From b109a94155659e4578a7f1f0f423b761227343b4 Mon Sep 17 00:00:00 2001 From: akwizgran <michael@briarproject.org> Date: Fri, 5 Apr 2013 21:13:24 +0100 Subject: [PATCH] Added a factory method for local authors. --- briar-api/src/net/sf/briar/api/AuthorFactory.java | 3 +++ .../net/sf/briar/messaging/AuthorFactoryImpl.java | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/briar-api/src/net/sf/briar/api/AuthorFactory.java b/briar-api/src/net/sf/briar/api/AuthorFactory.java index f9c50ca838..5b881f9f5b 100644 --- a/briar-api/src/net/sf/briar/api/AuthorFactory.java +++ b/briar-api/src/net/sf/briar/api/AuthorFactory.java @@ -5,4 +5,7 @@ import java.io.IOException; public interface AuthorFactory { Author createAuthor(String name, byte[] publicKey) throws IOException; + + LocalAuthor createLocalAuthor(String name, byte[] publicKey, + byte[] privateKey) throws IOException; } diff --git a/briar-core/src/net/sf/briar/messaging/AuthorFactoryImpl.java b/briar-core/src/net/sf/briar/messaging/AuthorFactoryImpl.java index 976094a197..67cfde1a17 100644 --- a/briar-core/src/net/sf/briar/messaging/AuthorFactoryImpl.java +++ b/briar-core/src/net/sf/briar/messaging/AuthorFactoryImpl.java @@ -8,6 +8,7 @@ import java.io.IOException; import net.sf.briar.api.Author; import net.sf.briar.api.AuthorFactory; import net.sf.briar.api.AuthorId; +import net.sf.briar.api.LocalAuthor; import net.sf.briar.api.crypto.CryptoComponent; import net.sf.briar.api.crypto.MessageDigest; import net.sf.briar.api.serial.Writer; @@ -28,6 +29,16 @@ class AuthorFactoryImpl implements AuthorFactory { public Author createAuthor(String name, byte[] publicKey) throws IOException { + return new Author(getId(name, publicKey), name, publicKey); + } + + public LocalAuthor createLocalAuthor(String name, byte[] publicKey, + byte[] privateKey) throws IOException { + return new LocalAuthor(getId(name, publicKey), name, publicKey, + privateKey); + } + + private AuthorId getId(String name, byte[] publicKey) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); Writer w = writerFactory.createWriter(out); w.writeStructId(AUTHOR); @@ -35,7 +46,6 @@ class AuthorFactoryImpl implements AuthorFactory { w.writeBytes(publicKey); MessageDigest messageDigest = crypto.getMessageDigest(); messageDigest.update(out.toByteArray()); - AuthorId id = new AuthorId(messageDigest.digest()); - return new Author(id, name, publicKey); + return new AuthorId(messageDigest.digest()); } } -- GitLab