Added abstract metadata base, chaining trust and metadata plugins.
[shibboleth/cpp-opensaml.git] / saml / saml2 / core / impl / SAML2ArtifactType0004.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  * SAML2ArtifactType0004.cpp
19  * 
20  * Type 0x0004 SAML 2.0 artifact class 
21  */
22
23 #include "internal.h"
24 #include "saml2/core/SAML2ArtifactType0004.h"
25
26 using namespace opensaml::saml2p;
27 using namespace opensaml;
28 using namespace xmltooling;
29 using namespace std;
30
31 namespace opensaml {
32     namespace saml2p {
33         SAMLArtifact* SAML_DLLLOCAL SAML2ArtifactType0004Factory(const char* const & s)
34         {
35             return new SAML2ArtifactType0004(s);
36         }
37     }
38 };
39
40 const unsigned int SAML2ArtifactType0004::SOURCEID_LENGTH = 20;
41 const unsigned int SAML2ArtifactType0004::HANDLE_LENGTH = 20;
42
43 SAML2ArtifactType0004::SAML2ArtifactType0004(const char* s) : SAML2Artifact(s)
44 {
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()) + ")."
51             );
52 }
53
54 SAML2ArtifactType0004::SAML2ArtifactType0004(const string& sourceid, int index)
55 {
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.");
60     m_raw+=(char)0x0;
61     m_raw+=(char)0x4;
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++)
68         m_raw+=buf[i];
69 }
70
71 SAML2ArtifactType0004::SAML2ArtifactType0004(const string& sourceid, int index, const string& handle)
72 {
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.");
79     m_raw+=(char)0x0;
80     m_raw+=(char)0x4;
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);
85 }