  <article>
    {% match advisory.metadata.collection %}
    {% when Some with (collection) %}
        <span class="floating-menu">
          <a href="https://github.com/RustSec/advisory-db/commits/main/{{ collection }}/{{ advisory.metadata.package }}/{{ advisory.id() }}.md">History</a> ⋅ 
          <a href="https://github.com/RustSec/advisory-db/edit/main/{{ collection }}/{{ advisory.metadata.package }}/{{ advisory.id() }}.md">Edit</a> ⋅
          <a href="https://api.osv.dev/v1/vulns/{{ advisory.id() }}">JSON (OSV)</a>
        </span>
    {% when None %}
    {% endmatch %}

    <header>
      <h1>
        {% if advisory.withdrawn() %}
        <span class="withdrawn">{{ advisory.id() }}</span>
        {% else %}
        {{ advisory.id() }}
        {% endif %}
      </h1>
      <span class="subtitle">{{ rendered_title|safe }}</span>
    </header>

    {% if advisory.withdrawn() %}
    <hr>
    <p class="warning">This advisory has been withdrawn and should be ignored. It is kept only for reference.</p>
    <hr>
    {% endif %}

    <dl>
      <dt id="reported">Reported</dt>
      <dd>
        <time datetime="{{ advisory.date().as_str() }}">
          {{ advisory.date()|friendly_date }}
        </time>
      </dd>

      <dt id="issued">Issued</dt>
      <dd>
        <time datetime="{{ cdate.as_str() }}">
          {{ cdate.clone()|friendly_date }}
        </time>
        {% if cdate != mdate %}
        <time datetime="{{ mdate.as_str() }}">
          (last modified: {{ mdate.clone()|friendly_date }})
        </time>
        {% endif %}
      </dd>

      <dt id="package">Package</dt>
      <dd>
        {% match advisory.metadata.collection %}
        {% when Some with (collection) %}
        {% if collection.to_string() == "crates" %}
        <a href="/packages/{{ advisory.metadata.package }}.html">{{ advisory.metadata.package }}</a>
          (<a href="https://crates.io/crates/{{ advisory.metadata.package }}">crates.io</a>)
        {% else %}
        <code><a href="/packages/{{ advisory.metadata.package }}.html">{{ advisory.metadata.package }}</a></code>
        {% endif %}
        {% when None %}
        <code><a href="/packages/{{ advisory.metadata.package }}.html">{{ advisory.metadata.package }}</a></code>
        {% endmatch %}
      </dd>

      <dt id="type">Type</dt>
      <dd>
        {% match advisory.metadata.informational %}
        {% when Some with (informational) %}
        <span class="tag info">INFO</span>
        {{ informational.to_string()|capitalize }}
        {% when None %}
        Vulnerability
        {% endmatch %}
      </dd>

      {% if advisory.metadata.categories.len() > 0 %}
      <dt id="categories">Categories</dt>
      <dd>
        <ul>
          {% for category in advisory.metadata.categories %}
          <li><a href="/categories/{{ category.to_string() }}.html">{{ category.to_string() }}</a></li>
          {% endfor %}
        </ul>
      </dd>
      {% endif %}

      {% if advisory.metadata.keywords.len() > 0 %}
      <dt id="keywords">Keywords</dt>
      <dd>
        {% for keyword in advisory.metadata.keywords %}
          <a href="/keywords/{{ keyword.as_str()|safe_keyword }}.html">#{{ keyword.as_str()|safe_keyword }}</a>
        {% endfor %}
      </dd>
      {% endif %}

      {% if advisory.metadata.aliases.len() > 0 %}
      <dt id="aliases">Aliases</dt>
      <dd>
        <ul>
          {% for id in advisory.metadata.aliases %}
          <li>
            {% match id.url() %}
            {% when Some with (url) %}
            <a href="{{ url }}">{{ id }}</a>
            {% when None %}
            {{ id }}
            {% endmatch %}
          </li>
          {% endfor %}
        </ul>
      </dd>
      {% endif %}

      {% if advisory.metadata.url.is_some() || !advisory.metadata.references.is_empty() %}
      <dt id="details">References</dt>
      <dd>
        <ul>
        {% if advisory.metadata.url.is_some() %}
          <li>
            <a href="{{ advisory.metadata.url.as_ref().unwrap() }}">
              {{ advisory.metadata.url.as_ref().unwrap() }}
            </a>
          </li>
        {% endif %}
        {% for reference in advisory.metadata.references %}
          <li>
            <a href="{{ reference }}">
              {{ reference }}
            </a>
          </li>
        {% endfor %}
        </ul>
      </dd>
      {% endif %}

      {% if advisory.metadata.related.len() > 0 %}
      <dt id="related">Related</dt>
      <dd>
        <ul>
          {% for id in advisory.metadata.related %}
          <li>
            {% match id.url() %}
            {% when Some with (url) %}
            <a href="{{ url }}">{{ id }}</a>
            {% when None %}
            {{ id }}
            {% endmatch %}
          </li>
          {% endfor %}
        </ul>
      </dd>
      {% endif %}

      {% match advisory.metadata.cvss %}
      {% when Some with (cvss) %}
      <dt id="cvss_score">CVSS Score</dt>
      <dd>{{ cvss.score().value() }} <span class="tag {{ advisory.severity().unwrap() }}">
        {{ advisory.severity().unwrap()|upper }}
      </span></dd>

      <dt id="cvss_details">CVSS Details</dt>
      <dd>
        <dl>
          {% match cvss.av %}
          {% when Some with (av) %}
          <dt>Attack vector</dt><dd>{{ "{:?}"|format(av) }}</dd>
          {% when None %}
          {% endmatch %}

          {% match cvss.ac %}
          {% when Some with (ac) %}
          <dt>Attack complexity</dt><dd>{{ "{:?}"|format(ac) }}</dd>
          {% when None %}
          {% endmatch %}

          {% match cvss.pr %}
          {% when Some with (pr) %}
          <dt>Privileges required</dt><dd>{{ "{:?}"|format(pr) }}</dd>
          {% when None %}
          {% endmatch %}

          {% match cvss.ui %}
          {% when Some with (ui) %}
          <dt>User interaction</dt><dd>{{ "{:?}"|format(ui) }}</dd>
          {% when None %}
          {% endmatch %}

          {% match cvss.s %}
          {% when Some with (s) %}
          <dt>Scope</dt><dd>{{ "{:?}"|format(s) }}</dd>
          {% when None %}
          {% endmatch %}

          {% match cvss.c %}
          {% when Some with (c) %}
          <dt>Confidentiality</dt><dd>{{ "{:?}"|format(c) }}</dd>
          {% when None %}
          {% endmatch %}

          {% match cvss.i %}
          {% when Some with (i) %}
          <dt>Integrity</dt><dd>{{ "{:?}"|format(i) }}</dd>
          {% when None %}
          {% endmatch %}

          {% match cvss.a %}
          {% when Some with (a) %}
          <dt>Availability</dt><dd>{{ "{:?}"|format(a) }}</dd>
          {% when None %}
          {% endmatch %}
        </dl>
      </dd>

      <dt id="cvss">CVSS Vector</dt>

      {% if cvss.to_string().starts_with("CVSS:3.1/") %}
      <dd><a href="https://www.first.org/cvss/calculator/3.1#{{ cvss }}">{{ cvss }}</a></dd>
      {% else if cvss.to_string().starts_with("CVSS:3.0/") %}
      <dd><a href="https://www.first.org/cvss/calculator/3.0#{{ cvss }}">{{ cvss }}</a></dd>
      {% else %}
      <dd>{{ cvss }}</dd>
      {% endif %}

      {% when None %}
      {% endmatch %}

      <dt id="patched">Patched</dt>
      <dd>
        {% if advisory.versions.patched().len() == 0 %}
        no patched versions
        {% else %}
        <ul>
          {% for patched in advisory.versions.patched() %}
          <li><code>{{ patched }}</code></li>
          {% endfor %}
        </ul>
        {% endif %}
      </dd>

      {% if advisory.versions.unaffected().len() > 0 %}
      <dt id="unaffected">Unaffected</dt>
      <dd>
        <ul>
          {% for unaffected in advisory.versions.unaffected() %}
          <li><code>{{ unaffected }}</code></li>
          {% endfor %}
        </ul>
      </dd>
      {% endif %}

      {% match advisory.affected %}
      {% when Some with (affected) %}
      {% if affected.arch.len() > 0 %}
      <dt>Affected Architectures</dt>
      <dd>
        <ul>
          {% for arch in affected.arch %}
          <li><code>{{ arch }}</code></li>
          {% endfor %}
        </ul>
      </dd>
      {% endif %}

      {% if affected.os.len() > 0 %}
      <dt>Affected OSes</dt>
      <dd>
        <ul>
          {% for os in affected.os %}
          <li><code>{{ os }}</code></li>
          {% endfor %}
        </ul>
      </dd>
      {% endif %}
      {% when None %}
      {% endmatch %}
    </dl>

    {% match advisory.affected %}
    {% when Some with (affected) %}
    {% if affected.functions.len() > 0 %}
    <dl>
      <dt>Affected Functions</dt>
      <dd>Version</dd>
      {% for function in affected.functions %}
      <dt><code>{{ function.0 }}</code></dt>
      <dd>
        <ul>
          {% for version_req in function.1 %}
          <li><code>{{ version_req }}</code></li>
          {% endfor %}
        </ul>
      </dd>
      {% endfor %}
    </dl>
    {% endif %}

    {% when None %}
    {% endmatch %}

    <h3 id="description">Description</h3>
    {{ rendered_description|safe }}

    <p id="license" class="license">Advisory available under <a href="https://spdx.org/licenses/{{ advisory.metadata.license.spdx() }}.html">{{ advisory.metadata.license.spdx() }}</a>
    license.

    {% if advisory.metadata.license == rustsec::advisory::License::CcBy40 %}
      {# License requires attribution, make it explicit #}
      {% match advisory.metadata.url %}
        {% when Some with (url) %}
          Source: <a href="{{ url }}">{{ url }}</a>
        {% when None %}
      {% endmatch %}
    {% endif %}
    </p>
  </article>
