<?xml version="1.0" encoding="UTF-8"?>
<!--
  xenc-schema.rnc (derived from xenc-schema.xsd)
  
  Copyright 2011 W3C (Massachusetts Institute of Technology, 
  Institut National de Recherche en Informatique et en Automatique, 
  Keio University). All Rights Reserved.  http://www.w3.org/Consortium/Legal/
  
  Use and distribution of all schemas in this directory are permitted under the terms
  W3C Software Notice and License
  http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
  
  It is assumed that the driver schema imports xmldsig-core-schema.rnc.
-->
<grammar ns="http://www.w3.org/2001/04/xmlenc#" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
  <define name="ds_KeyValueType" combine="choice">
    <ref name="xenc_DHKeyValue"/>
  </define>
  <define name="ds_DigestMethodType" combine="choice">
    <attribute name="Algorithm">
      <choice>
        <value type="anyURI">http://www.w3.org/2001/04/xmlenc#sha256</value>
        <value type="anyURI">http://www.w3.org/2001/04/xmlenc#sha512</value>
        <value type="anyURI">http://www.w3.org/2001/04/xmlenc#ripemd160</value>
      </choice>
    </attribute>
  </define>
  <define name="xenc_EncryptedType">
    <optional>
      <attribute name="Id">
        <ref name="xenc_IdType"/>
      </attribute>
    </optional>
    <optional>
      <attribute name="Type">
        <data type="anyURI"/>
      </attribute>
    </optional>
    <optional>
      <attribute name="MimeType">
        <data type="string"/>
      </attribute>
    </optional>
    <optional>
      <attribute name="Encoding">
        <data type="anyURI"/>
      </attribute>
    </optional>
    <optional>
      <element name="EncryptionMethod">
        <ref name="xenc_EncryptionMethodType"/>
      </element>
    </optional>
    <optional>
      <ref name="ds_KeyInfo"/>
    </optional>
    <ref name="xenc_CipherData"/>
    <optional>
      <ref name="xenc_EncryptionProperties"/>
    </optional>
  </define>
  <define name="xenc_EncryptionMethodType">
    <mixed>
      <optional>
        <element name="KeySize">
          <ref name="xenc_KeySizeType"/>
        </element>
      </optional>
      <ref name="xenc_EncryptionMethodOtherParams"/>
    </mixed>
  </define>
  <define name="ds_KeyInfoChild" combine="choice">
    <choice>
      <ref name="xenc_EncryptedKey"/>
      <ref name="xenc_AgreementMethod"/>
    </choice>
  </define>
  <define name="xenc_EncryptionMethodOtherParams">
    <choice>
      <attribute name="Algorithm">
        <value type="anyURI">http://www.w3.org/2001/04/xmlenc#tripledes-cbc</value>
      </attribute>
      <attribute name="Algorithm">
        <value type="anyURI">http://www.w3.org/2001/04/xmlenc#aes128-cbc</value>
      </attribute>
      <attribute name="Algorithm">
        <value type="anyURI">http://www.w3.org/2001/04/xmlenc#aes256-cbc</value>
      </attribute>
      <attribute name="Algorithm">
        <value type="anyURI">http://www.w3.org/2001/04/xmlenc#aes192-cbc</value>
      </attribute>
      <attribute name="Algorithm">
        <value type="anyURI">http://www.w3.org/2001/04/xmlenc#rsa-1_5</value>
      </attribute>
      <group>
        <attribute name="Algorithm">
          <value type="anyURI">http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p</value>
        </attribute>
        <optional>
          <element name="OAEPparams">
            <data type="base64Binary"/>
          </element>
        </optional>
        <optional>
          <ref name="ds_DigestMethod"/>
        </optional>
      </group>
      <attribute name="Algorithm">
        <value type="anyURI">http://www.w3.org/2001/04/xmlenc#kw-tripledes</value>
      </attribute>
      <attribute name="Algorithm">
        <choice>
          <value type="anyURI">http://www.w3.org/2001/04/xmlenc#kw-aes128</value>
          <value type="anyURI">http://www.w3.org/2001/04/xmlenc#kw-aes192</value>
          <value type="anyURI">http://www.w3.org/2001/04/xmlenc#kw-aes256</value>
        </choice>
      </attribute>
    </choice>
  </define>
  <define name="xenc_KeySizeType">
    <data type="integer"/>
  </define>
  <define name="xenc_CipherData">
    <element name="CipherData">
      <ref name="xenc_CipherDataType"/>
    </element>
  </define>
  <define name="xenc_CipherDataType">
    <choice>
      <element name="CipherValue">
        <data type="base64Binary"/>
      </element>
      <ref name="xenc_CipherReference"/>
    </choice>
  </define>
  <define name="xenc_CipherReference">
    <element name="CipherReference">
      <ref name="xenc_CipherReferenceType"/>
    </element>
  </define>
  <define name="xenc_CipherReferenceType">
    <attribute name="URI">
      <data type="anyURI"/>
    </attribute>
    <optional>
      <element name="Transforms">
        <ref name="xenc_TransformsType"/>
      </element>
    </optional>
  </define>
  <define name="xenc_TransformsType">
    <oneOrMore>
      <ref name="ds_Transform"/>
    </oneOrMore>
  </define>
  <define name="xenc_EncryptedData">
    <element name="EncryptedData">
      <ref name="xenc_EncryptedDataType"/>
    </element>
  </define>
  <define name="xenc_EncryptedDataType">
    <ref name="xenc_EncryptedType"/>
  </define>
  <define name="xenc_EncryptedKey">
    <element name="EncryptedKey">
      <ref name="xenc_EncryptedKeyType"/>
    </element>
  </define>
  <define name="xenc_EncryptedKeyType">
    <ref name="xenc_EncryptedType"/>
    <optional>
      <ref name="xenc_ReferenceList"/>
    </optional>
    <optional>
      <element name="CarriedKeyName">
        <data type="string"/>
      </element>
    </optional>
    <optional>
      <attribute name="Recipient">
        <data type="string"/>
      </attribute>
    </optional>
  </define>
  <define name="xenc_AgreementMethod">
    <element name="AgreementMethod">
      <ref name="xenc_AgreementMethodType"/>
    </element>
  </define>
  <define name="xenc_AgreementMethodType">
    <mixed>
      <optional>
        <element name="KA-Nonce">
          <data type="base64Binary"/>
        </element>
      </optional>
      <ref name="xenc_AgreementMethodParams"/>
      <optional>
        <element name="OriginatorKeyInfo">
          <ref name="ds_KeyInfoType"/>
        </element>
      </optional>
      <optional>
        <element name="RecipientKeyInfo">
          <ref name="ds_KeyInfoType"/>
        </element>
      </optional>
    </mixed>
  </define>
  <define name="xenc_AgreementMethodParams">
    <attribute name="Algorithm">
      <value type="anyURI">http://www.w3.org/2001/04/xmlenc#dh</value>
    </attribute>
    <ref name="ds_DigestMethod"/>
  </define>
  <define name="xenc_ReferenceList">
    <element name="ReferenceList">
      <oneOrMore>
        <choice>
          <element name="DataReference">
            <ref name="xenc_ReferenceType"/>
          </element>
          <element name="KeyReference">
            <ref name="xenc_ReferenceType"/>
          </element>
        </choice>
      </oneOrMore>
    </element>
  </define>
  <define name="xenc_ReferenceType">
    <attribute name="URI">
      <data type="anyURI"/>
    </attribute>
    <zeroOrMore>
      <ref name="xenc_anyForeignElement"/>
    </zeroOrMore>
  </define>
  <!--
    For both types of references one may optionally specify child elements to aid the recipient in retrieving the EncryptedKey and/or EncryptedData elements. These could include information such as XPath transforms, decompression transforms, or information on how to retrieve the elements from a document storage facility. For example:
    ds_Transforms
  -->
  <define name="xenc_EncryptionProperties">
    <element name="EncryptionProperties">
      <ref name="xenc_EncryptionPropertiesType"/>
    </element>
  </define>
  <define name="xenc_EncryptionPropertiesType">
    <optional>
      <attribute name="Id">
        <ref name="xenc_IdType"/>
      </attribute>
    </optional>
    <oneOrMore>
      <ref name="xenc_EncryptionProperty"/>
    </oneOrMore>
  </define>
  <define name="xenc_EncryptionProperty">
    <element name="EncryptionProperty">
      <ref name="xenc_EncryptionPropertyType"/>
    </element>
  </define>
  <define name="xenc_EncryptionPropertyType">
    <mixed>
      <optional>
        <attribute name="Target">
          <data type="anyURI"/>
        </attribute>
      </optional>
      <optional>
        <attribute name="Id">
          <ref name="xenc_IdType"/>
        </attribute>
      </optional>
      <zeroOrMore>
        <attribute>
          <nsName ns="http://www.w3.org/XML/1998/namespace"/>
        </attribute>
      </zeroOrMore>
      <oneOrMore>
        <ref name="xenc_anyForeignElement"/>
      </oneOrMore>
    </mixed>
  </define>
  <define name="xenc_DHKeyValue">
    <element name="DHKeyValue">
      <ref name="xenc_DHKeyValueType"/>
    </element>
  </define>
  <define name="xenc_DHKeyValueType">
    <optional>
      <element name="P">
        <ref name="ds_CryptoBinary"/>
      </element>
      <element name="Q">
        <ref name="ds_CryptoBinary"/>
      </element>
      <element name="Generator">
        <ref name="ds_CryptoBinary"/>
      </element>
    </optional>
    <element name="Public">
      <ref name="ds_CryptoBinary"/>
    </element>
    <optional>
      <element name="seed">
        <ref name="ds_CryptoBinary"/>
      </element>
      <element name="pgenCounter">
        <ref name="ds_CryptoBinary"/>
      </element>
    </optional>
  </define>
  <define name="xenc_IdType">
    <data type="NCName"/>
  </define>
  <!-- xsd:ID does not work -->
  <define name="ds_DigestAlgorithms" combine="choice">
    <choice>
      <value type="anyURI">http://www.w3.org/2001/04/xmlenc#sha256</value>
      <value type="anyURI">http://www.w3.org/2001/04/xmlenc#sha512</value>
      <value type="anyURI">http://www.w3.org/2001/04/xmlenc#ripemd160</value>
    </choice>
  </define>
  <define name="xenc_EncryptionAlgorithms">
    <choice>
      <value type="anyURI">http://www.w3.org/2001/04/xmlenc#tripledes-cbc</value>
      <value type="anyURI">http://www.w3.org/2001/04/xmlenc#aes128-cbc</value>
      <value type="anyURI">http://www.w3.org/2001/04/xmlenc#aes256-cbc</value>
      <value type="anyURI">http://www.w3.org/2001/04/xmlenc#aes192-cbc</value>
      <value type="anyURI">http://www.w3.org/2001/04/xmlenc#rsa-1_5</value>
      <value type="anyURI">http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p</value>
      <value type="anyURI">http://www.w3.org/2001/04/xmlenc#kw-tripledes</value>
      <value type="anyURI">http://www.w3.org/2001/04/xmlenc#kw-aes128</value>
      <value type="anyURI">http://www.w3.org/2001/04/xmlenc#kw-aes256</value>
      <value type="anyURI">http://www.w3.org/2001/04/xmlenc#kw-aes192</value>
    </choice>
  </define>
  <define name="xenc_KeyAgreementAlgorithms">
    <value type="anyURI">http://www.w3.org/2001/04/xmlenc#dh</value>
  </define>
</grammar>
