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.
24 * An Attribute whose values are binary data.
28 #include "attribute/BinaryAttribute.h"
30 #include <xercesc/util/Base64.hpp>
32 using namespace shibsp;
36 SHIBSP_DLLLOCAL Attribute* BinaryAttributeFactory(DDF& in) {
37 return new BinaryAttribute(in);
41 BinaryAttribute::BinaryAttribute(const vector<string>& ids) : Attribute(ids)
45 BinaryAttribute::BinaryAttribute(DDF& in) : Attribute(in)
48 DDF val = in.first().first();
49 while (val.string()) {
50 m_serialized.push_back(val.string());
51 XMLByte* decoded=Base64::decode(reinterpret_cast<const XMLByte*>(val.string()), &x);
53 m_values.push_back(string(reinterpret_cast<char*>(decoded), x));
54 #ifdef SHIBSP_XERCESC_HAS_XMLBYTE_RELEASE
55 XMLString::release(&decoded);
57 XMLString::release((char**)&decoded);
60 val = in.first().next();
64 BinaryAttribute::~BinaryAttribute()
68 vector<string>& BinaryAttribute::getValues()
73 const vector<string>& BinaryAttribute::getValues() const
78 size_t BinaryAttribute::valueCount() const
80 return m_values.size();
83 void BinaryAttribute::clearSerializedValues()
88 const char* BinaryAttribute::getString(size_t index) const
90 return m_values[index].c_str();
93 void BinaryAttribute::removeValue(size_t index)
95 Attribute::removeValue(index);
96 if (index < m_values.size())
97 m_values.erase(m_values.begin() + index);
100 const vector<string>& BinaryAttribute::getSerializedValues() const
104 if (m_serialized.empty()) {
105 for (vector<string>::const_iterator i=m_values.begin(); i!=m_values.end(); ++i) {
106 XMLByte* enc = Base64::encode(reinterpret_cast<const XMLByte*>(i->data()), i->size(), &len);
108 for (pos=enc, pos2=enc; *pos2; pos2++)
112 m_serialized.push_back(reinterpret_cast<char*>(enc));
113 #ifdef SHIBSP_XERCESC_HAS_XMLBYTE_RELEASE
114 XMLString::release(&enc);
116 XMLString::release((char**)&enc);
121 return Attribute::getSerializedValues();
124 DDF BinaryAttribute::marshall() const
126 DDF ddf = Attribute::marshall();
128 DDF vlist = ddf.first();
129 const vector<string>& encoded = getSerializedValues();
130 for (vector<string>::const_iterator i = encoded.begin(); i != encoded.end(); ++i) {
131 DDF val = DDF(nullptr).string(i->c_str());