Bug 1290014 - DiskStorage: Do not use StandardCharsets.UTF_8. It's only support on API level 19+. r=ahunt

MozReview-Commit-ID: 5wvR4dgiPoJ

--HG--
extra : rebase_source : 863ca9ca14eb7647d2dac314fe4b45deb87da0e6
This commit is contained in:
Sebastian Kaspari 2016-08-18 18:15:15 +02:00
parent daaeb912aa
commit 95fd11b02c

View File

@ -24,7 +24,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
/**
@ -256,10 +256,10 @@ public class DiskStorage {
return null;
}
byte[] data = prefix.getBytes(StandardCharsets.UTF_8);
byte[] data = prefix.getBytes("UTF-8");
NativeCrypto.sha256update(ctx, data, data.length);
data = url.getBytes(StandardCharsets.UTF_8);
data = url.getBytes("UTF-8");
NativeCrypto.sha256update(ctx, data, data.length);
return Utils.byte2Hex(NativeCrypto.sha256finalize(ctx));
} catch (NoClassDefFoundError | ExceptionInInitializerError error) {
@ -268,13 +268,15 @@ public class DiskStorage {
// we will have a lot of other problems if we can't load libmozglue.so
try {
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(prefix.getBytes(StandardCharsets.UTF_8));
md.update(url.getBytes(StandardCharsets.UTF_8));
md.update(prefix.getBytes("UTF-8"));
md.update(url.getBytes("UTF-8"));
return Utils.byte2Hex(md.digest());
} catch (Exception e) {
// Just give up. And let everyone know.
throw new RuntimeException(e);
}
} catch (UnsupportedEncodingException e) {
throw new AssertionError("Should not happen: Device does not understand UTF-8");
}
}