2 * Copyright 2001-2007 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @file saml/binding/SAMLArtifact.h
20 * Base class for SAML 1.x and 2.0 artifacts
23 #ifndef __saml_artifact_h__
24 #define __saml_artifact_h__
26 #include <saml/base.h>
29 #include <xmltooling/unicode.h>
34 * Base class for SAML 1.x and 2.0 artifacts.
36 class SAML_API SAMLArtifact
38 SAMLArtifact& operator=(const SAMLArtifact& src);
40 virtual ~SAMLArtifact() {}
43 * Returns artifact encoded into null-terminated base64 for transmission.
45 virtual std::string encode() const;
48 * Builds a duplicate, independent artifact of the same type.
50 * @return the new artifact
52 virtual SAMLArtifact* clone() const=0;
55 * Returns all of the raw binary data that makes up the artifact.
56 * The result is NOT null-terminated.
58 * @return the binary artifact data
60 virtual std::string getBytes() const {
65 * Returns the binary type code of the artifact.
66 * The result MAY contain embedded null characters.
68 * @return the binary type code
70 virtual std::string getTypeCode() const {
71 return m_raw.substr(0,TYPECODE_LENGTH);
75 * Returns the binary artifact data following the type code.
76 * The result MAY contain embedded null characters.
78 * @return the binary artifact data
80 virtual std::string getRemainingArtifact() const {
81 return m_raw.substr(TYPECODE_LENGTH);
85 * Returns a string that identifies the source of the artifact.
86 * The exact form this takes depends on the type but should match
87 * the syntax needed for metadata lookup.
89 * @return null-terminated source string
91 virtual std::string getSource() const=0;
94 * Returns the binary data that references the message (2.0) or assertion (1.x)
95 * The exact form this takes depends on the type.
96 * The result MAY contain embedded null characters.
98 * @return the binary reference data
100 virtual std::string getMessageHandle() const=0;
102 /** Length of type code */
103 static const unsigned int TYPECODE_LENGTH;
106 * Parses a base64-encoded null-terminated string into an artifact,
107 * if the type is known.
109 * @param s base64-encoded artifact
110 * @return the decoded artifact
112 static SAMLArtifact* parse(const char* s);
115 * Parses a base64-encoded null-terminated string into an artifact,
116 * if the type is known.
118 * @param s base64-encoded artifact
119 * @return the decoded artifact
121 static SAMLArtifact* parse(const XMLCh* s) {
122 xmltooling::auto_ptr_char temp(s);
123 return parse(temp.get());
127 * Converts binary data to hex notation.
129 * @param s the bytes to convert
130 * @return the data in hex form, 2 characters per byte
132 static std::string toHex(const std::string& s);
138 * Decodes a base64-encoded artifact into its raw form.
140 * @param s NULL-terminated base64-encoded string
142 SAMLArtifact(const char* s);
144 SAMLArtifact(const SAMLArtifact& src) : m_raw(src.m_raw) {}
146 /** Raw binary data that makes up an artifact. */
150 DECL_XMLTOOLING_EXCEPTION(ArtifactException,SAML_EXCEPTIONAPI(SAML_API),opensaml,xmltooling::XMLToolingException,Exceptions related to artifact parsing);
153 * Registers SAMLArtifact subclasses into the runtime.
155 void SAML_API registerSAMLArtifacts();
158 #endif /* __saml_artifact_h__ */