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 * SAML2ArtifactType0004.cpp
20 * Type 0x0004 SAML 2.0 artifact class
24 #include "saml2/binding/SAML2ArtifactType0004.h"
26 using namespace opensaml::saml2p;
27 using namespace opensaml;
28 using namespace xmltooling;
33 SAMLArtifact* SAML_DLLLOCAL SAML2ArtifactType0004Factory(const char* const & s)
35 return new SAML2ArtifactType0004(s);
40 const unsigned int SAML2ArtifactType0004::SOURCEID_LENGTH = 20;
41 const unsigned int SAML2ArtifactType0004::HANDLE_LENGTH = 20;
43 SAML2ArtifactType0004::SAML2ArtifactType0004(const char* s) : SAML2Artifact(s)
45 // The base class does the work, we just do the checking.
46 if (m_raw.size() != TYPECODE_LENGTH + INDEX_LENGTH + SOURCEID_LENGTH + HANDLE_LENGTH)
47 throw ArtifactException("Type 0x0004 artifact is of incorrect length.");
48 else if (m_raw[0] != 0x0 || m_raw[1] != 0x4)
49 throw ArtifactException(
50 string("Type 0x0004 artifact given an artifact of invalid type (") + toHex(getTypeCode()) + ")."
54 SAML2ArtifactType0004::SAML2ArtifactType0004(const string& sourceid, int index)
56 if (sourceid.size()!=SOURCEID_LENGTH)
57 throw ArtifactException("Type 0x0004 artifact sourceid of incorrect length.");
58 if (index < 0 || index > (1 << 16)-1)
59 throw ArtifactException("Type 0x0004 artifact index is invalid.");
62 m_raw+=(char)(index / 256);
63 m_raw+=(char)(index % 256);
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 SAML2ArtifactType0004::SAML2ArtifactType0004(const string& sourceid, int index, const string& handle)
73 if (sourceid.size()!=SOURCEID_LENGTH)
74 throw ArtifactException("Type 0x0004 artifact sourceid of incorrect length.");
75 if (index < 0 || index > (1 << 16)-1)
76 throw ArtifactException("Type 0x0004 artifact index is invalid.");
77 if (handle.size()!=HANDLE_LENGTH)
78 throw ArtifactException("Type 0x0004 artifact message handle of incorrect length.");
81 m_raw+=(char)(index / 256);
82 m_raw+=(char)(index % 256);
83 m_raw.append(sourceid,0,SOURCEID_LENGTH);
84 m_raw.append(handle,0,HANDLE_LENGTH);