|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object logahawk.formatters.HashedMessageFormatter
@ThreadSafe public class HashedMessageFormatter
Calculates a hash of the log message, and prepends that has to the message. This formatter uses another MessageFormatter
to format the actual message, and this class handles the hashing.
The purpose of this MessageFormatter
is to provide integrity for individual log messages. This cannot
determine whether log messages have been added, removed, or reordered. (See RollingHashedMessageFormatter
Nested Class Summary | |
---|---|
protected static class |
HashedMessageFormatter.HashMessagePair
Helper class that holds the hash and original message separately. |
Field Summary | |
---|---|
protected String |
hashPrefix
|
protected String |
hashSuffix
|
protected MessageDigest |
messageDigest
Used to generate the hash. |
protected MessageFormatter |
messageFormatter
|
Constructor Summary | |
---|---|
HashedMessageFormatter(MessageFormatter messageFormatter,
MessageDigest messageDigest)
|
Method Summary | |
---|---|
protected String |
createDigest(String message)
Creates a digest from the provided message. |
protected String |
encode(byte[] digest)
Encodes the digest hash bytes into something smaller for a log message. |
String |
format(LogMeta meta,
String message)
The log message is first created by the constructor provided MessageFormatter . |
String |
getHashPrefix()
Returns the prefix for the Hash. |
String |
getHashSuffix()
Returns the suffix for the Hash. |
void |
setHashPrefix(String value)
|
void |
setHashSuffix(String value)
|
protected List<HashedMessageFormatter.HashMessagePair> |
splitMessage(List<String> messages)
Given a list of log messages, split the hash and message and return them inside of HashedMessageFormatter.HashMessagePair s. |
int |
verify(List<String> messages)
Verifies that the hash contained within the messages is the correct hash. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected volatile String hashPrefix
protected volatile String hashSuffix
protected final MessageDigest messageDigest
protected final MessageFormatter messageFormatter
Constructor Detail |
---|
public HashedMessageFormatter(MessageFormatter messageFormatter, MessageDigest messageDigest)
Method Detail |
---|
public String format(LogMeta meta, String message)
MessageFormatter
. Then that message is
digested. That digest is prepended to the message, and that final message is returned.
format
in interface MessageFormatter
public String getHashPrefix()
public void setHashPrefix(String value)
public String getHashSuffix()
public void setHashSuffix(String value)
protected String createDigest(String message)
protected String encode(byte[] digest)
MessageDigest
digest
- The byte[] buffer to encode, usually the results of a MessageDigest
.
protected List<HashedMessageFormatter.HashMessagePair> splitMessage(List<String> messages)
HashedMessageFormatter.HashMessagePair
s. This
method exists to simplify verify(List)
to make derived implementations simpler.
public int verify(List<String> messages) throws IllegalArgumentException
List
, then all messages are valid.
IllegalArgumentException
- Thrown if the message does not contain a hash in the expected location.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |