{{% if pkg_version %}}
{{# If pkg_version isn't defined, then the rule should be NOTCHECKED, because we don't have data needed for the check #}}
<def-group>
  <definition class="compliance" id="ensure_oracle_gpgkey_installed" version="1">
    {{{ oval_metadata("The Oracle Linux key packages are required to be installed.") }}}
    <criteria comment="Oracle Vendor Keys" operator="AND">
      <criteria comment="Oracle Installed" operator="OR">
        <extend_definition comment="{{{ product }}} installed" definition_ref="installed_OS_is_{{{ product }}}" />
      </criteria>
      <criteria comment="Oracle Vendor Keys Installed" operator="OR">
        <criterion comment="package gpg-pubkey-{{{ pkg_version }}}-{{{ pkg_release }}} is installed"
            test_ref="test_oracle_package_gpgkey-{{{ pkg_version }}}-{{{ pkg_release }}}_installed" />
        {{% if aux_pkg_version %}}
        <criterion comment="package gpg-pubkey-{{{ aux_pkg_version }}}-{{{ aux_pkg_release }}} is installed"
            test_ref="test_oracle_package_gpgkey-{{{ aux_pkg_version }}}-{{{ aux_pkg_release }}}_installed" />
        {{% endif %}}
      </criteria>
    </criteria>
  </definition>

  <!-- First define global "object_oracle_package_gpg-pubkey" to be shared (reused) across multiple tests -->
  <linux:rpminfo_object id="object_oracle_package_gpg-pubkey" version="1">
    <linux:name>gpg-pubkey</linux:name>
  </linux:rpminfo_object>

  <!-- Test for Oracle release key -->
  <linux:rpminfo_test check="only one" check_existence="at_least_one_exists"
      id="test_oracle_package_gpgkey-{{{ pkg_version }}}-{{{ pkg_release }}}_installed" version="1"
      comment="Oracle release key package is installed">
    <linux:object object_ref="object_oracle_package_gpg-pubkey" />
    <linux:state state_ref="state_oracle_package_gpg-pubkey-{{{ pkg_version }}}-{{{ pkg_release }}}" />
  </linux:rpminfo_test>

  <linux:rpminfo_state id="state_oracle_package_gpg-pubkey-{{{ pkg_version }}}-{{{ pkg_release }}}" version="1">
    <linux:release>{{{ pkg_release }}}</linux:release>
    <linux:version>{{{ pkg_version }}}</linux:version>
  </linux:rpminfo_state>

  <!-- Test for Oracle auxiliary key -->
  {{% if aux_pkg_version %}}
  <linux:rpminfo_test check="only one" check_existence="at_least_one_exists"
  id="test_oracle_package_gpgkey-{{{ aux_pkg_version }}}-{{{ aux_pkg_release }}}_installed" version="1"
  comment="Oracle auxiliary key package is installed">
    <linux:object object_ref="object_oracle_package_gpg-pubkey" />
    <linux:state state_ref="state_oracle_package_gpg-pubkey-{{{ aux_pkg_version }}}-{{{ aux_pkg_release }}}" />
  </linux:rpminfo_test>

  <linux:rpminfo_state id="state_oracle_package_gpg-pubkey-{{{ aux_pkg_version }}}-{{{ aux_pkg_release }}}" version="1">
    <linux:release>{{{ aux_pkg_release }}}</linux:release>
    <linux:version>{{{ aux_pkg_version }}}</linux:version>
  </linux:rpminfo_state>
  {{% endif %}}

</def-group>
{{% endif %}}
