2 * Copyright 2001-2009 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 * SAMLArtifactType0002.cpp
20 * Type 0x0002 SAML 1.x artifact class.
24 #include "saml1/binding/SAMLArtifactType0002.h"
26 using namespace opensaml::saml1p;
27 using namespace opensaml;
28 using namespace xmltooling;
33 SAMLArtifact* SAML_DLLLOCAL SAMLArtifactType0002Factory(const char* const & s)
35 return new SAMLArtifactType0002(s);
40 const unsigned int SAMLArtifactType0002::HANDLE_LENGTH = 20;
42 SAMLArtifactType0002::SAMLArtifactType0002(const SAMLArtifactType0002& src) : SAMLArtifact(src)
46 SAMLArtifactType0002::SAMLArtifactType0002(const char* s) : SAMLArtifact(s)
48 // The base class does the work, we just do the checking.
49 if (m_raw.size() <= TYPECODE_LENGTH + HANDLE_LENGTH)
50 throw ArtifactException("Type 0x0002 artifact given artifact of incorrect length.");
51 else if (m_raw[0] != 0x0 || m_raw[1] != 0x2)
52 throw ArtifactException(
53 string("Type 0x0002 artifact given artifact of invalid type (") + toHex(getTypeCode()) + ")."
57 SAMLArtifactType0002::SAMLArtifactType0002(const string& sourceLocation)
59 if (sourceLocation.empty())
60 throw ArtifactException("Type 0x0002 artifact with empty source location.");
63 char buf[HANDLE_LENGTH];
64 SAMLConfig::getConfig().generateRandomBytes(buf,HANDLE_LENGTH);
65 for (int i=0; i<HANDLE_LENGTH; i++)
67 m_raw+=sourceLocation;
70 SAMLArtifactType0002::SAMLArtifactType0002(const string& sourceLocation, const string& handle)
72 if (sourceLocation.empty())
73 throw ArtifactException("Type 0x0002 artifact with empty source location.");
74 if (handle.size()!=HANDLE_LENGTH)
75 throw ArtifactException("Type 0x0002 artifact with handle of incorrect length.");
78 m_raw.append(handle,0,HANDLE_LENGTH);
79 m_raw+=sourceLocation;
82 SAMLArtifactType0002::~SAMLArtifactType0002()
86 SAMLArtifactType0002* SAMLArtifactType0002::clone() const
88 return new SAMLArtifactType0002(*this);
91 string SAMLArtifactType0002::getMessageHandle() const
93 return m_raw.substr(TYPECODE_LENGTH, HANDLE_LENGTH); // bytes 3-22
96 string SAMLArtifactType0002::getSource() const
98 return m_raw.c_str() + TYPECODE_LENGTH + HANDLE_LENGTH; // bytes 23-terminating null