Package org.apache.xml.security.c14n
Class Canonicalizer
- java.lang.Object
-
- org.apache.xml.security.c14n.Canonicalizer
-
public class Canonicalizer extends Object
- Author:
- Christian Geuer-Pollmann
-
-
Field Summary
Fields Modifier and Type Field Description static StringALGO_ID_C14N_EXCL_OMIT_COMMENTSThe URL defined in XML-SEC Rec for exclusive c14n without comments.static StringALGO_ID_C14N_EXCL_WITH_COMMENTSThe URL defined in XML-SEC Rec for exclusive c14n with comments.static StringALGO_ID_C14N_OMIT_COMMENTSThe URL defined in XML-SEC Rec for inclusive c14n without comments.static StringALGO_ID_C14N_PHYSICALNon-standard algorithm to serialize the physical representation for XML Encryptionstatic StringALGO_ID_C14N_WITH_COMMENTSThe URL defined in XML-SEC Rec for inclusive c14n with comments.static StringALGO_ID_C14N11_OMIT_COMMENTSThe URI for inclusive c14n 1.1 without comments.static StringALGO_ID_C14N11_WITH_COMMENTSThe URI for inclusive c14n 1.1 with comments.static StringENCODINGThe output encoding of canonicalized datastatic StringXPATH_C14N_WITH_COMMENTS_SINGLE_NODEXPath Expression for selecting every node and continuous comments joined in only one node
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]canonicalize(byte[] inputBytes)This method tries to canonicalize the given bytes.byte[]canonicalizeSubtree(Node node)Canonicalizes the subtree rooted bynode.byte[]canonicalizeSubtree(Node node, String inclusiveNamespaces)Canonicalizes the subtree rooted bynode.byte[]canonicalizeSubtree(Node node, String inclusiveNamespaces, boolean propagateDefaultNamespace)Canonicalizes the subtree rooted bynode.byte[]canonicalizeXPathNodeSet(Set<Node> xpathNodeSet)Canonicalizes an XPath node set.byte[]canonicalizeXPathNodeSet(Set<Node> xpathNodeSet, String inclusiveNamespaces)Canonicalizes an XPath node set.byte[]canonicalizeXPathNodeSet(NodeList xpathNodeSet)Canonicalizes an XPath node set.byte[]canonicalizeXPathNodeSet(NodeList xpathNodeSet, String inclusiveNamespaces)Canonicalizes an XPath node set.StringgetImplementingCanonicalizerClass()Returns the name of the implementingCanonicalizerSpiclassbooleangetIncludeComments()Method getIncludeCommentsstatic CanonicalizergetInstance(String algorithmURI)Method getInstanceStringgetURI()Method getURIbooleanisSecureValidation()voidnotReset()Set the canonicalizer behaviour to not reset.static voidregister(String algorithmURI, Class<? extends CanonicalizerSpi> implementingClass)Method registerstatic voidregister(String algorithmURI, String implementingClass)Method registerstatic voidregisterDefaultAlgorithms()This method registers the default algorithms.voidsetSecureValidation(boolean secureValidation)voidsetWriter(OutputStream os)Sets the writer where the canonicalization ends.
-
-
-
Field Detail
-
ENCODING
public static final String ENCODING
The output encoding of canonicalized data- See Also:
- Constant Field Values
-
XPATH_C14N_WITH_COMMENTS_SINGLE_NODE
public static final String XPATH_C14N_WITH_COMMENTS_SINGLE_NODE
XPath Expression for selecting every node and continuous comments joined in only one node- See Also:
- Constant Field Values
-
ALGO_ID_C14N_OMIT_COMMENTS
public static final String ALGO_ID_C14N_OMIT_COMMENTS
The URL defined in XML-SEC Rec for inclusive c14n without comments.- See Also:
- Constant Field Values
-
ALGO_ID_C14N_WITH_COMMENTS
public static final String ALGO_ID_C14N_WITH_COMMENTS
The URL defined in XML-SEC Rec for inclusive c14n with comments.- See Also:
- Constant Field Values
-
ALGO_ID_C14N_EXCL_OMIT_COMMENTS
public static final String ALGO_ID_C14N_EXCL_OMIT_COMMENTS
The URL defined in XML-SEC Rec for exclusive c14n without comments.- See Also:
- Constant Field Values
-
ALGO_ID_C14N_EXCL_WITH_COMMENTS
public static final String ALGO_ID_C14N_EXCL_WITH_COMMENTS
The URL defined in XML-SEC Rec for exclusive c14n with comments.- See Also:
- Constant Field Values
-
ALGO_ID_C14N11_OMIT_COMMENTS
public static final String ALGO_ID_C14N11_OMIT_COMMENTS
The URI for inclusive c14n 1.1 without comments.- See Also:
- Constant Field Values
-
ALGO_ID_C14N11_WITH_COMMENTS
public static final String ALGO_ID_C14N11_WITH_COMMENTS
The URI for inclusive c14n 1.1 with comments.- See Also:
- Constant Field Values
-
ALGO_ID_C14N_PHYSICAL
public static final String ALGO_ID_C14N_PHYSICAL
Non-standard algorithm to serialize the physical representation for XML Encryption- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
public static final Canonicalizer getInstance(String algorithmURI) throws InvalidCanonicalizerException
Method getInstance- Parameters:
algorithmURI-- Returns:
- a Canonicalizer instance ready for the job
- Throws:
InvalidCanonicalizerException
-
register
public static void register(String algorithmURI, String implementingClass) throws AlgorithmAlreadyRegisteredException, ClassNotFoundException
Method register- Parameters:
algorithmURI-implementingClass-- Throws:
AlgorithmAlreadyRegisteredExceptionSecurityException- if a security manager is installed and the caller does not have permission to register the canonicalizerClassNotFoundException
-
register
public static void register(String algorithmURI, Class<? extends CanonicalizerSpi> implementingClass) throws AlgorithmAlreadyRegisteredException, ClassNotFoundException
Method register- Parameters:
algorithmURI-implementingClass-- Throws:
AlgorithmAlreadyRegisteredExceptionSecurityException- if a security manager is installed and the caller does not have permission to register the canonicalizerClassNotFoundException
-
registerDefaultAlgorithms
public static void registerDefaultAlgorithms()
This method registers the default algorithms.
-
getURI
public final String getURI()
Method getURI- Returns:
- the URI defined for this c14n instance.
-
getIncludeComments
public boolean getIncludeComments()
Method getIncludeComments- Returns:
- true if the c14n respect the comments.
-
canonicalize
public byte[] canonicalize(byte[] inputBytes) throws ParserConfigurationException, IOException, SAXException, CanonicalizationExceptionThis method tries to canonicalize the given bytes. It's possible to even canonicalize non-wellformed sequences if they are well-formed after being wrapped with a>a<...>/a<.- Parameters:
inputBytes-- Returns:
- the result of the canonicalization.
- Throws:
CanonicalizationExceptionIOExceptionParserConfigurationExceptionSAXException
-
canonicalizeSubtree
public byte[] canonicalizeSubtree(Node node) throws CanonicalizationException
Canonicalizes the subtree rooted bynode.- Parameters:
node- The node to canonicalize- Returns:
- the result of the c14n.
- Throws:
CanonicalizationException
-
canonicalizeSubtree
public byte[] canonicalizeSubtree(Node node, String inclusiveNamespaces) throws CanonicalizationException
Canonicalizes the subtree rooted bynode.- Parameters:
node-inclusiveNamespaces-- Returns:
- the result of the c14n.
- Throws:
CanonicalizationException
-
canonicalizeSubtree
public byte[] canonicalizeSubtree(Node node, String inclusiveNamespaces, boolean propagateDefaultNamespace) throws CanonicalizationException
Canonicalizes the subtree rooted bynode.- Parameters:
node-inclusiveNamespaces-- Returns:
- the result of the c14n.
- Throws:
CanonicalizationException
-
canonicalizeXPathNodeSet
public byte[] canonicalizeXPathNodeSet(NodeList xpathNodeSet) throws CanonicalizationException
Canonicalizes an XPath node set. ThexpathNodeSetis treated as a list of XPath nodes, not as a list of subtrees.- Parameters:
xpathNodeSet-- Returns:
- the result of the c14n.
- Throws:
CanonicalizationException
-
canonicalizeXPathNodeSet
public byte[] canonicalizeXPathNodeSet(NodeList xpathNodeSet, String inclusiveNamespaces) throws CanonicalizationException
Canonicalizes an XPath node set. ThexpathNodeSetis treated as a list of XPath nodes, not as a list of subtrees.- Parameters:
xpathNodeSet-inclusiveNamespaces-- Returns:
- the result of the c14n.
- Throws:
CanonicalizationException
-
canonicalizeXPathNodeSet
public byte[] canonicalizeXPathNodeSet(Set<Node> xpathNodeSet) throws CanonicalizationException
Canonicalizes an XPath node set.- Parameters:
xpathNodeSet-- Returns:
- the result of the c14n.
- Throws:
CanonicalizationException
-
canonicalizeXPathNodeSet
public byte[] canonicalizeXPathNodeSet(Set<Node> xpathNodeSet, String inclusiveNamespaces) throws CanonicalizationException
Canonicalizes an XPath node set.- Parameters:
xpathNodeSet-inclusiveNamespaces-- Returns:
- the result of the c14n.
- Throws:
CanonicalizationException
-
setWriter
public void setWriter(OutputStream os)
Sets the writer where the canonicalization ends. ByteArrayOutputStream if none is set.- Parameters:
os-
-
getImplementingCanonicalizerClass
public String getImplementingCanonicalizerClass()
Returns the name of the implementingCanonicalizerSpiclass- Returns:
- the name of the implementing
CanonicalizerSpiclass
-
notReset
public void notReset()
Set the canonicalizer behaviour to not reset.
-
isSecureValidation
public boolean isSecureValidation()
-
setSecureValidation
public void setSecureValidation(boolean secureValidation)
-
-