/*
* 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
*
*
* 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.
*
*/
/*
*/
/*
* $Id: DOMPGPData.java,v 1.2 2008/07/24 15:20:32 mullan Exp $
*/
/**
* DOM-based implementation of PGPData.
*
* @author Sean Mullan
*/
private final byte[] keyId;
private final byte[] keyPacket;
/**
* Creates a <code>DOMPGPData</code> 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
* <a href="http://www.ietf.org/rfc/rfc2440.txt"/>RFC 2440</a>. 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 <code>null</code> or empty.
* @throws NullPointerException if <code>keyPacket</code> is
* <code>null</code>
* @throws IllegalArgumentException if the key packet is not in the
* correct format
* @throws ClassCastException if <code>other</code> contains any
* entries that are not of type {@link XMLStructure}
*/
throw new NullPointerException("keyPacket cannot be null");
}
} else {
throw new ClassCastException
("other["+i+"] is not a valid PGPData type");
}
}
}
}
/**
* Creates a <code>DOMPGPData</code> 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
* <a href="http://www.ietf.org/rfc/rfc2440.txt"/>RFC 2440</a>. The
* array is cloned to prevent subsequent modification.
* @param keyPacket a PGP Key Material Packet as defined in section 5.5 of
* <a href="http://www.ietf.org/rfc/rfc2440.txt"/>RFC 2440</a> (may
* be <code>null</code>). 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 <code>null</code> or empty.
* @throws NullPointerException if <code>keyId</code> is <code>null</code>
* @throws IllegalArgumentException if the key id or packet is not in the
* correct format
* @throws ClassCastException if <code>other</code> contains any
* entries that are not of type {@link XMLStructure}
*/
throw new NullPointerException("keyId cannot be null");
}
// key ids must be 8 bytes
throw new IllegalArgumentException("keyId must be 8 bytes long");
}
} else {
throw new ClassCastException
("other["+i+"] is not a valid PGPData type");
}
}
}
}
}
/**
* Creates a <code>DOMPGPData</code> from an element.
*
* @param pdElem a PGPData element
*/
// get all children nodes
for (int x = 0; x < length; x++) {
try {
} else {
}
} catch (Base64DecodingException bde) {
throw new MarshalException(bde);
}
}
}
}
public byte[] getKeyId() {
}
public byte[] getKeyPacket() {
}
return externalElements;
}
throws MarshalException {
// create and append PGPKeyID element
}
// create and append PGPKeyPacket element
}
// create and append any elements
}
}
/**
* We assume packets use the new format packet syntax, as specified in
* 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.
*/
// length must be at least 3 (one byte for tag, one byte for length,
// and minimally one byte of content
throw new IllegalArgumentException("keypacket must be at least " +
"3 bytes long");
}
// first bit must be set
throw new IllegalArgumentException("keypacket tag is invalid: " +
"bit 7 is not set");
}
// make sure using new format
throw new IllegalArgumentException("old keypacket tag format is " +
"unsupported");
}
// tag value must be 6, 14, 5 or 7
throw new IllegalArgumentException("keypacket tag is invalid: " +
"must be 6, 14, 5, or 7");
}
}
}