File: SAMLArtifactType0002.cpp

package info (click to toggle)
opensaml 3.3.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,480 kB
  • sloc: cpp: 27,961; sh: 4,593; xml: 1,004; makefile: 429; ansic: 18
file content (103 lines) | stat: -rw-r--r-- 3,303 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
 * Licensed to the University Corporation for Advanced Internet
 * Development, Inc. (UCAID) under one or more contributor license
 * agreements. See the NOTICE file distributed with this work for
 * additional information regarding copyright ownership.
 *
 * UCAID licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the
 * License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific
 * language governing permissions and limitations under the License.
 */

/**
 * SAMLArtifactType0002.cpp
 * 
 * Type 0x0002 SAML 1.x artifact class.
 */

#include "internal.h"
#include "saml1/binding/SAMLArtifactType0002.h"

using namespace opensaml::saml1p;
using namespace opensaml;
using namespace xmltooling;
using namespace std;

namespace opensaml {
    namespace saml1p {
        SAMLArtifact* SAML_DLLLOCAL SAMLArtifactType0002Factory(const char* const & s, bool)
        {
            return new SAMLArtifactType0002(s);
        }
    }
};

const unsigned int SAMLArtifactType0002::HANDLE_LENGTH = 20;

SAMLArtifactType0002::SAMLArtifactType0002(const SAMLArtifactType0002& src) : SAMLArtifact(src)
{
}

SAMLArtifactType0002::SAMLArtifactType0002(const char* s) : SAMLArtifact(s)
{
    // The base class does the work, we just do the checking.
    if (m_raw.size() <= TYPECODE_LENGTH + HANDLE_LENGTH)
        throw ArtifactException("Type 0x0002 artifact given artifact of incorrect length.");
    else if (m_raw[0] != 0x0 || m_raw[1] != 0x2)
        throw ArtifactException(
            string("Type 0x0002 artifact given artifact of invalid type (") + toHex(getTypeCode()) + ")."
            );
}

SAMLArtifactType0002::SAMLArtifactType0002(const string& sourceLocation)
{
    if (sourceLocation.empty())
        throw ArtifactException("Type 0x0002 artifact with empty source location.");
    m_raw+=(char)0x0;
    m_raw+=(char)0x2;
    char buf[HANDLE_LENGTH];
    SAMLConfig::getConfig().generateRandomBytes(buf,HANDLE_LENGTH);
    for (unsigned int i=0; i<HANDLE_LENGTH; i++)
        m_raw+=buf[i];
    m_raw+=sourceLocation;
}

SAMLArtifactType0002::SAMLArtifactType0002(const string& sourceLocation, const string& handle)
{
    if (sourceLocation.empty())
        throw ArtifactException("Type 0x0002 artifact with empty source location.");
    if (handle.size()!=HANDLE_LENGTH)
        throw ArtifactException("Type 0x0002 artifact with handle of incorrect length.");
    m_raw+=(char)0x0;
    m_raw+=(char)0x2;
    m_raw.append(handle,0,HANDLE_LENGTH);
    m_raw+=sourceLocation;
}

SAMLArtifactType0002::~SAMLArtifactType0002()
{
}

SAMLArtifactType0002* SAMLArtifactType0002::clone() const
{
    return new SAMLArtifactType0002(*this);
}

string SAMLArtifactType0002::getMessageHandle() const
{
    return m_raw.substr(TYPECODE_LENGTH, HANDLE_LENGTH);    // bytes 3-22
}

string SAMLArtifactType0002::getSource() const
{
    return m_raw.c_str() + TYPECODE_LENGTH + HANDLE_LENGTH; // bytes 23-terminating null
}