Added abstract metadata base, chaining trust and metadata plugins.
[shibboleth/cpp-opensaml.git] / saml / saml1 / core / impl / SAMLArtifactType0002.cpp
1 /*
2  *  Copyright 2001-2006 Internet2
3  * 
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /**
18  * SAMLArtifactType0002.cpp
19  * 
20  * Type 0x0002 SAML 1.x artifact class 
21  */
22
23 #include "internal.h"
24 #include "saml1/core/SAMLArtifactType0002.h"
25
26 using namespace opensaml::saml1p;
27 using namespace opensaml;
28 using namespace xmltooling;
29 using namespace std;
30
31 namespace opensaml {
32     namespace saml1p {
33         SAMLArtifact* SAML_DLLLOCAL SAMLArtifactType0002Factory(const char* const & s)
34         {
35             return new SAMLArtifactType0002(s);
36         }
37     }
38 };
39
40 const unsigned int SAMLArtifactType0002::HANDLE_LENGTH = 20;
41
42 SAMLArtifactType0002::SAMLArtifactType0002(const char* s) : SAMLArtifact(s)
43 {
44     // The base class does the work, we just do the checking.
45     if (m_raw.size() <= TYPECODE_LENGTH + HANDLE_LENGTH)
46         throw ArtifactException("Type 0x0002 artifact given artifact of incorrect length.");
47     else if (m_raw[0] != 0x0 || m_raw[1] != 0x2)
48         throw ArtifactException(
49             string("Type 0x0002 artifact given artifact of invalid type (") + toHex(getTypeCode()) + ")."
50             );
51 }
52
53 SAMLArtifactType0002::SAMLArtifactType0002(const string& sourceLocation)
54 {
55     if (sourceLocation.empty())
56         throw ArtifactException("Type 0x0002 artifact with empty source location.");
57     m_raw+=(char)0x0;
58     m_raw+=(char)0x2;
59     char buf[HANDLE_LENGTH];
60     SAMLConfig::getConfig().generateRandomBytes(buf,HANDLE_LENGTH);
61     for (int i=0; i<HANDLE_LENGTH; i++)
62         m_raw+=buf[i];
63     m_raw+=sourceLocation;
64 }
65
66 SAMLArtifactType0002::SAMLArtifactType0002(const string& sourceLocation, const string& handle)
67 {
68     if (sourceLocation.empty())
69         throw ArtifactException("Type 0x0002 artifact with empty source location.");
70     if (handle.size()!=HANDLE_LENGTH)
71         throw ArtifactException("Type 0x0002 artifact with handle of incorrect length.");
72     m_raw+=(char)0x0;
73     m_raw+=(char)0x2;
74     m_raw.append(handle,0,HANDLE_LENGTH);
75     m_raw+=sourceLocation;
76 }