2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
22 * SAML2ArtifactType0004.cpp
24 * Type 0x0004 SAML 2.0 artifact class.
28 #include "saml2/binding/SAML2ArtifactType0004.h"
30 using namespace opensaml::saml2p;
31 using namespace opensaml;
32 using namespace xmltooling;
37 SAMLArtifact* SAML_DLLLOCAL SAML2ArtifactType0004Factory(const char* const & s)
39 return new SAML2ArtifactType0004(s);
44 const unsigned int SAML2ArtifactType0004::SOURCEID_LENGTH = 20;
45 const unsigned int SAML2ArtifactType0004::HANDLE_LENGTH = 20;
47 SAML2ArtifactType0004::SAML2ArtifactType0004(const char* s) : SAML2Artifact(s)
49 // The base class does the work, we just do the checking.
50 if (m_raw.size() != TYPECODE_LENGTH + INDEX_LENGTH + SOURCEID_LENGTH + HANDLE_LENGTH)
51 throw ArtifactException("Type 0x0004 artifact is of incorrect length.");
52 else if (m_raw[0] != 0x0 || m_raw[1] != 0x4)
53 throw ArtifactException(
54 string("Type 0x0004 artifact given an artifact of invalid type (") + toHex(getTypeCode()) + ")."
58 SAML2ArtifactType0004::SAML2ArtifactType0004(const string& sourceid, int index)
60 if (sourceid.size()!=SOURCEID_LENGTH)
61 throw ArtifactException("Type 0x0004 artifact sourceid of incorrect length.");
62 if (index < 0 || index > (1 << 16)-1)
63 throw ArtifactException("Type 0x0004 artifact index is invalid.");
66 m_raw+=(char)(index / 256);
67 m_raw+=(char)(index % 256);
68 m_raw.append(sourceid,0,SOURCEID_LENGTH);
69 char buf[HANDLE_LENGTH];
70 SAMLConfig::getConfig().generateRandomBytes(buf,HANDLE_LENGTH);
71 for (int i=0; i<HANDLE_LENGTH; i++)
75 SAML2ArtifactType0004::SAML2ArtifactType0004(const string& sourceid, int index, const string& handle)
77 if (sourceid.size()!=SOURCEID_LENGTH)
78 throw ArtifactException("Type 0x0004 artifact sourceid of incorrect length.");
79 if (index < 0 || index > (1 << 16)-1)
80 throw ArtifactException("Type 0x0004 artifact index is invalid.");
81 if (handle.size()!=HANDLE_LENGTH)
82 throw ArtifactException("Type 0x0004 artifact message handle of incorrect length.");
85 m_raw+=(char)(index / 256);
86 m_raw+=(char)(index % 256);
87 m_raw.append(sourceid,0,SOURCEID_LENGTH);
88 m_raw.append(handle,0,HANDLE_LENGTH);
91 SAML2ArtifactType0004::SAML2ArtifactType0004(const SAML2ArtifactType0004& src) : SAML2Artifact(src)
95 SAML2ArtifactType0004::~SAML2ArtifactType0004()
99 SAML2ArtifactType0004* SAML2ArtifactType0004::clone() const
101 return new SAML2ArtifactType0004(*this);
104 string SAML2ArtifactType0004::getSource() const
106 return toHex(getSourceID());
109 string SAML2ArtifactType0004::getSourceID() const
111 return m_raw.substr(TYPECODE_LENGTH + INDEX_LENGTH, SOURCEID_LENGTH); // bytes 5-24
114 string SAML2ArtifactType0004::getMessageHandle() const
116 return m_raw.substr(TYPECODE_LENGTH + INDEX_LENGTH + SOURCEID_LENGTH, HANDLE_LENGTH); // bytes 25-44