keyinfo.java
来自「JAVA 所有包」· Java 代码 · 共 1,226 行 · 第 1/3 页
JAVA
1,226 行
public int lengthUnknownElement() { int res = 0; NodeList nl = this._constructionElement.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node current = nl.item(i); /** * $todo$ using this method, we don't see unknown Elements * from Signature NS; revisit */ if ((current.getNodeType() == Node.ELEMENT_NODE) && current.getNamespaceURI() .equals(Constants.SignatureSpecNS)) { res++; } } return res; } /** * Method itemKeyName * * @param i * @return the asked KeyName element, null if the index is too big * @throws XMLSecurityException */ public KeyName itemKeyName(int i) throws XMLSecurityException { Element e = XMLUtils.selectDsNode(this._constructionElement.getFirstChild(), Constants._TAG_KEYNAME,i); if (e != null) { return new KeyName(e, this._baseURI); } return null; } /** * Method itemKeyValue * * @param i * @return the asked KeyValue element, null if the index is too big * @throws XMLSecurityException */ public KeyValue itemKeyValue(int i) throws XMLSecurityException { Element e = XMLUtils.selectDsNode(this._constructionElement.getFirstChild(), Constants._TAG_KEYVALUE,i); if (e != null) { return new KeyValue(e, this._baseURI); } return null; } /** * Method itemMgmtData * * @param i *@return the asked MgmtData element, null if the index is too big * @throws XMLSecurityException */ public MgmtData itemMgmtData(int i) throws XMLSecurityException { Element e = XMLUtils.selectDsNode(this._constructionElement.getFirstChild(), Constants._TAG_MGMTDATA,i); if (e != null) { return new MgmtData(e, this._baseURI); } return null; } /** * Method itemPGPData * * @param i *@return the asked PGPData element, null if the index is too big * @throws XMLSecurityException */ public PGPData itemPGPData(int i) throws XMLSecurityException { Element e = XMLUtils.selectDsNode(this._constructionElement.getFirstChild(), Constants._TAG_PGPDATA,i); if (e != null) { return new PGPData(e, this._baseURI); } return null; } /** * Method itemRetrievalMethod * * @param i *@return the asked RetrievalMethod element, null if the index is too big * @throws XMLSecurityException */ public RetrievalMethod itemRetrievalMethod(int i) throws XMLSecurityException { Element e = XMLUtils.selectDsNode(this._constructionElement.getFirstChild(), Constants._TAG_RETRIEVALMETHOD,i); if (e != null) { return new RetrievalMethod(e, this._baseURI); } return null; } /** * Method itemSPKIData * * @param i *@return the asked SPKIData element, null if the index is too big * @throws XMLSecurityException */ public SPKIData itemSPKIData(int i) throws XMLSecurityException { Element e = XMLUtils.selectDsNode(this._constructionElement.getFirstChild(), Constants._TAG_SPKIDATA,i); if (e != null) { return new SPKIData(e, this._baseURI); } return null; } /** * Method itemX509Data *@return the asked X509Data element, null if the index is too big * @param i * * @throws XMLSecurityException */ public X509Data itemX509Data(int i) throws XMLSecurityException { Element e = XMLUtils.selectDsNode(this._constructionElement.getFirstChild(), Constants._TAG_X509DATA,i); if (e != null) { return new X509Data(e, this._baseURI); } return null; } /** * Method itemEncryptedKey * * @param i * @return the asked EncryptedKey element, null if the index is too big * @throws XMLSecurityException */ public EncryptedKey itemEncryptedKey(int i) throws XMLSecurityException { Element e = XMLUtils.selectXencNode(this._constructionElement.getFirstChild(), EncryptionConstants._TAG_ENCRYPTEDKEY,i); if (e != null) { XMLCipher cipher = XMLCipher.getInstance(); cipher.init(XMLCipher.UNWRAP_MODE, null); return cipher.loadEncryptedKey(e); } return null; } /** * Method itemUnknownElement * * @param i index * @return the element number of the unknown elemens */ public Element itemUnknownElement(int i) { NodeList nl = this._constructionElement.getChildNodes(); int res = 0; for (int j = 0; j < nl.getLength(); j++) { Node current = nl.item(j); /** * $todo$ using this method, we don't see unknown Elements * from Signature NS; revisit */ if ((current.getNodeType() == Node.ELEMENT_NODE) && current.getNamespaceURI() .equals(Constants.SignatureSpecNS)) { res++; if (res == i) { return (Element) current; } } } return null; } /** * Method isEmpty * * @return true if the element has no descedants. */ public boolean isEmpty() { return this._constructionElement.getFirstChild()==null; } /** * Method containsKeyName * * @return If the KeyInfo contains a KeyName node */ public boolean containsKeyName() { return this.lengthKeyName() > 0; } /** * Method containsKeyValue * * @return If the KeyInfo contains a KeyValue node */ public boolean containsKeyValue() { return this.lengthKeyValue() > 0; } /** * Method containsMgmtData * * @return If the KeyInfo contains a MgmtData node */ public boolean containsMgmtData() { return this.lengthMgmtData() > 0; } /** * Method containsPGPData * * @return If the KeyInfo contains a PGPData node */ public boolean containsPGPData() { return this.lengthPGPData() > 0; } /** * Method containsRetrievalMethod * * @return If the KeyInfo contains a RetrievalMethod node */ public boolean containsRetrievalMethod() { return this.lengthRetrievalMethod() > 0; } /** * Method containsSPKIData * * @return If the KeyInfo contains a SPKIData node */ public boolean containsSPKIData() { return this.lengthSPKIData() > 0; } /** * Method containsUnknownElement * * @return If the KeyInfo contains a UnknownElement node */ public boolean containsUnknownElement() { return this.lengthUnknownElement() > 0; } /** * Method containsX509Data * * @return If the KeyInfo contains a X509Data node */ public boolean containsX509Data() { return this.lengthX509Data() > 0; } /** * This method returns the public key. * * @return If the KeyInfo contains a PublicKey node * @throws KeyResolverException */ public PublicKey getPublicKey() throws KeyResolverException { PublicKey pk = this.getPublicKeyFromInternalResolvers(); if (pk != null) { if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I could find a key using the per-KeyInfo key resolvers"); return pk; } if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I couldn't find a key using the per-KeyInfo key resolvers"); pk = this.getPublicKeyFromStaticResolvers(); if (pk != null) { if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I could find a key using the system-wide key resolvers"); return pk; } if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I couldn't find a key using the system-wide key resolvers"); return null; } /** * Searches the library wide keyresolvers for public keys * * @return The publick contained in this Node. * @throws KeyResolverException */ PublicKey getPublicKeyFromStaticResolvers() throws KeyResolverException { for (int i = 0; i < KeyResolver.length(); i++) { KeyResolver keyResolver = KeyResolver.item(i); Node currentChild=this._constructionElement.getFirstChild(); while (currentChild!=null) { if (currentChild.getNodeType() == Node.ELEMENT_NODE) { if (this._storageResolvers.size() == 0) { // if we do not have storage resolvers, we verify with null StorageResolver storage = null; if (keyResolver.canResolve((Element) currentChild, this.getBaseURI(), storage)) { PublicKey pk = keyResolver.resolvePublicKey((Element) currentChild, this.getBaseURI(), storage); if (pk != null) { return pk; } } } else { for (int k = 0; k < this._storageResolvers.size(); k++) { StorageResolver storage = (StorageResolver) this._storageResolvers.get(k); if (keyResolver.canResolve((Element) currentChild, this.getBaseURI(), storage)) { PublicKey pk = keyResolver.resolvePublicKey((Element) currentChild, this.getBaseURI(), storage); if (pk != null) { return pk; } } } } } currentChild=currentChild.getNextSibling(); } } return null; } /** * Searches the per-KeyInfo keyresolvers for public keys * * @return The publick contained in this Node. * @throws KeyResolverException */ PublicKey getPublicKeyFromInternalResolvers() throws KeyResolverException { for (int i = 0; i < this.lengthInternalKeyResolver(); i++) { KeyResolverSpi keyResolver = this.itemInternalKeyResolver(i); if (true) if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Try " + keyResolver.getClass().getName()); Node currentChild=this._constructionElement.getFirstChild(); while (currentChild!=null) { if (currentChild.getNodeType() == Node.ELEMENT_NODE) { if (this._storageResolvers.size() == 0) { // if we do not have storage resolvers, we verify with null StorageResolver storage = null; if (keyResolver.engineCanResolve((Element) currentChild, this.getBaseURI(), storage)) { PublicKey pk = keyResolver .engineResolvePublicKey((Element) currentChild, this .getBaseURI(), storage); if (pk != null) { return pk; } } } else { for (int k = 0; k < this._storageResolvers.size(); k++) { StorageResolver storage = (StorageResolver) this._storageResolvers.get(k); if (keyResolver.engineCanResolve((Element) currentChild, this.getBaseURI(), storage)) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?