зеркало из https://github.com/mozilla/gecko-dev.git
Bug 888086 - Use StringBuilder in sync/Utils.java r=rnewman
This commit is contained in:
Родитель
9926ce4162
Коммит
af3879dde7
|
@ -210,7 +210,7 @@ public class CryptoRecord extends Record {
|
|||
CryptoInfo info = CryptoInfo.encrypt(cleartextBytes, keyBundle);
|
||||
String message = new String(Base64.encodeBase64(info.getMessage()));
|
||||
String iv = new String(Base64.encodeBase64(info.getIV()));
|
||||
String hmac = Utils.byte2hex(info.getHMAC());
|
||||
String hmac = Utils.byte2Hex(info.getHMAC());
|
||||
ExtendedJSONObject ciphertext = new ExtendedJSONObject();
|
||||
ciphertext.put(KEY_CIPHERTEXT, message);
|
||||
ciphertext.put(KEY_HMAC, hmac);
|
||||
|
|
|
@ -82,26 +82,20 @@ public class Utils {
|
|||
/**
|
||||
* Helper to convert a byte array to a hex-encoded string
|
||||
*/
|
||||
public static String byte2hex(byte[] b) {
|
||||
// StringBuffer should be used instead.
|
||||
String hs = "";
|
||||
public static String byte2Hex(final byte[] b) {
|
||||
final StringBuilder hs = new StringBuilder(b.length * 2);
|
||||
String stmp;
|
||||
|
||||
for (int n = 0; n < b.length; n++) {
|
||||
stmp = java.lang.Integer.toHexString(b[n] & 0XFF);
|
||||
stmp = Integer.toHexString(b[n] & 0XFF);
|
||||
|
||||
if (stmp.length() == 1) {
|
||||
hs = hs + "0" + stmp;
|
||||
} else {
|
||||
hs = hs + stmp;
|
||||
}
|
||||
|
||||
if (n < b.length - 1) {
|
||||
hs = hs + "";
|
||||
hs.append("0");
|
||||
}
|
||||
hs.append(stmp);
|
||||
}
|
||||
|
||||
return hs;
|
||||
return hs.toString();
|
||||
}
|
||||
|
||||
public static byte[] concatAll(byte[] first, byte[]... rest) {
|
||||
|
@ -536,4 +530,4 @@ public class Utils {
|
|||
public static String obfuscateEmail(final String in) {
|
||||
return in.replaceAll("[^@\\.]", "X");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -308,7 +308,7 @@ public class JPakeClient {
|
|||
payload.put(Constants.JSON_KEY_CIPHERTEXT, message64);
|
||||
payload.put(Constants.JSON_KEY_IV, iv64);
|
||||
if (makeHmac) {
|
||||
String hmacHex = Utils.byte2hex(encrypted.getHMAC());
|
||||
String hmacHex = Utils.byte2Hex(encrypted.getHMAC());
|
||||
payload.put(Constants.JSON_KEY_HMAC, hmacHex);
|
||||
}
|
||||
return payload;
|
||||
|
|
Загрузка…
Ссылка в новой задаче