XMLCipher dataCipher = XMLCipher.getInstance();
dataCipher.init(XMLCipher.DECRYPT_MODE, null);
ReferenceList dataRefList = dataCipher.createReferenceList(ReferenceList.DATA_REFERENCE);
Reference dataRef1 = dataRefList.newDataReference("#id1");
dataRefList.add(dataRef1);
Reference dataRef2 = dataRefList.newDataReference("#id2");
dataRefList.add(dataRef2);
assertEquals("#id1", dataRef1.getURI());
ReferenceList keyRefList = dataCipher.createReferenceList(ReferenceList.KEY_REFERENCE);
Reference keyRef10 = keyRefList.newKeyReference("#id10");
keyRefList.add(keyRef10);
Reference keyRef20 = keyRefList.newKeyReference("#id20");
keyRefList.add(keyRef20);
assertEquals("#id10", keyRef10.getURI());
// See SANTUARIO-302
// https://issues.apache.org/jira/browse/SANTUARIO-302
Element dataRefListElement = dataCipher.martial(doc, dataRefList);
assertEquals(EncryptionConstants.EncryptionSpecNS, dataRefListElement.getNamespaceURI());
assertEquals(EncryptionConstants._TAG_REFERENCELIST, dataRefListElement.getLocalName());
Element dataRef1Element = (Element)dataRefListElement.getFirstChild();
assertEquals(EncryptionConstants.EncryptionSpecNS, dataRef1Element.getNamespaceURI());
assertEquals(EncryptionConstants._TAG_DATAREFERENCE, dataRef1Element.getLocalName());
assertEquals("#id1", dataRef1Element.getAttribute("URI"));
Element dataRef2Element = (Element)dataRef1Element.getNextSibling();
assertEquals(EncryptionConstants.EncryptionSpecNS, dataRef2Element.getNamespaceURI());
assertEquals(EncryptionConstants._TAG_DATAREFERENCE, dataRef2Element.getLocalName());
assertEquals("#id2", dataRef2Element.getAttribute("URI"));
assertNull(dataRef2Element.getNextSibling());
Element keyRefListElement = dataCipher.martial(doc, keyRefList);
assertEquals(EncryptionConstants.EncryptionSpecNS, keyRefListElement.getNamespaceURI());
assertEquals(EncryptionConstants._TAG_REFERENCELIST, keyRefListElement.getLocalName());
Element keyRef10Element = (Element)keyRefListElement.getFirstChild();
assertEquals(EncryptionConstants.EncryptionSpecNS, keyRef10Element.getNamespaceURI());
assertEquals(EncryptionConstants._TAG_KEYREFERENCE, keyRef10Element.getLocalName());
assertEquals("#id10", keyRef10Element.getAttribute("URI"));
Element keyRef20Element = (Element)keyRef10Element.getNextSibling();
assertEquals(EncryptionConstants.EncryptionSpecNS, keyRef20Element.getNamespaceURI());
assertEquals(EncryptionConstants._TAG_KEYREFERENCE, keyRef20Element.getLocalName());
assertEquals("#id20", keyRef20Element.getAttribute("URI"));
assertNull(keyRef20Element.getNextSibling());
// See SANTUARIO-304
// https://issues.apache.org/jira/browse/SANTUARIO-304
Iterator<Reference> iter = dataRefList.getReferences();
Reference ref = iter.next();
assertEquals(EncryptionConstants._TAG_DATAREFERENCE, ref.getType());
assertEquals("#id1", ref.getURI());
ref = iter.next();
assertEquals(EncryptionConstants._TAG_DATAREFERENCE, ref.getType());
assertEquals("#id2", ref.getURI());
assertTrue(!iter.hasNext());
iter = keyRefList.getReferences();
ref = iter.next();
assertEquals(EncryptionConstants._TAG_KEYREFERENCE, ref.getType());
assertEquals("#id10", ref.getURI());
ref = iter.next();
assertEquals(EncryptionConstants._TAG_KEYREFERENCE, ref.getType());
assertEquals("#id20", ref.getURI());
assertTrue(!iter.hasNext());
}