Skip to content

Commit

Permalink
clean up blowfish code - formatting and include exception cause
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanmarz committed Feb 18, 2013
1 parent 0267c00 commit 141aad4
Showing 1 changed file with 26 additions and 26 deletions.
Expand Up @@ -30,45 +30,45 @@ public class BlowfishTupleSerializer extends Serializer<ListDelegate> {
private BlowfishSerializer _serializer;

public BlowfishTupleSerializer(Kryo kryo, Map storm_conf) {
String encryption_key = null;
try {
encryption_key = (String)storm_conf.get(SECRET_KEY);
LOG.debug("Blowfish serializer being constructed ...");
if (encryption_key == null) {
LOG.error("Encryption key not specified");
throw new RuntimeException("Blowfish encryption key not specified");
}
byte[] bytes = Hex.decodeHex(encryption_key.toCharArray());
_serializer = new BlowfishSerializer(new ListDelegateSerializer(), bytes);
} catch (org.apache.commons.codec.DecoderException ex) {
LOG.error("Invalid encryption key");
throw new RuntimeException("Blowfish encryption key invalid");
}
String encryption_key = null;
try {
encryption_key = (String)storm_conf.get(SECRET_KEY);
LOG.debug("Blowfish serializer being constructed ...");
if (encryption_key == null) {
LOG.error("Encryption key not specified");
throw new RuntimeException("Blowfish encryption key not specified");
}
byte[] bytes = Hex.decodeHex(encryption_key.toCharArray());
_serializer = new BlowfishSerializer(new ListDelegateSerializer(), bytes);
} catch (org.apache.commons.codec.DecoderException ex) {
LOG.error("Invalid encryption key", ex);
throw new RuntimeException("Blowfish encryption key invalid", ex);
}
}

@Override
public void write(Kryo kryo, Output output, ListDelegate object) {
_serializer.write(kryo, output, object);
_serializer.write(kryo, output, object);
}

@Override
public ListDelegate read(Kryo kryo, Input input, Class<ListDelegate> type) {
return (ListDelegate)_serializer.read(kryo, input, type);
return (ListDelegate)_serializer.read(kryo, input, type);
}

/**
* Produce a blowfish key to be used in "Storm jar" command
*/
public static void main(String[] args) {
try{
KeyGenerator kgen = KeyGenerator.getInstance("Blowfish");
SecretKey skey = kgen.generateKey();
byte[] raw = skey.getEncoded();
String keyString = new String(Hex.encodeHex(raw));
System.out.println("storm -c "+SECRET_KEY+"="+keyString+" -c "+Config.TOPOLOGY_TUPLE_SERIALIZER+"="+BlowfishTupleSerializer.class.getName() + " ..." );
} catch (Exception ex) {
LOG.error(ex.getMessage());
ex.printStackTrace();
}
try{
KeyGenerator kgen = KeyGenerator.getInstance("Blowfish");
SecretKey skey = kgen.generateKey();
byte[] raw = skey.getEncoded();
String keyString = new String(Hex.encodeHex(raw));
System.out.println("storm -c "+SECRET_KEY+"="+keyString+" -c "+Config.TOPOLOGY_TUPLE_SERIALIZER+"="+BlowfishTupleSerializer.class.getName() + " ..." );
} catch (Exception ex) {
LOG.error(ex.getMessage());
ex.printStackTrace();
}
}
}

0 comments on commit 141aad4

Please sign in to comment.