Refactoring: renamed 'security' to 'cryptography'

This commit is contained in:
2016-01-10 13:38:32 +01:00
parent de0100e14f
commit 549c8854ed
30 changed files with 72 additions and 74 deletions

View File

@@ -27,5 +27,5 @@ dependencies {
compile 'org.slf4j:slf4j-api:1.7.12'
testCompile 'junit:junit:4.11'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile project(':security-bc')
testCompile project(':cryptography-bc')
}

View File

@@ -325,7 +325,7 @@ public class BitmessageContext {
MessageRepository messageRepo;
ProofOfWorkRepository proofOfWorkRepository;
ProofOfWorkEngine proofOfWorkEngine;
Security security;
Cryptography cryptography;
MessageCallback messageCallback;
CustomCommandHandler customCommandHandler;
Listener listener;
@@ -372,8 +372,8 @@ public class BitmessageContext {
return this;
}
public Builder security(Security security) {
this.security = security;
public Builder cryptography(Cryptography cryptography) {
this.cryptography = cryptography;
return this;
}

View File

@@ -42,7 +42,7 @@ import java.util.TreeSet;
public class InternalContext {
private final static Logger LOG = LoggerFactory.getLogger(InternalContext.class);
private final Security security;
private final Cryptography cryptography;
private final Inventory inventory;
private final NodeRegistry nodeRegistry;
private final NetworkHandler networkHandler;
@@ -64,7 +64,7 @@ public class InternalContext {
private int connectionLimit;
public InternalContext(BitmessageContext.Builder builder) {
this.security = builder.security;
this.cryptography = builder.cryptography;
this.inventory = builder.inventory;
this.nodeRegistry = builder.nodeRegistry;
this.networkHandler = builder.networkHandler;
@@ -73,7 +73,7 @@ public class InternalContext {
this.proofOfWorkRepository = builder.proofOfWorkRepository;
this.proofOfWorkService = new ProofOfWorkService();
this.proofOfWorkEngine = builder.proofOfWorkEngine;
this.clientNonce = security.randomNonce();
this.clientNonce = cryptography.randomNonce();
this.messageCallback = builder.messageCallback;
this.customCommandHandler = builder.customCommandHandler;
this.port = builder.port;
@@ -81,7 +81,7 @@ public class InternalContext {
this.connectionTTL = builder.connectionTTL;
this.pubkeyTTL = builder.pubkeyTTL;
Singleton.initialize(security);
Singleton.initialize(cryptography);
// TODO: streams of new identities and subscriptions should also be added. This works only after a restart.
for (BitmessageAddress address : addressRepository.getIdentities()) {
@@ -94,7 +94,7 @@ public class InternalContext {
streams.add(1L);
}
init(security, inventory, nodeRegistry, networkHandler, addressRepository, messageRepository,
init(cryptography, inventory, nodeRegistry, networkHandler, addressRepository, messageRepository,
proofOfWorkRepository, proofOfWorkService, proofOfWorkEngine,
messageCallback, customCommandHandler);
for (BitmessageAddress identity : addressRepository.getIdentities()) {
@@ -110,8 +110,8 @@ public class InternalContext {
}
}
public Security getSecurity() {
return security;
public Cryptography getCryptography() {
return cryptography;
}
public Inventory getInventory() {
@@ -203,7 +203,7 @@ public class InternalContext {
.payload(identity.getPubkey())
.build();
response.sign(identity.getPrivateKey());
response.encrypt(security.createPublicKey(identity.getPublicDecryptionKey()));
response.encrypt(cryptography.createPublicKey(identity.getPublicDecryptionKey()));
messageCallback.proofOfWorkStarted(identity.getPubkey());
// TODO: remember that the pubkey is just about to be sent, and on which stream!
proofOfWorkService.doProofOfWork(response);

View File

@@ -7,7 +7,7 @@ import ch.dissem.bitmessage.entity.PlaintextHolder;
import ch.dissem.bitmessage.ports.MessageRepository;
import ch.dissem.bitmessage.ports.ProofOfWorkEngine;
import ch.dissem.bitmessage.ports.ProofOfWorkRepository;
import ch.dissem.bitmessage.ports.Security;
import ch.dissem.bitmessage.ports.Cryptography;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -21,7 +21,7 @@ import static ch.dissem.bitmessage.utils.Singleton.security;
public class ProofOfWorkService implements ProofOfWorkEngine.Callback, InternalContext.ContextHolder {
private final static Logger LOG = LoggerFactory.getLogger(ProofOfWorkService.class);
private Security security;
private Cryptography cryptography;
private InternalContext ctx;
private ProofOfWorkRepository powRepo;
private MessageRepository messageRepo;
@@ -33,7 +33,7 @@ public class ProofOfWorkService implements ProofOfWorkEngine.Callback, InternalC
LOG.info("Doing POW for " + items.size() + " tasks.");
for (byte[] initialHash : items) {
ProofOfWorkRepository.Item item = powRepo.getItem(initialHash);
security.doProofOfWork(item.object, item.nonceTrialsPerByte, item.extraBytes, this);
cryptography.doProofOfWork(item.object, item.nonceTrialsPerByte, item.extraBytes, this);
}
}
@@ -50,10 +50,10 @@ public class ProofOfWorkService implements ProofOfWorkEngine.Callback, InternalC
powRepo.putObject(object, nonceTrialsPerByte, extraBytes);
if (object.getPayload() instanceof PlaintextHolder) {
Plaintext plaintext = ((PlaintextHolder) object.getPayload()).getPlaintext();
plaintext.setInitialHash(security.getInitialHash(object));
plaintext.setInitialHash(cryptography.getInitialHash(object));
messageRepo.save(plaintext);
}
security.doProofOfWork(object, nonceTrialsPerByte, extraBytes, this);
cryptography.doProofOfWork(object, nonceTrialsPerByte, extraBytes, this);
}
@Override
@@ -75,7 +75,7 @@ public class ProofOfWorkService implements ProofOfWorkEngine.Callback, InternalC
@Override
public void setContext(InternalContext ctx) {
this.ctx = ctx;
this.security = security();
this.cryptography = security();
this.powRepo = ctx.getProofOfWorkRepository();
this.messageRepo = ctx.getMessageRepository();
}

View File

@@ -17,7 +17,6 @@
package ch.dissem.bitmessage.entity;
import ch.dissem.bitmessage.exception.DecryptionFailedException;
import ch.dissem.bitmessage.ports.Security;
import java.io.IOException;

View File

@@ -22,7 +22,6 @@ import ch.dissem.bitmessage.entity.payload.Pubkey;
import ch.dissem.bitmessage.entity.valueobject.InventoryVector;
import ch.dissem.bitmessage.entity.valueobject.PrivateKey;
import ch.dissem.bitmessage.exception.DecryptionFailedException;
import ch.dissem.bitmessage.ports.Security;
import ch.dissem.bitmessage.utils.Bytes;
import ch.dissem.bitmessage.utils.Encode;

View File

@@ -18,7 +18,6 @@ package ch.dissem.bitmessage.entity.payload;
import ch.dissem.bitmessage.entity.BitmessageAddress;
import ch.dissem.bitmessage.entity.Plaintext;
import ch.dissem.bitmessage.ports.Security;
import java.io.IOException;
import java.io.InputStream;

View File

@@ -39,8 +39,8 @@ import static ch.dissem.bitmessage.utils.Numbers.max;
/**
* Implements everything that isn't directly dependent on either Spongy- or Bouncycastle.
*/
public abstract class AbstractSecurity implements Security, InternalContext.ContextHolder {
public static final Logger LOG = LoggerFactory.getLogger(Security.class);
public abstract class AbstractCryptography implements Cryptography, InternalContext.ContextHolder {
public static final Logger LOG = LoggerFactory.getLogger(Cryptography.class);
private static final SecureRandom RANDOM = new SecureRandom();
private static final BigInteger TWO = BigInteger.valueOf(2);
private static final BigInteger TWO_POW_64 = TWO.pow(64);
@@ -49,7 +49,7 @@ public abstract class AbstractSecurity implements Security, InternalContext.Cont
private final String provider;
private InternalContext context;
protected AbstractSecurity(String provider) {
protected AbstractCryptography(String provider) {
this.provider = provider;
}

View File

@@ -29,7 +29,7 @@ import java.security.SecureRandom;
* Provides some methods to help with hashing and encryption. All randoms are created using {@link SecureRandom},
* which should be secure enough.
*/
public interface Security {
public interface Cryptography {
/**
* A helper method to calculate SHA-512 hashes. Please note that a new {@link MessageDigest} object is created at
* each call (to ensure thread safety), so you shouldn't use this if you need to do many hash calculations in

View File

@@ -16,23 +16,23 @@
package ch.dissem.bitmessage.utils;
import ch.dissem.bitmessage.ports.Security;
import ch.dissem.bitmessage.ports.Cryptography;
/**
* Created by chris on 20.07.15.
*/
public class Singleton {
private static Security security;
private static Cryptography cryptography;
public static void initialize(Security security) {
public static void initialize(Cryptography cryptography) {
synchronized (Singleton.class) {
if (Singleton.security == null) {
Singleton.security = security;
if (Singleton.cryptography == null) {
Singleton.cryptography = cryptography;
}
}
}
public static Security security() {
return security;
public static Cryptography security() {
return cryptography;
}
}

View File

@@ -16,13 +16,13 @@
package ch.dissem.bitmessage.utils;
import ch.dissem.bitmessage.security.bc.BouncySecurity;
import ch.dissem.bitmessage.cryptography.bc.BouncyCryptography;
/**
* Created by chris on 20.07.15.
*/
public class TestBase {
static {
Singleton.initialize(new BouncySecurity());
Singleton.initialize(new BouncyCryptography());
}
}