Make the API of all encoding classes similar

pull/41/head
Alexander Bakker 7 years ago
parent 9c433f96cf
commit 0ad39ab673

@ -32,8 +32,8 @@ public class DatabaseFile {
JSONObject cryptObj = null;
if (_cryptParameters != null) {
cryptObj = new JSONObject();
cryptObj.put("nonce", Hex.toString(_cryptParameters.Nonce));
cryptObj.put("tag", Hex.toString(_cryptParameters.Tag));
cryptObj.put("nonce", Hex.encode(_cryptParameters.Nonce));
cryptObj.put("tag", Hex.encode(_cryptParameters.Tag));
}
// don't write the crypt parameters if the content is not encrypted
@ -70,8 +70,8 @@ public class DatabaseFile {
JSONObject cryptObj = headerObj.optJSONObject("params");
if (cryptObj != null) {
_cryptParameters = new CryptParameters() {{
Nonce = Hex.toBytes(cryptObj.getString("nonce"));
Tag = Hex.toBytes(cryptObj.getString("tag"));
Nonce = Hex.decode(cryptObj.getString("nonce"));
Tag = Hex.decode(cryptObj.getString("tag"));
}};
}

@ -29,7 +29,7 @@ public class PasswordSlot extends RawSlot {
obj.put("n", _n);
obj.put("r", _r);
obj.put("p", _p);
obj.put("salt", Hex.toString(_salt));
obj.put("salt", Hex.encode(_salt));
return obj;
} catch (JSONException e) {
throw new SlotException(e);
@ -43,7 +43,7 @@ public class PasswordSlot extends RawSlot {
_n = obj.getInt("n");
_r = obj.getInt("r");
_p = obj.getInt("p");
_salt = Hex.toBytes(obj.getString("salt"));
_salt = Hex.decode(obj.getString("salt"));
} catch (JSONException | HexException e) {
throw new SlotException(e);
}

@ -72,7 +72,7 @@ public abstract class Slot implements Serializable {
JSONObject obj = new JSONObject();
obj.put("type", getType());
obj.put("uuid", _uuid.toString());
obj.put("key", Hex.toString(_encryptedMasterKey));
obj.put("key", Hex.encode(_encryptedMasterKey));
return obj;
} catch (JSONException e) {
throw new SlotException(e);
@ -90,7 +90,7 @@ public abstract class Slot implements Serializable {
} else {
_uuid = UUID.fromString(obj.getString("uuid"));
}
_encryptedMasterKey = Hex.toBytes(obj.getString("key"));
_encryptedMasterKey = Hex.decode(obj.getString("key"));
} catch (JSONException | HexException e) {
throw new SlotException(e);
}

@ -22,7 +22,7 @@ public class SlotCollection implements Iterable<Slot>, Serializable {
public static JSONObject serialize(SlotCollection slots) throws SlotCollectionException {
try {
JSONObject obj = new JSONObject();
obj.put("hash", Hex.toString(slots.getMasterHash()));
obj.put("hash", Hex.encode(slots.getMasterHash()));
JSONArray entries = new JSONArray();
for (Slot slot : slots) {
@ -40,7 +40,7 @@ public class SlotCollection implements Iterable<Slot>, Serializable {
SlotCollection slots = new SlotCollection();
try {
byte[] masterHash = Hex.toBytes(obj.getString("hash"));
byte[] masterHash = Hex.decode(obj.getString("hash"));
slots.setMasterHash(masterHash);
JSONArray entries = obj.getJSONArray("entries");

@ -15,7 +15,7 @@ public class Hex {
private static final char[] hexCode = "0123456789abcdef".toCharArray();
public static byte[] toBytes(String s) throws HexException {
public static byte[] decode(String s) throws HexException {
final int len = s.length();
if (len % 2 != 0)
@ -35,7 +35,7 @@ public class Hex {
return out;
}
public static String toString(byte[] data) {
public static String encode(byte[] data) {
StringBuilder r = new StringBuilder(data.length * 2);
for (byte b : data) {
r.append(hexCode[(b >> 4) & 0xF]);

Loading…
Cancel
Save