diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2013-11-07 07:24:34 +0400 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2013-11-07 07:24:34 +0400 |
commit | 9d18c9c61e0c5aef829c08a51c92e999fd52e3b3 (patch) | |
tree | 35c5b01be0e5fc7b20fb15012ef92ee4910bd95e /core/src/main/java/org/bouncycastle/crypto/tls/DeferredHash.java | |
parent | 45345b383ab14a3924a1f22ff4076ef775c94fcd (diff) |
Refactoring in preparation for improving DeferredHash
Diffstat (limited to 'core/src/main/java/org/bouncycastle/crypto/tls/DeferredHash.java')
-rw-r--r-- | core/src/main/java/org/bouncycastle/crypto/tls/DeferredHash.java | 50 |
1 files changed, 23 insertions, 27 deletions
diff --git a/core/src/main/java/org/bouncycastle/crypto/tls/DeferredHash.java b/core/src/main/java/org/bouncycastle/crypto/tls/DeferredHash.java index b97aa47e..8c5801d6 100644 --- a/core/src/main/java/org/bouncycastle/crypto/tls/DeferredHash.java +++ b/core/src/main/java/org/bouncycastle/crypto/tls/DeferredHash.java @@ -33,7 +33,6 @@ class DeferredHash public TlsHandshakeHash commit() { int prfAlgorithm = context.getSecurityParameters().getPrfAlgorithm(); - Digest prfHash = TlsUtils.createPRFHash(prfAlgorithm); buf.updateDigest(prfHash); @@ -53,70 +52,67 @@ class DeferredHash public TlsHandshakeHash fork() { - checkHash(); int prfAlgorithm = context.getSecurityParameters().getPrfAlgorithm(); - return new DeferredHash(TlsUtils.clonePRFHash(prfAlgorithm, hash)); + Digest prfHash = TlsUtils.clonePRFHash(prfAlgorithm, checkHash()); + + return new DeferredHash(prfHash); } public String getAlgorithmName() { - checkHash(); - return hash.getAlgorithmName(); + return checkHash().getAlgorithmName(); } public int getDigestSize() { - checkHash(); - return hash.getDigestSize(); + return checkHash().getDigestSize(); } public void update(byte input) { - if (hash == null) + if (buf != null) { buf.write(input); + return; } - else - { - hash.update(input); - } + + hash.update(input); } public void update(byte[] input, int inOff, int len) { - if (hash == null) + if (buf != null) { buf.write(input, inOff, len); + return; } - else - { - hash.update(input, inOff, len); - } + + hash.update(input, inOff, len); } public int doFinal(byte[] output, int outOff) { - checkHash(); - return hash.doFinal(output, outOff); + return checkHash().doFinal(output, outOff); } public void reset() { - if (hash == null) + if (buf != null) { buf.reset(); + return; } - else - { - hash.reset(); - } + + hash.reset(); } - protected void checkHash() + protected Digest checkHash() { - if (hash == null) + if (buf != null) { - throw new IllegalStateException("No hash algorithm has been set"); + throw new IllegalStateException("No hash algorithm has been decided on"); } + + return hash; } } |