summaryrefslogtreecommitdiffstats
path: root/xmlsecurity/source/helper/ooxmlsecparser.cxx
blob: 4bc7274b783bb3adcfb181ed3516c3fc8c27f88a (plain)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */


#include "ooxmlsecparser.hxx"

using namespace com::sun::star;

OOXMLSecParser::OOXMLSecParser(XSecController* pXSecController)
    : m_pXSecController(pXSecController)
    ,m_bInDigestValue(false)
    ,m_bInSignatureValue(false)
    ,m_bInX509Certificate(false)
    ,m_bInMdssiValue(false)
    ,m_bInSignatureComments(false)
{
}

OOXMLSecParser::~OOXMLSecParser()
{
}

void SAL_CALL OOXMLSecParser::startDocument() throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
{
    if (m_xNextHandler.is())
        m_xNextHandler->startDocument();
}

void SAL_CALL OOXMLSecParser::endDocument() throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
{
    if (m_xNextHandler.is())
        m_xNextHandler->endDocument();
}

void SAL_CALL OOXMLSecParser::startElement(const OUString& rName, const uno::Reference<xml::sax::XAttributeList>& xAttribs)
throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
{
    OUString aId = xAttribs->getValueByName("Id");
    if (!aId.isEmpty())
        m_pXSecController->collectToVerify(aId);

    if (rName == "Signature")
    {
        m_pXSecController->addSignature();
        if (!aId.isEmpty())
            m_pXSecController->setId(aId);
    }
    else if (rName == "Reference")
    {
        OUString aURI = xAttribs->getValueByName("URI");
        if (aURI.startsWith("#"))
            m_pXSecController->addReference(aURI.copy(1));
        // TODO else
    }
    else if (rName == "DigestValue")
    {
        m_aDigestValue.clear();
        m_bInDigestValue = true;
    }
    else if (rName == "SignatureValue")
    {
        m_aSignatureValue.clear();
        m_bInSignatureValue = true;
    }
    else if (rName == "X509Certificate")
    {
        m_aX509Certificate.clear();
        m_bInX509Certificate = true;
    }
    else if (rName == "mdssi:Value")
    {
        m_aMdssiValue.clear();
        m_bInMdssiValue = true;
    }
    else if (rName == "SignatureComments")
    {
        m_aSignatureComments.clear();
        m_bInSignatureComments = true;
    }

    if (m_xNextHandler.is())
        m_xNextHandler->startElement(rName, xAttribs);
}

void SAL_CALL OOXMLSecParser::endElement(const OUString& rName) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
{
    if (rName == "SignedInfo")
        m_pXSecController->setReferenceCount();
    else if (rName == "Reference")
        m_pXSecController->setDigestValue(m_aDigestValue);
    else if (rName == "DigestValue")
        m_bInDigestValue = false;
    else if (rName == "SignatureValue")
    {
        m_pXSecController->setSignatureValue(m_aSignatureValue);
        m_bInSignatureValue = false;
    }
    else if (rName == "X509Certificate")
    {
        m_pXSecController->setX509Certificate(m_aX509Certificate);
        m_bInX509Certificate = false;
    }
    else if (rName == "mdssi:Value")
    {
        m_pXSecController->setDate(m_aMdssiValue);
        m_bInMdssiValue = false;
    }
    else if (rName == "SignatureComments")
    {
        m_pXSecController->setDescription(m_aSignatureComments);
        m_bInSignatureComments = false;
    }

    if (m_xNextHandler.is())
        m_xNextHandler->endElement(rName);
}

void SAL_CALL OOXMLSecParser::characters(const OUString& rChars) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
{
    if (m_bInDigestValue)
        m_aDigestValue += rChars;
    else if (m_bInSignatureValue)
        m_aSignatureValue += rChars;
    else if (m_bInX509Certificate)
        m_aX509Certificate += rChars;
    else if (m_bInMdssiValue)
        m_aMdssiValue += rChars;
    else if (m_bInSignatureComments)
        m_aSignatureComments += rChars;

    if (m_xNextHandler.is())
        m_xNextHandler->characters(rChars);
}

void SAL_CALL OOXMLSecParser::ignorableWhitespace(const OUString& rWhitespace) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
{
    if (m_xNextHandler.is())
        m_xNextHandler->ignorableWhitespace(rWhitespace);
}

void SAL_CALL OOXMLSecParser::processingInstruction(const OUString& rTarget, const OUString& rData) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
{
    if (m_xNextHandler.is())
        m_xNextHandler->processingInstruction(rTarget, rData);
}

void SAL_CALL OOXMLSecParser::setDocumentLocator(const uno::Reference<xml::sax::XLocator>& xLocator) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
{
    if (m_xNextHandler.is())
        m_xNextHandler->setDocumentLocator(xLocator);
}

void SAL_CALL OOXMLSecParser::initialize(const uno::Sequence<uno::Any>& rArguments) throw (uno::Exception, uno::RuntimeException, std::exception)
{
    rArguments[0] >>= m_xNextHandler;
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */