logahawk.formatters
Class RollingHashedMessageFormatter

java.lang.Object
  extended by logahawk.formatters.HashedMessageFormatter
      extended by logahawk.formatters.RollingHashedMessageFormatter
All Implemented Interfaces:
MessageFormatter

@ThreadSafe
public class RollingHashedMessageFormatter
extends HashedMessageFormatter

Hashes log messages using a rolling hash -- that is the hash of the previous message is part of the hash for the following hash. This means the hash can be used to detect when a log messages have been added, removed, or reordered.


Nested Class Summary
 
Nested classes/interfaces inherited from class logahawk.formatters.HashedMessageFormatter
HashedMessageFormatter.HashMessagePair
 
Field Summary
protected  String previousDigest
           
 
Fields inherited from class logahawk.formatters.HashedMessageFormatter
hashPrefix, hashSuffix, messageDigest, messageFormatter
 
Constructor Summary
RollingHashedMessageFormatter(MessageFormatter messageFormatter, MessageDigest messageDigest)
           
 
Method Summary
protected  String createDigest(String message)
          Creates a digest from the provided message.
 int verify(List<String> messages)
          Verifies that the hash contained within the messages is the correct hash.
 
Methods inherited from class logahawk.formatters.HashedMessageFormatter
encode, format, getHashPrefix, getHashSuffix, setHashPrefix, setHashSuffix, splitMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

previousDigest

protected String previousDigest
Constructor Detail

RollingHashedMessageFormatter

public RollingHashedMessageFormatter(MessageFormatter messageFormatter,
                                     MessageDigest messageDigest)
                              throws CloneNotSupportedException
Throws:
CloneNotSupportedException - The MessageDigest must be cloneable for verify(List) to work correctly. The constructor tests cloning by calling MessageDigest.clone() and letting the exception go uncaught.
Method Detail

createDigest

protected String createDigest(String message)
Description copied from class: HashedMessageFormatter
Creates a digest from the provided message. This method may not be idempotent depending on the implementation.

Overrides:
createDigest in class HashedMessageFormatter

verify

public int verify(List<String> messages)
           throws IllegalArgumentException
Description copied from class: HashedMessageFormatter
Verifies that the hash contained within the messages is the correct hash.

Overrides:
verify in class HashedMessageFormatter
Returns:
The index of the first invalid message. If the returned index equals the length of the provided List, then all messages are valid.
Throws:
IllegalArgumentException - Thrown if the message does not contain a hash in the expected location.