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 * SAMLArtifactType0002.cpp
24 * Type 0x0002 SAML 1.x artifact class.
28 #include "saml1/binding/SAMLArtifactType0002.h"
30 using namespace opensaml::saml1p;
31 using namespace opensaml;
32 using namespace xmltooling;
37 SAMLArtifact* SAML_DLLLOCAL SAMLArtifactType0002Factory(const char* const & s)
39 return new SAMLArtifactType0002(s);
44 const unsigned int SAMLArtifactType0002::HANDLE_LENGTH = 20;
46 SAMLArtifactType0002::SAMLArtifactType0002(const SAMLArtifactType0002& src) : SAMLArtifact(src)
50 SAMLArtifactType0002::SAMLArtifactType0002(const char* s) : SAMLArtifact(s)
52 // The base class does the work, we just do the checking.
53 if (m_raw.size() <= TYPECODE_LENGTH + HANDLE_LENGTH)
54 throw ArtifactException("Type 0x0002 artifact given artifact of incorrect length.");
55 else if (m_raw[0] != 0x0 || m_raw[1] != 0x2)
56 throw ArtifactException(
57 string("Type 0x0002 artifact given artifact of invalid type (") + toHex(getTypeCode()) + ")."
61 SAMLArtifactType0002::SAMLArtifactType0002(const string& sourceLocation)
63 if (sourceLocation.empty())
64 throw ArtifactException("Type 0x0002 artifact with empty source location.");
67 char buf[HANDLE_LENGTH];
68 SAMLConfig::getConfig().generateRandomBytes(buf,HANDLE_LENGTH);
69 for (int i=0; i<HANDLE_LENGTH; i++)
71 m_raw+=sourceLocation;
74 SAMLArtifactType0002::SAMLArtifactType0002(const string& sourceLocation, const string& handle)
76 if (sourceLocation.empty())
77 throw ArtifactException("Type 0x0002 artifact with empty source location.");
78 if (handle.size()!=HANDLE_LENGTH)
79 throw ArtifactException("Type 0x0002 artifact with handle of incorrect length.");
82 m_raw.append(handle,0,HANDLE_LENGTH);
83 m_raw+=sourceLocation;
86 SAMLArtifactType0002::~SAMLArtifactType0002()
90 SAMLArtifactType0002* SAMLArtifactType0002::clone() const
92 return new SAMLArtifactType0002(*this);
95 string SAMLArtifactType0002::getMessageHandle() const
97 return m_raw.substr(TYPECODE_LENGTH, HANDLE_LENGTH); // bytes 3-22
100 string SAMLArtifactType0002::getSource() const
102 return m_raw.c_str() + TYPECODE_LENGTH + HANDLE_LENGTH; // bytes 23-terminating null