You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by bl...@apache.org on 2003/10/26 12:33:13 UTC

cvs commit: xml-security/c/src/xenc/impl XENCEncryptedDataImpl.hpp XENCEncryptedKeyImpl.hpp XENCEncryptedTypeImpl.cpp XENCEncryptedTypeImpl.hpp

blautenb    2003/10/26 03:33:13

  Modified:    c/src/tools/xtest xtest.cpp
               c/src/xenc XENCEncryptedType.hpp
               c/src/xenc/impl XENCEncryptedDataImpl.hpp
                        XENCEncryptedKeyImpl.hpp XENCEncryptedTypeImpl.cpp
                        XENCEncryptedTypeImpl.hpp
  Log:
  Support for MimeType and Encoding Attributes in EncryptedType structures
  
  Revision  Changes    Path
  1.26      +28 -1     xml-security/c/src/tools/xtest/xtest.cpp
  
  Index: xtest.cpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/tools/xtest/xtest.cpp,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- xtest.cpp	19 Oct 2003 11:01:01 -0000	1.25
  +++ xtest.cpp	26 Oct 2003 11:33:13 -0000	1.26
  @@ -256,6 +256,15 @@
   
   };
   
  +XMLCh s_tstEncoding[] = {
  +	chLatin_B, chLatin_a, chLatin_s, chLatin_e, chDigit_6, chDigit_4, chNull
  +};
  +
  +XMLCh s_tstMimeType[] = {
  +	chLatin_i, chLatin_m, chLatin_a, chLatin_g, chLatin_e,
  +	chForwardSlash, chLatin_p, chLatin_n, chLatin_g, chNull
  +};
  +
   // --------------------------------------------------------------------------------
   //           Some test keys
   // --------------------------------------------------------------------------------
  @@ -983,6 +992,12 @@
   		cerr << "done\nAppending a <KeyName> ... ";
   		XENCEncryptedData * encryptedData = cipher->getEncryptedData();
   		encryptedData->appendKeyName(s_tstKeyName);
  +		cerr << "done\nAdding Encoding and MimeType ... ";
  +
  +		// Add MimeType and Encoding
  +		encryptedData->setEncodingURI(s_tstEncoding);
  +		encryptedData->setMimeType(s_tstMimeType);
  +
   		cerr << "done\nSearching for <category> ... ";
   
   		DOMNode * t = findNode(doc, MAKE_UNICODE_STRING("category"));
  @@ -1075,6 +1090,18 @@
   		}
   		else
   			cerr << "yes." << endl;
  +
  +		cerr << "Checking MimeType and Encoding ... ";
  +		if (encryptedData->getMimeType() == NULL || !strEquals(encryptedData->getMimeType(), s_tstMimeType)) {
  +			cerr << "Bad MimeType" << endl;
  +			exit(1);
  +		}
  +		if (encryptedData->getEncodingURI() == NULL || !strEquals(encryptedData->getEncodingURI(), s_tstEncoding)) {
  +			cerr << "Bad Encoding" << endl;
  +			exit(1);
  +		}
  +
  +		cerr << "OK" << endl;
   
   	}
   	catch (XSECException &e)
  
  
  
  1.8       +66 -1     xml-security/c/src/xenc/XENCEncryptedType.hpp
  
  Index: XENCEncryptedType.hpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/xenc/XENCEncryptedType.hpp,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XENCEncryptedType.hpp	26 Oct 2003 10:32:32 -0000	1.7
  +++ XENCEncryptedType.hpp	26 Oct 2003 11:33:13 -0000	1.8
  @@ -174,6 +174,37 @@
   
   	virtual const XMLCh * getTypeURI(void) const = 0;
   
  +	/**
  +	 * \brief Get the MimeType of the EncryptedType
  +	 *
  +	 * If this object is an EncryptedData, it <em>may</em> have a 
  +	 * MimeType attribute that "describes the media type of the 
  +	 * data which has been encrypted" (from the XML Encryption spec).
  +	 *
  +	 * The XML-Security-C library makes no use of this attribute, but
  +	 * it provides these functions to allow applications to set and get.
  +	 *
  +	 * @returns a pointer to the MimeType string (owned by the library)
  +	 * or NULL if no MimeType is set
  +	 */
  +
  +	virtual const XMLCh * getMimeType(void) const = 0;
  +
  +	/**
  +	 * \brief Get the Encoding of the EncryptedType
  +	 *
  +	 * If this object is an EncryptedData, it <em>may</em> have an
  +	 * encoding attribute that describes how the data has been encoded
  +	 * prior to encryption.  (E.g. http://www.w3.org/2000/09/xmldsig#base64)
  +	 *
  +	 * The XML-Security-C library makes no use of this attribute, but
  +	 * it provides these functions to allow applications to set and get.
  +	 *
  +	 * @returns A string (owned by the library) providing the encoding URI
  +	 */
  +
  +	virtual const XMLCh * getEncodingURI(void) const = 0;
  +
   	//@}
   
   	/** @name Setter interface methods */
  @@ -192,6 +223,40 @@
   	 */
   
   	virtual void setTypeURI(const XMLCh * uri) = 0;
  +
  +	/**
  +	 * \brief Set the MimeType of the EncryptedType
  +	 *
  +	 * If this object is an EncryptedData, it <em>may</em> have a 
  +	 * MimeType attribute that "describes the media type of the 
  +	 * data which has been encrypted" (from the XML Encryption spec).
  +	 *
  +	 * The XML-Security-C library makes no use of this attribute, but
  +	 * it provides these functions to allow applications to set and get.
  +	 *
  +	 * @param mimeType String to set in the MimeType attribute.
  +	 * @note no checking of this string is done by the library - it
  +	 * simply sets the value of the MimeType attribute to this value.
  +	 */
  +
  +	virtual void setMimeType(const XMLCh * mimeType) = 0;
  +
  +	/**
  +	 * \brief Set the Encoding of the EncryptedType
  +	 *
  +	 * If this object is an EncryptedData, it <em>may</em> have an
  +	 * encoding attribute that describes how the data has been encoded
  +	 * prior to encryption.  (E.g. http://www.w3.org/2000/09/xmldsig#base64)
  +	 *
  +	 * The XML-Security-C library makes no use of this attribute, but
  +	 * it provides these functions to allow applications to set and get.
  +	 *
  +	 * @param encoding String (URI) to set in the Encoding attribute.
  +	 * @note no checking of this string is done by the library - it
  +	 * simply sets the value of the Encoding attribute to this value.
  +	 */
  +
  +	virtual void setEncodingURI(const XMLCh * uri) = 0;
   
   	//@}
   
  
  
  
  1.8       +9 -2      xml-security/c/src/xenc/impl/XENCEncryptedDataImpl.hpp
  
  Index: XENCEncryptedDataImpl.hpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/xenc/impl/XENCEncryptedDataImpl.hpp,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XENCEncryptedDataImpl.hpp	26 Oct 2003 10:32:33 -0000	1.7
  +++ XENCEncryptedDataImpl.hpp	26 Oct 2003 11:33:13 -0000	1.8
  @@ -120,11 +120,18 @@
   	// Get methods
   	virtual const XMLCh * getTypeURI(void) const
   		{return XENCEncryptedTypeImpl::getTypeURI();}
  +	virtual const XMLCh * getMimeType(void) const
  +		{return XENCEncryptedTypeImpl::getMimeType();}
  +	virtual const XMLCh * getEncodingURI(void) const
  +		{return XENCEncryptedTypeImpl::getEncodingURI();}
   
   	// Set methods
   	virtual void setTypeURI(const XMLCh * uri)
   		{XENCEncryptedTypeImpl::setTypeURI(uri);}
  -
  +	virtual void setMimeType(const XMLCh * mimeType)
  +		{XENCEncryptedTypeImpl::setMimeType(mimeType);}
  +	virtual void setEncodingURI(const XMLCh * uri)
  +		{XENCEncryptedTypeImpl::setEncodingURI(uri);}
   
   private:
   
  
  
  
  1.3       +9 -1      xml-security/c/src/xenc/impl/XENCEncryptedKeyImpl.hpp
  
  Index: XENCEncryptedKeyImpl.hpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/xenc/impl/XENCEncryptedKeyImpl.hpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XENCEncryptedKeyImpl.hpp	26 Oct 2003 10:32:33 -0000	1.2
  +++ XENCEncryptedKeyImpl.hpp	26 Oct 2003 11:33:13 -0000	1.3
  @@ -123,10 +123,18 @@
   	// Get methods
   	virtual const XMLCh * getTypeURI(void) const
   		{return XENCEncryptedTypeImpl::getTypeURI();}
  +	virtual const XMLCh * getMimeType(void) const
  +		{return XENCEncryptedTypeImpl::getMimeType();}
  +	virtual const XMLCh * getEncodingURI(void) const
  +		{return XENCEncryptedTypeImpl::getEncodingURI();}
   
   	// Set methods
   	virtual void setTypeURI(const XMLCh * uri)
   		{XENCEncryptedTypeImpl::setTypeURI(uri);}
  +	virtual void setMimeType(const XMLCh * mimeType)
  +		{XENCEncryptedTypeImpl::setMimeType(mimeType);}
  +	virtual void setEncodingURI(const XMLCh * uri)
  +		{XENCEncryptedTypeImpl::setEncodingURI(uri);}
   
   private:
   
  
  
  
  1.9       +116 -3    xml-security/c/src/xenc/impl/XENCEncryptedTypeImpl.cpp
  
  Index: XENCEncryptedTypeImpl.cpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/xenc/impl/XENCEncryptedTypeImpl.cpp,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- XENCEncryptedTypeImpl.cpp	26 Oct 2003 10:32:33 -0000	1.8
  +++ XENCEncryptedTypeImpl.cpp	26 Oct 2003 11:33:13 -0000	1.9
  @@ -149,6 +149,33 @@
   	chNull
   };
   
  +static XMLCh s_MimeType[] = {
  +	
  +	chLatin_M,
  +	chLatin_i,
  +	chLatin_m,
  +	chLatin_e,
  +	chLatin_T,
  +	chLatin_y,
  +	chLatin_p,
  +	chLatin_e,
  +	chNull
  +};
  +
  +
  +static XMLCh s_Encoding[] = {
  +	
  +	chLatin_E,
  +	chLatin_n,
  +	chLatin_c,
  +	chLatin_o,
  +	chLatin_d,
  +	chLatin_i,
  +	chLatin_n,
  +	chLatin_g,
  +	chNull
  +};
  +
   // --------------------------------------------------------------------------------
   //			Constructors and Destructors
   // --------------------------------------------------------------------------------
  @@ -161,7 +188,9 @@
   mp_cipherData(NULL),
   mp_encryptionMethod(NULL),
   m_keyInfoList(env),
  -mp_typeAttributeNode(NULL) {
  +mp_typeAttributeNode(NULL),
  +mp_mimeTypeAttributeNode(NULL),
  +mp_encodingAttributeNode(NULL) {
   
   }
   
  @@ -174,7 +203,9 @@
   mp_cipherData(NULL),
   mp_encryptionMethod(NULL),
   m_keyInfoList(env),
  -mp_typeAttributeNode(NULL) {
  +mp_typeAttributeNode(NULL),
  +mp_mimeTypeAttributeNode(NULL),
  +mp_encodingAttributeNode(NULL) {
   
   }
   
  @@ -208,6 +239,12 @@
   	// Type
   	mp_typeAttributeNode = atts->getNamedItemNS(DSIGConstants::s_unicodeStrURIXENC,
   												s_Type);
  +	// MimeType
  +	mp_mimeTypeAttributeNode = atts->getNamedItemNS(DSIGConstants::s_unicodeStrURIXENC,
  +												s_MimeType);
  +	// Encoding
  +	mp_encodingAttributeNode = atts->getNamedItemNS(DSIGConstants::s_unicodeStrURIXENC,
  +												s_Encoding);
   
   	// Don't know what the node name should be (held by super class), 
   	// so go straight to the children
  @@ -494,6 +531,82 @@
   
   			throw XSECException(XSECException::InternalError,
   				"XENCEncryptedTypeImpl::setTypeURI - Cannot find the attribute I just added");
  +
  +		}
  +
  +	}
  +}
  +
  +// --------------------------------------------------------------------------------
  +//			MimeType handling
  +// --------------------------------------------------------------------------------
  +
  +const XMLCh * XENCEncryptedTypeImpl::getMimeType(void) const {
  +
  +	if (mp_mimeTypeAttributeNode != NULL)
  +		return mp_mimeTypeAttributeNode->getNodeValue();
  +
  +	return NULL;
  +
  +}
  +
  +void XENCEncryptedTypeImpl::setMimeType(const XMLCh * mimeType) {
  +
  +	if (mp_mimeTypeAttributeNode != NULL) {
  +		mp_mimeTypeAttributeNode->setNodeValue(mimeType);
  +	}
  +	else {
  +
  +		// Need to create the node
  +		DOMElement * typeElt = static_cast<DOMElement *>(mp_encryptedTypeNode);
  +
  +		typeElt->setAttributeNS(DSIGConstants::s_unicodeStrURIXENC, s_MimeType, mimeType);
  +
  +		DOMNamedNodeMap *atts = mp_encryptedTypeNode->getAttributes();
  +		mp_mimeTypeAttributeNode = atts->getNamedItemNS(DSIGConstants::s_unicodeStrURIXENC,
  +												s_MimeType);
  +		if (mp_mimeTypeAttributeNode = NULL) {
  +
  +			throw XSECException(XSECException::InternalError,
  +				"XENCEncryptedTypeImpl::setMimeType - Cannot find the attribute I just added");
  +
  +		}
  +
  +	}
  +}
  +
  +// --------------------------------------------------------------------------------
  +//			Encoding handling
  +// --------------------------------------------------------------------------------
  +
  +const XMLCh * XENCEncryptedTypeImpl::getEncodingURI(void) const {
  +
  +	if (mp_encodingAttributeNode != NULL)
  +		return mp_encodingAttributeNode->getNodeValue();
  +
  +	return NULL;
  +
  +}
  +
  +void XENCEncryptedTypeImpl::setEncodingURI(const XMLCh * uri) {
  +
  +	if (mp_encodingAttributeNode != NULL) {
  +		mp_encodingAttributeNode->setNodeValue(uri);
  +	}
  +	else {
  +
  +		// Need to create the node
  +		DOMElement * typeElt = static_cast<DOMElement *>(mp_encryptedTypeNode);
  +
  +		typeElt->setAttributeNS(DSIGConstants::s_unicodeStrURIXENC, s_Encoding, uri);
  +
  +		DOMNamedNodeMap *atts = mp_encryptedTypeNode->getAttributes();
  +		mp_encodingAttributeNode = atts->getNamedItemNS(DSIGConstants::s_unicodeStrURIXENC,
  +												s_Encoding);
  +		if (mp_encodingAttributeNode = NULL) {
  +
  +			throw XSECException(XSECException::InternalError,
  +				"XENCEncryptedTypeImpl::setEncodingURI - Cannot find the attribute I just added");
   
   		}
   
  
  
  
  1.9       +9 -3      xml-security/c/src/xenc/impl/XENCEncryptedTypeImpl.hpp
  
  Index: XENCEncryptedTypeImpl.hpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/xenc/impl/XENCEncryptedTypeImpl.hpp,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- XENCEncryptedTypeImpl.hpp	26 Oct 2003 10:32:33 -0000	1.8
  +++ XENCEncryptedTypeImpl.hpp	26 Oct 2003 11:33:13 -0000	1.9
  @@ -121,11 +121,13 @@
   
   	// Get methods
   	virtual const XMLCh * getTypeURI(void) const;
  +	virtual const XMLCh * getMimeType(void) const;
  +	virtual const XMLCh * getEncodingURI(void) const;
   
   	// Set methods
   	virtual void setTypeURI(const XMLCh * uri);
  -
  -
  +	virtual void setMimeType(const XMLCh * mimeType);
  +	virtual void setEncodingURI(const XMLCh * uri);
   
   protected:
   
  @@ -153,6 +155,10 @@
   	// Type URI
   	XERCES_CPP_NAMESPACE_QUALIFIER DOMNode
   								* mp_typeAttributeNode;
  +	XERCES_CPP_NAMESPACE_QUALIFIER DOMNode
  +								* mp_mimeTypeAttributeNode;
  +	XERCES_CPP_NAMESPACE_QUALIFIER DOMNode
  +								* mp_encodingAttributeNode;
   
   	friend class XENCCipherImpl;
   };