+/*\r
+ * Copyright 2001-2006 Internet2\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/**\r
+ * @file saml/SAMLArtifact.h\r
+ * \r
+ * Base class for SAML 1.x and 2.0 artifacts \r
+ */\r
+\r
+#ifndef __saml_artifact_h__\r
+#define __saml_artifact_h__\r
+\r
+#include <saml/base.h>\r
+\r
+#include <string>\r
+#include <xmltooling/unicode.h>\r
+\r
+namespace opensaml {\r
+\r
+ /**\r
+ * Base class for SAML 1.x and 2.0 artifacts.\r
+ */\r
+ class SAML_API SAMLArtifact\r
+ {\r
+ SAMLArtifact& operator=(const SAMLArtifact& src);\r
+ public:\r
+ virtual ~SAMLArtifact() {}\r
+\r
+ /**\r
+ * Returns artifact encoded into null-terminated base64 for transmission.\r
+ */\r
+ virtual std::string encode() const;\r
+ \r
+ /**\r
+ * Builds a duplicate, independent artifact of the same type.\r
+ * \r
+ * @return the new artifact\r
+ */\r
+ virtual SAMLArtifact* clone() const=0;\r
+ \r
+ /**\r
+ * Returns all of the raw binary data that makes up the artifact.\r
+ * The result is NOT null-terminated.\r
+ * \r
+ * @return the binary artifact data\r
+ */\r
+ virtual std::string getBytes() const {\r
+ return m_raw;\r
+ }\r
+\r
+ /**\r
+ * Returns the binary type code of the artifact.\r
+ * The result is NOT null-terminated.\r
+ * \r
+ * @return the binary type code\r
+ */\r
+ virtual std::string getTypeCode() const {\r
+ return m_raw.substr(0,TYPECODE_LENGTH);\r
+ }\r
+ \r
+ /**\r
+ * Returns the binary artifact data following the type code.\r
+ * The result is NOT null-terminated.\r
+ * \r
+ * @return the binary artifact data\r
+ */\r
+ virtual std::string getRemainingArtifact() const {\r
+ return m_raw.substr(TYPECODE_LENGTH);\r
+ }\r
+ \r
+ /**\r
+ * Returns the binary data that identifies the source of the artifact.\r
+ * The exact form this takes depends on the type.\r
+ * The result is NOT null-terminated.\r
+ * \r
+ * @return the binary source data\r
+ */\r
+ virtual std::string getSource() const=0;\r
+ \r
+ /**\r
+ * Returns the binary data that references the message (2.0) or assertion (1.x)\r
+ * The exact form this takes depends on the type.\r
+ * The result is NOT null-terminated.\r
+ * \r
+ * @return the binary reference data\r
+ */\r
+ virtual std::string getMessageHandle() const=0;\r
+\r
+ /** Length of type code */ \r
+ static const unsigned int TYPECODE_LENGTH;\r
+\r
+ /**\r
+ * Parses a base64-encoded null-terminated string into an artifact,\r
+ * if the type is known.\r
+ * \r
+ * @param s base64-encoded artifact\r
+ * @return the decoded artifact\r
+ */\r
+ static SAMLArtifact* parse(const char* s);\r
+ \r
+ /**\r
+ * Parses a base64-encoded null-terminated string into an artifact,\r
+ * if the type is known.\r
+ * \r
+ * @param s base64-encoded artifact\r
+ * @return the decoded artifact\r
+ */\r
+ static SAMLArtifact* parse(const XMLCh* s) {\r
+ xmltooling::auto_ptr_char temp(s);\r
+ return parse(temp.get());\r
+ }\r
+\r
+ /**\r
+ * Converts binary data to hex notation.\r
+ * \r
+ * @param s the bytes to convert\r
+ * @return the data in hex form, 2 characters per byte\r
+ */\r
+ static std::string toHex(const std::string& s);\r
+ \r
+ protected:\r
+ SAMLArtifact() {}\r
+\r
+ /**\r
+ * Decodes a base64-encoded artifact into its raw form.\r
+ * \r
+ * @param s NULL-terminated base64-encoded string \r
+ */ \r
+ SAMLArtifact(const char* s);\r
+\r
+ SAMLArtifact(const SAMLArtifact& src) : m_raw(src.m_raw) {}\r
+ \r
+ /** Raw binary data that makes up an artifact. */\r
+ std::string m_raw;\r
+ };\r
+\r
+ DECL_XMLTOOLING_EXCEPTION(ArtifactException,SAML_EXCEPTIONAPI(SAML_API),opensaml,xmltooling::XMLToolingException,Exceptions related to artifact parsing);\r
+ \r
+ /**\r
+ * Registers SAMLArtifact subclasses into the runtime.\r
+ */\r
+ void SAML_API registerSAMLArtifacts();\r
+};\r
+\r
+#endif /* __saml_artifact_h__ */\r