Jon,
Wow, that is some ugly code you have there!
<GRIN>.
There is no "nice" way I know of to do what you want - but one question
- why do you first extract everything from the set and put into a list?
Can't you call nodes.contains() for each node you are interested in?
Cheers,
Berin
Anderson Jonathan wrote:
> Greetings,
> I'm curious - is there an efficient way to verify signature references
> against a set of required elements? I'm trying to write some code that
> enforces signature "coverage," and I'm struggling to find an elegant way to
> do it. Here's what I've got so far:
>
> List coveredElementNodes = new ArrayList();
> for (int i=0; i < sig.getSignedInfo().getLength(); i++)
> {
> Reference ref = sig.getSignedInfo().item(i);
> XMLSignatureInput input = ref.getContentsBeforeTransformation();
> Set nodes = input.getNodeSet();
> for (Iterator iterator = nodes.iterator(); iterator.hasNext();)
> {
> Node node = (Node) iterator.next();
> if (node.getNodeType() == Node.ELEMENT_NODE)
> {
> coveredElementNodes.add(node);
> }
> }
> }
>
> And then I simply do a coverElementNodes.contains() for every Element in the
> DOM that I want to ensure has been signed. It's ugly, it's inefficient, and
> I'm curious - is there a better way?
>
> Any and all feedback would be appreciated (including "wow, that is some ugly
> code you've got there" comments). :) Thanks in advance.
>
> -Jon
>
>
>
>
|