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 * SAMLArtifactType0001.cpp
24 * Type 0x0001 SAML 1.x artifact class.
28 #include "saml1/binding/SAMLArtifactType0001.h"
30 using namespace opensaml::saml1p;
31 using namespace opensaml;
32 using namespace xmltooling;
37 SAMLArtifact* SAML_DLLLOCAL SAMLArtifactType0001Factory(const char* const & s)
39 return new SAMLArtifactType0001(s);
44 const unsigned int SAMLArtifactType0001::SOURCEID_LENGTH = 20;
45 const unsigned int SAMLArtifactType0001::HANDLE_LENGTH = 20;
47 SAMLArtifactType0001::SAMLArtifactType0001(const SAMLArtifactType0001& src) : SAMLArtifact(src)
51 SAMLArtifactType0001::SAMLArtifactType0001(const char* s) : SAMLArtifact(s)
53 // The base class does the work, we just do the checking.
54 if (m_raw.size() != TYPECODE_LENGTH + SOURCEID_LENGTH + HANDLE_LENGTH)
55 throw ArtifactException("Type 0x0001 artifact is of incorrect length.");
56 else if (m_raw[0] != 0x0 || m_raw[1] != 0x1)
57 throw ArtifactException(
58 string("Type 0x0001 artifact given an artifact of invalid type (") + toHex(getTypeCode()) + ")."
62 SAMLArtifactType0001::SAMLArtifactType0001(const string& sourceid)
64 if (sourceid.size()!=SOURCEID_LENGTH)
65 throw ArtifactException("Type 0x0001 artifact sourceid of incorrect length.");
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 SAMLArtifactType0001::SAMLArtifactType0001(const string& sourceid, const string& handle)
77 if (sourceid.size()!=SOURCEID_LENGTH)
78 throw ArtifactException("Type 0x0001 artifact sourceid of incorrect length.");
79 if (handle.size()!=HANDLE_LENGTH)
80 throw ArtifactException("Type 0x0001 artifact assertion handle of incorrect length.");
83 m_raw.append(sourceid,0,SOURCEID_LENGTH);
84 m_raw.append(handle,0,HANDLE_LENGTH);
87 SAMLArtifactType0001::~SAMLArtifactType0001()
91 SAMLArtifactType0001* SAMLArtifactType0001::clone() const
93 return new SAMLArtifactType0001(*this);
96 string SAMLArtifactType0001::getSource() const
98 return toHex(getSourceID());
101 string SAMLArtifactType0001::getSourceID() const
103 return m_raw.substr(TYPECODE_LENGTH,SOURCEID_LENGTH); // bytes 3-22
106 string SAMLArtifactType0001::getMessageHandle() const
108 return m_raw.substr(TYPECODE_LENGTH+SOURCEID_LENGTH, HANDLE_LENGTH); // bytes 23-42