/**
  * Creates a <code>DOMPGPData</code> from an element.
  *
  * @param pdElem a PGPData element
  */
 public DOMPGPData(Element pdElem) throws MarshalException {
   // get all children nodes
   byte[] keyId = null;
   byte[] keyPacket = null;
   NodeList nl = pdElem.getChildNodes();
   int length = nl.getLength();
   List other = new ArrayList(length);
   for (int x = 0; x < length; x++) {
     Node n = nl.item(x);
     if (n.getNodeType() == Node.ELEMENT_NODE) {
       Element childElem = (Element) n;
       String localName = childElem.getLocalName();
       try {
         if (localName.equals("PGPKeyID")) {
           keyId = Base64.decode(childElem);
         } else if (localName.equals("PGPKeyPacket")) {
           keyPacket = Base64.decode(childElem);
         } else {
           other.add(new javax.xml.crypto.dom.DOMStructure(childElem));
         }
       } catch (Base64DecodingException bde) {
         throw new MarshalException(bde);
       }
     }
   }
   this.keyId = keyId;
   this.keyPacket = keyPacket;
   this.externalElements = Collections.unmodifiableList(other);
 }
Exemplo n.º 2
0
  /**
   * Creates an <code>XMLObject</code> from an element.
   *
   * @param objElem an Object element
   * @throws MarshalException if there is an error when unmarshalling
   */
  public DOMXMLObject(Element objElem, XMLCryptoContext context, Provider provider)
      throws MarshalException {
    // unmarshal attributes
    this.encoding = DOMUtils.getAttributeValue(objElem, "Encoding");

    Attr attr = objElem.getAttributeNodeNS(null, "Id");
    if (attr != null) {
      this.id = attr.getValue();
      objElem.setIdAttributeNode(attr, true);
    } else {
      this.id = null;
    }
    this.mimeType = DOMUtils.getAttributeValue(objElem, "MimeType");

    NodeList nodes = objElem.getChildNodes();
    int length = nodes.getLength();
    List content = new ArrayList(length);
    for (int i = 0; i < length; i++) {
      Node child = nodes.item(i);
      if (child.getNodeType() == Node.ELEMENT_NODE) {
        Element childElem = (Element) child;
        String tag = childElem.getLocalName();
        if (tag.equals("Manifest")) {
          content.add(new DOMManifest(childElem, context, provider));
          continue;
        } else if (tag.equals("SignatureProperties")) {
          content.add(new DOMSignatureProperties(childElem));
          continue;
        } else if (tag.equals("X509Data")) {
          content.add(new DOMX509Data(childElem));
          continue;
        }
        // @@@FIXME: check for other dsig structures
      }
      content.add(new javax.xml.crypto.dom.DOMStructure(child));
    }
    if (content.isEmpty()) {
      this.content = Collections.EMPTY_LIST;
    } else {
      this.content = Collections.unmodifiableList(content);
    }
  }
Exemplo n.º 3
0
  /**
   * Creates a <code>DOMReference</code> from an element.
   *
   * @param refElem a Reference element
   */
  public DOMReference(Element refElem, XMLCryptoContext context) throws MarshalException {
    // unmarshal Transforms, if specified
    Element nextSibling = DOMUtils.getFirstChildElement(refElem);
    List transforms = new ArrayList(5);
    if (nextSibling.getLocalName().equals("Transforms")) {
      Element transformElem = DOMUtils.getFirstChildElement(nextSibling);
      while (transformElem != null) {
        transforms.add(new DOMTransform(transformElem, context));
        transformElem = DOMUtils.getNextSiblingElement(transformElem);
      }
      nextSibling = DOMUtils.getNextSiblingElement(nextSibling);
    }

    // unmarshal DigestMethod
    Element dmElem = nextSibling;
    this.digestMethod = DOMDigestMethod.unmarshal(dmElem);

    // unmarshal DigestValue
    try {
      Element dvElem = DOMUtils.getNextSiblingElement(dmElem);
      this.digestValue = Base64.decode(dvElem);
    } catch (Base64DecodingException bde) {
      throw new MarshalException(bde);
    }

    // unmarshal attributes
    this.uri = DOMUtils.getAttributeValue(refElem, "URI");
    this.id = DOMUtils.getAttributeValue(refElem, "Id");

    this.type = DOMUtils.getAttributeValue(refElem, "Type");
    this.here = refElem.getAttributeNodeNS(null, "URI");
    this.refElem = refElem;

    if (transforms.isEmpty()) {
      this.transforms = Collections.EMPTY_LIST;
    } else {
      this.transforms = Collections.unmodifiableList(transforms);
    }
    this.appliedTransforms = Collections.EMPTY_LIST;
    this.allTransforms = transforms;
    this.appliedTransformData = null;
  }
  /**
   * Creates a <code>DOMSignatureProperty</code> from an element.
   *
   * @param propElem a SignatureProperty element
   */
  public DOMSignatureProperty(Element propElem) throws MarshalException {
    // unmarshal attributes
    target = DOMUtils.getAttributeValue(propElem, "Target");
    if (target == null) {
      throw new MarshalException("target cannot be null");
    }
    id = DOMUtils.getAttributeValue(propElem, "Id");

    NodeList nodes = propElem.getChildNodes();
    int length = nodes.getLength();
    List content = new ArrayList(length);
    for (int i = 0; i < length; i++) {
      content.add(new javax.xml.crypto.dom.DOMStructure(nodes.item(i)));
    }
    if (content.isEmpty()) {
      throw new MarshalException("content cannot be empty");
    } else {
      this.content = Collections.unmodifiableList(content);
    }
  }