tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / xmlsecurity / source / xmlsec / mscrypt / sanextension_mscryptimpl.cxx
blob6ded5fa0cb9c15cd2437717117656fb0951e2eaa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <memory>
24 #include <rtl/uuid.h>
25 #include <rtl/ustring.hxx>
26 #include <com/sun/star/security/ExtAltNameType.hpp>
27 #include <com/sun/star/security/CertAltNameEntry.hpp>
28 #include <com/sun/star/beans/NamedValue.hpp>
29 #include <comphelper/sequence.hxx>
30 #include <o3tl/char16_t2wchar_t.hxx>
32 #include "sanextension_mscryptimpl.hxx"
34 using namespace ::com::sun::star;
35 using namespace ::com::sun::star::uno ;
36 using namespace ::com::sun::star::security ;
38 using ::com::sun::star::security::XCertificateExtension ;
41 SanExtensionImpl::SanExtensionImpl() :
42 m_critical( false )
46 SanExtensionImpl::~SanExtensionImpl() {
50 //Methods from XCertificateExtension
51 sal_Bool SAL_CALL SanExtensionImpl::isCritical() {
52 return m_critical ;
55 css::uno::Sequence< sal_Int8 > SAL_CALL SanExtensionImpl::getExtensionId() {
56 return m_xExtnId ;
59 css::uno::Sequence< sal_Int8 > SAL_CALL SanExtensionImpl::getExtensionValue() {
60 return m_xExtnValue ;
63 //Methods from XSanExtension
64 css::uno::Sequence< css::security::CertAltNameEntry > SAL_CALL SanExtensionImpl::getAlternativeNames(){
66 if (!m_Entries.hasElements())
68 CERT_ALT_NAME_INFO *subjectName;
69 DWORD size;
70 CryptDecodeObjectEx(X509_ASN_ENCODING, X509_ALTERNATE_NAME, reinterpret_cast<unsigned char*>(m_xExtnValue.getArray()), m_xExtnValue.getLength(), CRYPT_DECODE_ALLOC_FLAG | CRYPT_DECODE_NOCOPY_FLAG, nullptr,&subjectName, &size);
72 auto arrCertAltNameEntry = std::make_unique<CertAltNameEntry[]>(subjectName->cAltEntry);
74 for (unsigned int i = 0; i < static_cast<unsigned int>(subjectName->cAltEntry); i++){
75 PCERT_ALT_NAME_ENTRY pEntry = &subjectName->rgAltEntry[i];
77 switch(pEntry->dwAltNameChoice) {
78 case CERT_ALT_NAME_OTHER_NAME :
80 arrCertAltNameEntry[i].Type = ExtAltNameType_OTHER_NAME;
81 PCERT_OTHER_NAME pOtherName = pEntry->pOtherName;
83 css::beans::NamedValue otherNameProp;
84 otherNameProp.Name = OUString::createFromAscii(pOtherName->pszObjId);
86 Sequence< sal_Int8 > otherName( comphelper::arrayToSequence<sal_Int8>(
87 pOtherName->Value.pbData, pOtherName->Value.cbData) );
88 otherNameProp.Value <<= otherName;
90 arrCertAltNameEntry[i].Value <<= otherNameProp;
91 break;
93 case CERT_ALT_NAME_RFC822_NAME :
94 arrCertAltNameEntry[i].Type = ExtAltNameType_RFC822_NAME;
95 arrCertAltNameEntry[i].Value <<= OUString(o3tl::toU(pEntry->pwszRfc822Name));
96 break;
97 case CERT_ALT_NAME_DNS_NAME :
98 arrCertAltNameEntry[i].Type = ExtAltNameType_DNS_NAME;
99 arrCertAltNameEntry[i].Value <<= OUString(o3tl::toU(pEntry->pwszDNSName));
100 break;
101 case CERT_ALT_NAME_DIRECTORY_NAME :
103 arrCertAltNameEntry[i].Type = ExtAltNameType_DIRECTORY_NAME;
104 break;
106 case CERT_ALT_NAME_URL :
107 arrCertAltNameEntry[i].Type = ExtAltNameType_URL;
108 arrCertAltNameEntry[i].Value <<= OUString(o3tl::toU(pEntry->pwszURL));
109 break;
110 case CERT_ALT_NAME_IP_ADDRESS :
112 arrCertAltNameEntry[i].Type = ExtAltNameType_IP_ADDRESS;
114 Sequence< sal_Int8 > ipAddress( comphelper::arrayToSequence<sal_Int8>(
115 pEntry->IPAddress.pbData, pEntry->IPAddress.cbData) );
116 arrCertAltNameEntry[i].Value <<= ipAddress;
117 break;
119 case CERT_ALT_NAME_REGISTERED_ID :
120 arrCertAltNameEntry[i].Type = ExtAltNameType_REGISTERED_ID;
121 arrCertAltNameEntry[i].Value <<= OUString::createFromAscii(pEntry->pszRegisteredID);
122 break;
125 m_Entries = ::comphelper::arrayToSequence< css::security::CertAltNameEntry >(arrCertAltNameEntry.get(), subjectName->cAltEntry);
128 return m_Entries;
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */