Skip to content
Browse files

Cache sysinfo response in constructor.

Besides enabling us to do efficient version differentiation, this
ensures we are really in sync after the CommandHandler.reset().
  • Loading branch information...
1 parent c83c63a commit d6a27851f5d93e09d7c4fac1e3a93330ee904c62 @fredrikt fredrikt committed
Showing with 6 additions and 4 deletions.
  1. +6 −4 src/main/java/org/unitedid/yhsm/YubiHSM.java
View
10 src/main/java/org/unitedid/yhsm/YubiHSM.java
@@ -37,6 +37,9 @@
/** The hash length, default is 20 */
public static int minHashLength = 20;
+ /* YubiHSM sysinfo cache */
+ private Map<String, String> info;
+
/**
* Constructor
*
@@ -47,6 +50,7 @@
public YubiHSM(String device, float timeout) throws YubiHSMErrorException {
deviceHandler = DeviceHandlerFactory.get(device, timeout);
CommandHandler.reset(deviceHandler);
+ info = SystemInfoCmd.execute(deviceHandler);
}
/**
@@ -67,18 +71,16 @@ public String echo(String str) throws YubiHSMErrorException {
* @throws YubiHSMErrorException if the YubiHSM info command fail
*/
public Map<String, String> info() throws YubiHSMErrorException {
- return SystemInfoCmd.execute(deviceHandler);
+ return info;
}
/**
- * Get the firmware verseion and unique ID from the YubiHSM (string representation).
+ * Get the firmware version and unique ID from the YubiHSM (string representation).
*
* @return a string with version, protocol and unique ID
* @throws YubiHSMErrorException if the YubiHSM info command fail
*/
public String infoToString() throws YubiHSMErrorException {
- Map<String, String> info = SystemInfoCmd.execute(deviceHandler);
-
return String.format("Version %s.%s.%s Protocol=%s SysId: %s", info.get("major"), info.get("minor"),
info.get("build"), info.get("protocol"),
info.get("sysid"));

0 comments on commit d6a2785

Please sign in to comment.
Something went wrong with that request. Please try again.