Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1653b1dd authored by Narayan Kamath's avatar Narayan Kamath
Browse files

Throw IllegalArgumentException on invalid hex-strings.

Beats returning null since there's let's chance it will be interpreted
as the lack of a password.

Change-Id: I4986a8e806d9066129f696ab9f2e80655424e723
parent 78108a3e
Loading
Loading
Loading
Loading
+3 −9
Original line number Diff line number Diff line
@@ -2155,7 +2155,7 @@ class MountService extends IMountService.Stub
        }
    }

    private String toHex(String password) {
    private static String toHex(String password) {
        if (password == null) {
            return "";
        }
@@ -2163,18 +2163,12 @@ class MountService extends IMountService.Stub
        return new String(HexEncoding.encode(bytes));
    }

    private String fromHex(String hexPassword) {
    private static String fromHex(String hexPassword) throws IllegalArgumentException {
        if (hexPassword == null) {
            return null;
        }

        final byte[] bytes;
        try {
            bytes = HexEncoding.decode(hexPassword.toCharArray(), false);
        } catch (IllegalArgumentException e) {
            return null;
        }

        final byte[] bytes = HexEncoding.decode(hexPassword.toCharArray(), false);
        return new String(bytes, StandardCharsets.UTF_8);
    }