Loading services/core/java/com/android/server/locksettings/LockSettingsStorage.java +0 −38 Original line number Diff line number Diff line Loading @@ -95,8 +95,6 @@ class LockSettingsStorage { @VisibleForTesting public static class CredentialHash { /** Deprecated private static final int VERSION_LEGACY = 0; */ private static final int VERSION_GATEKEEPER = 1; private CredentialHash(byte[] hash, @CredentialType int type) { if (type != LockPatternUtils.CREDENTIAL_TYPE_NONE) { Loading Loading @@ -126,42 +124,6 @@ class LockSettingsStorage { byte[] hash; @CredentialType int type; public byte[] toBytes() { try { ByteArrayOutputStream os = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(os); dos.write(VERSION_GATEKEEPER); dos.write(type); if (hash != null && hash.length > 0) { dos.writeInt(hash.length); dos.write(hash); } else { dos.writeInt(0); } dos.close(); return os.toByteArray(); } catch (IOException e) { throw new IllegalStateException("Fail to serialze credential hash", e); } } public static CredentialHash fromBytes(byte[] bytes) { try { DataInputStream is = new DataInputStream(new ByteArrayInputStream(bytes)); /* int version = */ is.read(); int type = is.read(); int hashSize = is.readInt(); byte[] hash = null; if (hashSize > 0) { hash = new byte[hashSize]; is.readFully(hash); } return new CredentialHash(hash, type); } catch (IOException e) { throw new IllegalStateException("Fail to deserialze credential hash", e); } } } public LockSettingsStorage(Context context) { Loading services/tests/servicestests/src/com/android/server/locksettings/LockSettingsStorageTests.java +0 −29 Original line number Diff line number Diff line Loading @@ -434,35 +434,6 @@ public class LockSettingsStorageTests extends AndroidTestCase { assertEquals(2, PersistentData.TYPE_SP_WEAVER); } public void testCredentialHash_serializeUnserialize() { byte[] serialized = CredentialHash.create( PAYLOAD, LockPatternUtils.CREDENTIAL_TYPE_PASSWORD).toBytes(); CredentialHash deserialized = CredentialHash.fromBytes(serialized); assertEquals(LockPatternUtils.CREDENTIAL_TYPE_PASSWORD, deserialized.type); assertArrayEquals(PAYLOAD, deserialized.hash); } public void testCredentialHash_unserialize_versionGatekeeper() { // This test ensures that we can read serialized VERSION_GATEKEEPER CredentialHashes // even if we change the wire format in the future. byte[] serialized = new byte[] { 1, /* VERSION_GATEKEEPER */ 2, /* CREDENTIAL_TYPE_PASSWORD */ 0, 0, 0, 5, /* hash length */ 1, 2, -1, -2, 33, /* hash */ }; CredentialHash deserialized = CredentialHash.fromBytes(serialized); assertEquals(LockPatternUtils.CREDENTIAL_TYPE_PASSWORD, deserialized.type); assertArrayEquals(PAYLOAD, deserialized.hash); // Make sure the constants we use on the wire do not change. assertEquals(-1, LockPatternUtils.CREDENTIAL_TYPE_NONE); assertEquals(1, LockPatternUtils.CREDENTIAL_TYPE_PATTERN); assertEquals(2, LockPatternUtils.CREDENTIAL_TYPE_PASSWORD); } private static void assertArrayEquals(byte[] expected, byte[] actual) { if (!Arrays.equals(expected, actual)) { fail("expected:<" + Arrays.toString(expected) + Loading Loading
services/core/java/com/android/server/locksettings/LockSettingsStorage.java +0 −38 Original line number Diff line number Diff line Loading @@ -95,8 +95,6 @@ class LockSettingsStorage { @VisibleForTesting public static class CredentialHash { /** Deprecated private static final int VERSION_LEGACY = 0; */ private static final int VERSION_GATEKEEPER = 1; private CredentialHash(byte[] hash, @CredentialType int type) { if (type != LockPatternUtils.CREDENTIAL_TYPE_NONE) { Loading Loading @@ -126,42 +124,6 @@ class LockSettingsStorage { byte[] hash; @CredentialType int type; public byte[] toBytes() { try { ByteArrayOutputStream os = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(os); dos.write(VERSION_GATEKEEPER); dos.write(type); if (hash != null && hash.length > 0) { dos.writeInt(hash.length); dos.write(hash); } else { dos.writeInt(0); } dos.close(); return os.toByteArray(); } catch (IOException e) { throw new IllegalStateException("Fail to serialze credential hash", e); } } public static CredentialHash fromBytes(byte[] bytes) { try { DataInputStream is = new DataInputStream(new ByteArrayInputStream(bytes)); /* int version = */ is.read(); int type = is.read(); int hashSize = is.readInt(); byte[] hash = null; if (hashSize > 0) { hash = new byte[hashSize]; is.readFully(hash); } return new CredentialHash(hash, type); } catch (IOException e) { throw new IllegalStateException("Fail to deserialze credential hash", e); } } } public LockSettingsStorage(Context context) { Loading
services/tests/servicestests/src/com/android/server/locksettings/LockSettingsStorageTests.java +0 −29 Original line number Diff line number Diff line Loading @@ -434,35 +434,6 @@ public class LockSettingsStorageTests extends AndroidTestCase { assertEquals(2, PersistentData.TYPE_SP_WEAVER); } public void testCredentialHash_serializeUnserialize() { byte[] serialized = CredentialHash.create( PAYLOAD, LockPatternUtils.CREDENTIAL_TYPE_PASSWORD).toBytes(); CredentialHash deserialized = CredentialHash.fromBytes(serialized); assertEquals(LockPatternUtils.CREDENTIAL_TYPE_PASSWORD, deserialized.type); assertArrayEquals(PAYLOAD, deserialized.hash); } public void testCredentialHash_unserialize_versionGatekeeper() { // This test ensures that we can read serialized VERSION_GATEKEEPER CredentialHashes // even if we change the wire format in the future. byte[] serialized = new byte[] { 1, /* VERSION_GATEKEEPER */ 2, /* CREDENTIAL_TYPE_PASSWORD */ 0, 0, 0, 5, /* hash length */ 1, 2, -1, -2, 33, /* hash */ }; CredentialHash deserialized = CredentialHash.fromBytes(serialized); assertEquals(LockPatternUtils.CREDENTIAL_TYPE_PASSWORD, deserialized.type); assertArrayEquals(PAYLOAD, deserialized.hash); // Make sure the constants we use on the wire do not change. assertEquals(-1, LockPatternUtils.CREDENTIAL_TYPE_NONE); assertEquals(1, LockPatternUtils.CREDENTIAL_TYPE_PATTERN); assertEquals(2, LockPatternUtils.CREDENTIAL_TYPE_PASSWORD); } private static void assertArrayEquals(byte[] expected, byte[] actual) { if (!Arrays.equals(expected, actual)) { fail("expected:<" + Arrays.toString(expected) + Loading