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

Commit 8ce84699 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Move KeyParameter operator== to support lib."

parents d05e4b31 25692982
Loading
Loading
Loading
Loading
+86 −0
Original line number Diff line number Diff line
@@ -329,6 +329,92 @@ inline NullOr<const typename TypedTag2ValueType<TypedTag<tag_type, tag>>::type&>
    return accessTagValue(ttag, param);
}

inline bool operator==(const KeyParameter& a, const KeyParameter& b) {
    if (a.tag != b.tag) {
        return false;
    }

    switch (a.tag) {
        /* Boolean tags */
        case Tag::INVALID:
        case Tag::CALLER_NONCE:
        case Tag::INCLUDE_UNIQUE_ID:
        case Tag::BOOTLOADER_ONLY:
        case Tag::NO_AUTH_REQUIRED:
        case Tag::ALLOW_WHILE_ON_BODY:
        case Tag::ROLLBACK_RESISTANCE:
        case Tag::RESET_SINCE_ID_ROTATION:
        case Tag::TRUSTED_USER_PRESENCE_REQUIRED:
            return true;

        /* Integer tags */
        case Tag::KEY_SIZE:
        case Tag::MIN_MAC_LENGTH:
        case Tag::MIN_SECONDS_BETWEEN_OPS:
        case Tag::MAX_USES_PER_BOOT:
        case Tag::OS_VERSION:
        case Tag::OS_PATCHLEVEL:
        case Tag::MAC_LENGTH:
        case Tag::AUTH_TIMEOUT:
            return a.f.integer == b.f.integer;

        /* Long integer tags */
        case Tag::RSA_PUBLIC_EXPONENT:
        case Tag::USER_SECURE_ID:
            return a.f.longInteger == b.f.longInteger;

        /* Date-time tags */
        case Tag::ACTIVE_DATETIME:
        case Tag::ORIGINATION_EXPIRE_DATETIME:
        case Tag::USAGE_EXPIRE_DATETIME:
        case Tag::CREATION_DATETIME:
            return a.f.dateTime == b.f.dateTime;

        /* Bytes tags */
        case Tag::APPLICATION_ID:
        case Tag::APPLICATION_DATA:
        case Tag::ROOT_OF_TRUST:
        case Tag::UNIQUE_ID:
        case Tag::ATTESTATION_CHALLENGE:
        case Tag::ATTESTATION_APPLICATION_ID:
        case Tag::ATTESTATION_ID_BRAND:
        case Tag::ATTESTATION_ID_DEVICE:
        case Tag::ATTESTATION_ID_PRODUCT:
        case Tag::ATTESTATION_ID_SERIAL:
        case Tag::ATTESTATION_ID_IMEI:
        case Tag::ATTESTATION_ID_MEID:
        case Tag::ATTESTATION_ID_MANUFACTURER:
        case Tag::ATTESTATION_ID_MODEL:
        case Tag::ASSOCIATED_DATA:
        case Tag::NONCE:
            return a.blob == b.blob;

        /* Enum tags */
        case Tag::PURPOSE:
            return a.f.purpose == b.f.purpose;
        case Tag::ALGORITHM:
            return a.f.algorithm == b.f.algorithm;
        case Tag::BLOCK_MODE:
            return a.f.blockMode == b.f.blockMode;
        case Tag::DIGEST:
            return a.f.digest == b.f.digest;
        case Tag::PADDING:
            return a.f.paddingMode == b.f.paddingMode;
        case Tag::EC_CURVE:
            return a.f.ecCurve == b.f.ecCurve;
        case Tag::BLOB_USAGE_REQUIREMENTS:
            return a.f.keyBlobUsageRequirements == b.f.keyBlobUsageRequirements;
        case Tag::USER_AUTH_TYPE:
            return a.f.integer == b.f.integer;
        case Tag::ORIGIN:
            return a.f.origin == b.f.origin;
        case Tag::HARDWARE_TYPE:
            return a.f.hardwareType == b.f.hardwareType;
    }

    return false;
}

}  // namespace V4_0
}  // namespace keymaster
}  // namespace hardware
+0 −86
Original line number Diff line number Diff line
@@ -52,92 +52,6 @@ bool operator==(const hidl_vec<T>& a, const hidl_vec<T>& b) {
namespace keymaster {
namespace V4_0 {

bool operator==(const KeyParameter& a, const KeyParameter& b) {
    if (a.tag != b.tag) {
        return false;
    }

    switch (a.tag) {
        /* Boolean tags */
        case Tag::INVALID:
        case Tag::CALLER_NONCE:
        case Tag::INCLUDE_UNIQUE_ID:
        case Tag::BOOTLOADER_ONLY:
        case Tag::NO_AUTH_REQUIRED:
        case Tag::ALLOW_WHILE_ON_BODY:
        case Tag::ROLLBACK_RESISTANCE:
        case Tag::RESET_SINCE_ID_ROTATION:
        case Tag::TRUSTED_USER_PRESENCE_REQUIRED:
            return true;

        /* Integer tags */
        case Tag::KEY_SIZE:
        case Tag::MIN_MAC_LENGTH:
        case Tag::MIN_SECONDS_BETWEEN_OPS:
        case Tag::MAX_USES_PER_BOOT:
        case Tag::OS_VERSION:
        case Tag::OS_PATCHLEVEL:
        case Tag::MAC_LENGTH:
        case Tag::AUTH_TIMEOUT:
            return a.f.integer == b.f.integer;

        /* Long integer tags */
        case Tag::RSA_PUBLIC_EXPONENT:
        case Tag::USER_SECURE_ID:
            return a.f.longInteger == b.f.longInteger;

        /* Date-time tags */
        case Tag::ACTIVE_DATETIME:
        case Tag::ORIGINATION_EXPIRE_DATETIME:
        case Tag::USAGE_EXPIRE_DATETIME:
        case Tag::CREATION_DATETIME:
            return a.f.dateTime == b.f.dateTime;

        /* Bytes tags */
        case Tag::APPLICATION_ID:
        case Tag::APPLICATION_DATA:
        case Tag::ROOT_OF_TRUST:
        case Tag::UNIQUE_ID:
        case Tag::ATTESTATION_CHALLENGE:
        case Tag::ATTESTATION_APPLICATION_ID:
        case Tag::ATTESTATION_ID_BRAND:
        case Tag::ATTESTATION_ID_DEVICE:
        case Tag::ATTESTATION_ID_PRODUCT:
        case Tag::ATTESTATION_ID_SERIAL:
        case Tag::ATTESTATION_ID_IMEI:
        case Tag::ATTESTATION_ID_MEID:
        case Tag::ATTESTATION_ID_MANUFACTURER:
        case Tag::ATTESTATION_ID_MODEL:
        case Tag::ASSOCIATED_DATA:
        case Tag::NONCE:
            return a.blob == b.blob;

        /* Enum tags */
        case Tag::PURPOSE:
            return a.f.purpose == b.f.purpose;
        case Tag::ALGORITHM:
            return a.f.algorithm == b.f.algorithm;
        case Tag::BLOCK_MODE:
            return a.f.blockMode == b.f.blockMode;
        case Tag::DIGEST:
            return a.f.digest == b.f.digest;
        case Tag::PADDING:
            return a.f.paddingMode == b.f.paddingMode;
        case Tag::EC_CURVE:
            return a.f.ecCurve == b.f.ecCurve;
        case Tag::BLOB_USAGE_REQUIREMENTS:
            return a.f.keyBlobUsageRequirements == b.f.keyBlobUsageRequirements;
        case Tag::USER_AUTH_TYPE:
            return a.f.integer == b.f.integer;
        case Tag::ORIGIN:
            return a.f.origin == b.f.origin;
        case Tag::HARDWARE_TYPE:
            return a.f.hardwareType == b.f.hardwareType;
    }

    return false;
}

bool operator==(const AuthorizationSet& a, const AuthorizationSet& b) {
    return a.size() == b.size() && std::equal(a.begin(), a.end(), b.begin());
}