Loading core/java/android/content/integrity/AtomicFormula.java +10 −4 Original line number Diff line number Diff line Loading @@ -332,9 +332,12 @@ public abstract class AtomicFormula extends IntegrityFormula { * Constructs a new {@link StringAtomicFormula} together with handling the necessary * hashing for the given key. * * <p> The value will be hashed with SHA256 and the hex digest will be computed; for * all cases except when the key is PACKAGE_NAME or INSTALLER_NAME and the value * is less than 33 characters. * <p> The value will be automatically hashed with SHA256 and the hex digest will be * computed when the key is PACKAGE_NAME or INSTALLER_NAME and the value is more than 32 * characters. * * <p> The APP_CERTIFICATES and INSTALLER_CERTIFICATES are always delivered in hashed * form. So the isHashedValue is set to true by default. * * @throws IllegalArgumentException if {@code key} cannot be used with string value. */ Loading @@ -348,7 +351,10 @@ public abstract class AtomicFormula extends IntegrityFormula { String.format( "Key %s cannot be used with StringAtomicFormula", keyToString(key))); mValue = hashValue(key, value); mIsHashedValue = !mValue.equals(value); mIsHashedValue = key == APP_CERTIFICATE || key == INSTALLER_CERTIFICATE ? true : !mValue.equals(value); } StringAtomicFormula(Parcel in) { Loading core/tests/coretests/src/android/content/integrity/AtomicFormulaTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -97,7 +97,7 @@ public class AtomicFormulaTest { assertThat(stringAtomicFormula.getKey()).isEqualTo(AtomicFormula.APP_CERTIFICATE); assertThat(stringAtomicFormula.getValue()).matches(appCert); assertThat(stringAtomicFormula.getIsHashedValue()).isFalse(); assertThat(stringAtomicFormula.getIsHashedValue()).isTrue(); } @Test Loading @@ -110,7 +110,7 @@ public class AtomicFormulaTest { assertThat(stringAtomicFormula.getKey()).isEqualTo( AtomicFormula.INSTALLER_CERTIFICATE); assertThat(stringAtomicFormula.getValue()).matches(installerCert); assertThat(stringAtomicFormula.getIsHashedValue()).isFalse(); assertThat(stringAtomicFormula.getIsHashedValue()).isTrue(); } @Test Loading core/tests/coretests/src/android/content/integrity/IntegrityFormulaTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -54,7 +54,7 @@ public class IntegrityFormulaTest { assertThat(stringAtomicFormula.getKey()).isEqualTo(AtomicFormula.APP_CERTIFICATE); assertThat(stringAtomicFormula.getValue()).matches(appCertificate); assertThat(stringAtomicFormula.getIsHashedValue()).isFalse(); assertThat(stringAtomicFormula.getIsHashedValue()).isTrue(); } @Test Loading Loading @@ -82,7 +82,7 @@ public class IntegrityFormulaTest { assertThat(stringAtomicFormula.getKey()).isEqualTo(AtomicFormula.INSTALLER_CERTIFICATE); assertThat(stringAtomicFormula.getValue()).matches(installerCertificate); assertThat(stringAtomicFormula.getIsHashedValue()).isFalse(); assertThat(stringAtomicFormula.getIsHashedValue()).isTrue(); } @Test Loading Loading
core/java/android/content/integrity/AtomicFormula.java +10 −4 Original line number Diff line number Diff line Loading @@ -332,9 +332,12 @@ public abstract class AtomicFormula extends IntegrityFormula { * Constructs a new {@link StringAtomicFormula} together with handling the necessary * hashing for the given key. * * <p> The value will be hashed with SHA256 and the hex digest will be computed; for * all cases except when the key is PACKAGE_NAME or INSTALLER_NAME and the value * is less than 33 characters. * <p> The value will be automatically hashed with SHA256 and the hex digest will be * computed when the key is PACKAGE_NAME or INSTALLER_NAME and the value is more than 32 * characters. * * <p> The APP_CERTIFICATES and INSTALLER_CERTIFICATES are always delivered in hashed * form. So the isHashedValue is set to true by default. * * @throws IllegalArgumentException if {@code key} cannot be used with string value. */ Loading @@ -348,7 +351,10 @@ public abstract class AtomicFormula extends IntegrityFormula { String.format( "Key %s cannot be used with StringAtomicFormula", keyToString(key))); mValue = hashValue(key, value); mIsHashedValue = !mValue.equals(value); mIsHashedValue = key == APP_CERTIFICATE || key == INSTALLER_CERTIFICATE ? true : !mValue.equals(value); } StringAtomicFormula(Parcel in) { Loading
core/tests/coretests/src/android/content/integrity/AtomicFormulaTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -97,7 +97,7 @@ public class AtomicFormulaTest { assertThat(stringAtomicFormula.getKey()).isEqualTo(AtomicFormula.APP_CERTIFICATE); assertThat(stringAtomicFormula.getValue()).matches(appCert); assertThat(stringAtomicFormula.getIsHashedValue()).isFalse(); assertThat(stringAtomicFormula.getIsHashedValue()).isTrue(); } @Test Loading @@ -110,7 +110,7 @@ public class AtomicFormulaTest { assertThat(stringAtomicFormula.getKey()).isEqualTo( AtomicFormula.INSTALLER_CERTIFICATE); assertThat(stringAtomicFormula.getValue()).matches(installerCert); assertThat(stringAtomicFormula.getIsHashedValue()).isFalse(); assertThat(stringAtomicFormula.getIsHashedValue()).isTrue(); } @Test Loading
core/tests/coretests/src/android/content/integrity/IntegrityFormulaTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -54,7 +54,7 @@ public class IntegrityFormulaTest { assertThat(stringAtomicFormula.getKey()).isEqualTo(AtomicFormula.APP_CERTIFICATE); assertThat(stringAtomicFormula.getValue()).matches(appCertificate); assertThat(stringAtomicFormula.getIsHashedValue()).isFalse(); assertThat(stringAtomicFormula.getIsHashedValue()).isTrue(); } @Test Loading Loading @@ -82,7 +82,7 @@ public class IntegrityFormulaTest { assertThat(stringAtomicFormula.getKey()).isEqualTo(AtomicFormula.INSTALLER_CERTIFICATE); assertThat(stringAtomicFormula.getValue()).matches(installerCertificate); assertThat(stringAtomicFormula.getIsHashedValue()).isFalse(); assertThat(stringAtomicFormula.getIsHashedValue()).isTrue(); } @Test Loading