private KeyDescriptor buildKeyDescriptor(String keyName, UsageType use, Object... contentItems) {
    KeyDescriptor keyDesc = buildXMLObject(KeyDescriptor.DEFAULT_ELEMENT_NAME);
    KeyInfo keyInfo = buildXMLObject(KeyInfo.DEFAULT_ELEMENT_NAME);

    for (Object contentItem : contentItems) {
      if (contentItem instanceof PublicKey) {
        KeyInfoSupport.addPublicKey(keyInfo, (PublicKey) contentItem);
      } else if (contentItem instanceof X509Certificate) {
        try {
          KeyInfoSupport.addCertificate(keyInfo, (X509Certificate) contentItem);
        } catch (CertificateEncodingException e) {
          throw new RuntimeException("CertificateEncodingException ading cert to KeyInfo", e);
        }
      } else {
        throw new RuntimeException(
            "Saw unknown KeyInfo content type: " + contentItem.getClass().getName());
      }
    }

    if (keyName != null) {
      KeyInfoSupport.addKeyName(keyInfo, keyName);
    }

    keyDesc.setKeyInfo(keyInfo);

    if (use != null) {
      keyDesc.setUse(use);
    }

    return keyDesc;
  }