--- old/src/share/classes/org/jcp/xml/dsig/internal/dom/DOMPGPData.java 2013-06-28 11:34:53.791931539 -0400 +++ new/src/share/classes/org/jcp/xml/dsig/internal/dom/DOMPGPData.java 2013-06-28 11:34:53.599937513 -0400 @@ -2,27 +2,29 @@ * reserved comment block * DO NOT REMOVE OR ALTER! */ -/* - * Copyright 2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ /* * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved. */ /* - * $Id: DOMPGPData.java,v 1.2 2008/07/24 15:20:32 mullan Exp $ + * $Id: DOMPGPData.java 1203846 2011-11-18 21:18:17Z mullan $ */ package org.jcp.xml.dsig.internal.dom; @@ -48,42 +50,42 @@ private final byte[] keyId; private final byte[] keyPacket; - private final List externalElements; + private final List externalElements; /** - * Creates a DOMPGPData containing the specified key packet. + * Creates a DOMPGPData containing the specified key packet. * and optional list of external elements. * - * @param keyPacket a PGP Key Material Packet as defined in section 5.5 of - * RFC 2440. The + * @param keyPacket a PGP Key Material Packet as defined in section 5.5 of + * RFC 2440. The * array is cloned to prevent subsequent modification. * @param other a list of {@link XMLStructure}s representing elements from * an external namespace. The list is defensively copied to prevent * subsequent modification. May be null or empty. - * @throws NullPointerException if keyPacket is + * @throws NullPointerException if keyPacket is * null - * @throws IllegalArgumentException if the key packet is not in the + * @throws IllegalArgumentException if the key packet is not in the * correct format * @throws ClassCastException if other contains any * entries that are not of type {@link XMLStructure} */ - public DOMPGPData(byte[] keyPacket, List other) { + public DOMPGPData(byte[] keyPacket, List other) { if (keyPacket == null) { throw new NullPointerException("keyPacket cannot be null"); } if (other == null || other.isEmpty()) { - this.externalElements = Collections.EMPTY_LIST; + this.externalElements = Collections.emptyList(); } else { - List otherCopy = new ArrayList(other); - for (int i = 0, size = otherCopy.size(); i < size; i++) { - if (!(otherCopy.get(i) instanceof XMLStructure)) { + this.externalElements = + Collections.unmodifiableList(new ArrayList(other)); + for (int i = 0, size = this.externalElements.size(); i < size; i++) { + if (!(this.externalElements.get(i) instanceof XMLStructure)) { throw new ClassCastException ("other["+i+"] is not a valid PGPData type"); } } - this.externalElements = Collections.unmodifiableList(otherCopy); } - this.keyPacket = (byte []) keyPacket.clone(); + this.keyPacket = (byte[])keyPacket.clone(); checkKeyPacket(keyPacket); this.keyId = null; } @@ -92,23 +94,25 @@ * Creates a DOMPGPData containing the specified key id and * optional key packet and list of external elements. * - * @param keyId a PGP public key id as defined in section 11.2 of - * RFC 2440. The + * @param keyId a PGP public key id as defined in section 11.2 of + * RFC 2440. The * array is cloned to prevent subsequent modification. - * @param keyPacket a PGP Key Material Packet as defined in section 5.5 of + * @param keyPacket a PGP Key Material Packet as defined in section 5.5 of * RFC 2440 (may - * be null). The array is cloned to prevent subsequent + * be null). The array is cloned to prevent subsequent * modification. * @param other a list of {@link XMLStructure}s representing elements from * an external namespace. The list is defensively copied to prevent * subsequent modification. May be null or empty. * @throws NullPointerException if keyId is null - * @throws IllegalArgumentException if the key id or packet is not in the + * @throws IllegalArgumentException if the key id or packet is not in the * correct format * @throws ClassCastException if other contains any * entries that are not of type {@link XMLStructure} */ - public DOMPGPData(byte[] keyId, byte[] keyPacket, List other) { + public DOMPGPData(byte[] keyId, byte[] keyPacket, + List other) + { if (keyId == null) { throw new NullPointerException("keyId cannot be null"); } @@ -117,19 +121,20 @@ throw new IllegalArgumentException("keyId must be 8 bytes long"); } if (other == null || other.isEmpty()) { - this.externalElements = Collections.EMPTY_LIST; + this.externalElements = Collections.emptyList(); } else { - List otherCopy = new ArrayList(other); - for (int i = 0, size = otherCopy.size(); i < size; i++) { - if (!(otherCopy.get(i) instanceof XMLStructure)) { + this.externalElements = + Collections.unmodifiableList(new ArrayList(other)); + for (int i = 0, size = this.externalElements.size(); i < size; i++) { + if (!(this.externalElements.get(i) instanceof XMLStructure)) { throw new ClassCastException ("other["+i+"] is not a valid PGPData type"); } } - this.externalElements = Collections.unmodifiableList(otherCopy); } - this.keyId = (byte []) keyId.clone(); - this.keyPacket = keyPacket == null ? null : (byte []) keyPacket.clone(); + this.keyId = (byte[])keyId.clone(); + this.keyPacket = keyPacket == null ? null + : (byte[])keyPacket.clone(); if (keyPacket != null) { checkKeyPacket(keyPacket); } @@ -146,11 +151,11 @@ byte[] keyPacket = null; NodeList nl = pdElem.getChildNodes(); int length = nl.getLength(); - List other = new ArrayList(length); + 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; + Element childElem = (Element)n; String localName = childElem.getLocalName(); try { if (localName.equals("PGPKeyID")) { @@ -172,11 +177,11 @@ } public byte[] getKeyId() { - return (keyId == null ? null : (byte []) keyId.clone()); + return (keyId == null ? null : (byte[])keyId.clone()); } public byte[] getKeyPacket() { - return (keyPacket == null ? null : (byte []) keyPacket.clone()); + return (keyPacket == null ? null : (byte[])keyPacket.clone()); } public List getExternalElements() { @@ -184,16 +189,17 @@ } public void marshal(Node parent, String dsPrefix, DOMCryptoContext context) - throws MarshalException { + throws MarshalException + { Document ownerDoc = DOMUtils.getOwnerDocument(parent); - - Element pdElem = DOMUtils.createElement - (ownerDoc, "PGPData", XMLSignature.XMLNS, dsPrefix); + Element pdElem = DOMUtils.createElement(ownerDoc, "PGPData", + XMLSignature.XMLNS, dsPrefix); // create and append PGPKeyID element if (keyId != null) { - Element keyIdElem = DOMUtils.createElement - (ownerDoc, "PGPKeyID", XMLSignature.XMLNS, dsPrefix); + Element keyIdElem = DOMUtils.createElement(ownerDoc, "PGPKeyID", + XMLSignature.XMLNS, + dsPrefix); keyIdElem.appendChild (ownerDoc.createTextNode(Base64.encode(keyId))); pdElem.appendChild(keyIdElem); @@ -201,17 +207,19 @@ // create and append PGPKeyPacket element if (keyPacket != null) { - Element keyPktElem = DOMUtils.createElement - (ownerDoc, "PGPKeyPacket", XMLSignature.XMLNS, dsPrefix); + Element keyPktElem = DOMUtils.createElement(ownerDoc, + "PGPKeyPacket", + XMLSignature.XMLNS, + dsPrefix); keyPktElem.appendChild (ownerDoc.createTextNode(Base64.encode(keyPacket))); pdElem.appendChild(keyPktElem); } // create and append any elements - for (int i = 0, size = externalElements.size(); i < size; i++) { - DOMUtils.appendChild(pdElem, ((javax.xml.crypto.dom.DOMStructure) - externalElements.get(i)).getNode()); + for (XMLStructure extElem : externalElements) { + DOMUtils.appendChild(pdElem, ((javax.xml.crypto.dom.DOMStructure) + extElem).getNode()); } parent.appendChild(pdElem); @@ -222,33 +230,33 @@ * section 4 of RFC 2440. * * This method only checks if the packet contains a valid tag. The - * contents of the packet should be checked by the application. + * contents of the packet should be checked by the application. */ private void checkKeyPacket(byte[] keyPacket) { // length must be at least 3 (one byte for tag, one byte for length, // and minimally one byte of content if (keyPacket.length < 3) { throw new IllegalArgumentException("keypacket must be at least " + - "3 bytes long"); + "3 bytes long"); } int tag = keyPacket[0]; // first bit must be set if ((tag & 128) != 128) { throw new IllegalArgumentException("keypacket tag is invalid: " + - "bit 7 is not set"); + "bit 7 is not set"); } // make sure using new format if ((tag & 64) != 64) { throw new IllegalArgumentException("old keypacket tag format is " + - "unsupported"); + "unsupported"); } // tag value must be 6, 14, 5 or 7 - if (((tag & 6) != 6) && ((tag & 14) != 14) && + if (((tag & 6) != 6) && ((tag & 14) != 14) && ((tag & 5) != 5) && ((tag & 7) != 7)) { throw new IllegalArgumentException("keypacket tag is invalid: " + - "must be 6, 14, 5, or 7"); + "must be 6, 14, 5, or 7"); } } }