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 * SAMLArtifactType0001.cpp
20 * Type 0x0001 SAML 1.x artifact class.
24 #include "saml1/binding/SAMLArtifactType0001.h"
26 using namespace opensaml::saml1p;
27 using namespace opensaml;
28 using namespace xmltooling;
33 SAMLArtifact* SAML_DLLLOCAL SAMLArtifactType0001Factory(const char* const & s)
35 return new SAMLArtifactType0001(s);
40 const unsigned int SAMLArtifactType0001::SOURCEID_LENGTH = 20;
41 const unsigned int SAMLArtifactType0001::HANDLE_LENGTH = 20;
43 SAMLArtifactType0001::SAMLArtifactType0001(const SAMLArtifactType0001& src) : SAMLArtifact(src)
47 SAMLArtifactType0001::SAMLArtifactType0001(const char* s) : SAMLArtifact(s)
49 // The base class does the work, we just do the checking.
50 if (m_raw.size() != TYPECODE_LENGTH + SOURCEID_LENGTH + HANDLE_LENGTH)
51 throw ArtifactException("Type 0x0001 artifact is of incorrect length.");
52 else if (m_raw[0] != 0x0 || m_raw[1] != 0x1)
53 throw ArtifactException(
54 string("Type 0x0001 artifact given an artifact of invalid type (") + toHex(getTypeCode()) + ")."
58 SAMLArtifactType0001::SAMLArtifactType0001(const string& sourceid)
60 if (sourceid.size()!=SOURCEID_LENGTH)
61 throw ArtifactException("Type 0x0001 artifact sourceid of incorrect length.");
64 m_raw.append(sourceid,0,SOURCEID_LENGTH);
65 char buf[HANDLE_LENGTH];
66 SAMLConfig::getConfig().generateRandomBytes(buf,HANDLE_LENGTH);
67 for (int i=0; i<HANDLE_LENGTH; i++)
71 SAMLArtifactType0001::SAMLArtifactType0001(const string& sourceid, const string& handle)
73 if (sourceid.size()!=SOURCEID_LENGTH)
74 throw ArtifactException("Type 0x0001 artifact sourceid of incorrect length.");
75 if (handle.size()!=HANDLE_LENGTH)
76 throw ArtifactException("Type 0x0001 artifact assertion handle of incorrect length.");
79 m_raw.append(sourceid,0,SOURCEID_LENGTH);
80 m_raw.append(handle,0,HANDLE_LENGTH);
83 SAMLArtifactType0001::~SAMLArtifactType0001()
87 SAMLArtifactType0001* SAMLArtifactType0001::clone() const
89 return new SAMLArtifactType0001(*this);
92 string SAMLArtifactType0001::getSource() const
94 return toHex(getSourceID());
97 string SAMLArtifactType0001::getSourceID() const
99 return m_raw.substr(TYPECODE_LENGTH,SOURCEID_LENGTH); // bytes 3-22
102 string SAMLArtifactType0001::getMessageHandle() const
104 return m_raw.substr(TYPECODE_LENGTH+SOURCEID_LENGTH, HANDLE_LENGTH); // bytes 23-42