22#include <rtl/ustrbuf.hxx>
23#include <osl/diagnose.h>
35 case css::security::CertificateKind_X509:
37 case css::security::CertificateKind_OPENPGP:
54 std::vector< std::pair< OUString, OUString > > vecAttrValueOfDN =
parseDN(rRawString);
55 OUStringBuffer s1, s2;
56 for (
auto i = vecAttrValueOfDN.cbegin();
i < vecAttrValueOfDN.cend(); ++
i)
58 if (
i != vecAttrValueOfDN.cbegin())
64 s2.append(
i->first +
" = " +
i->second);
66 return std::make_pair(s1.makeStringAndClear(), s2.makeStringAndClear());
76std::vector< std::pair< OUString, OUString> >
parseDN(std::u16string_view rRawString)
78 std::vector< std::pair<OUString, OUString> > retVal;
79 bool bInEscape =
false;
80 bool bInValue =
false;
82 sal_Int32 nTypeNameStart = 0;
83 std::u16string_view
sType;
84 OUStringBuffer sbufValue;
85 size_t length = rRawString.size();
95 sType = rRawString.substr(nTypeNameStart, i - nTypeNameStart);
112 if ( i + 1 < length && rRawString[i+1] ==
'"')
115 bInValue = !bInValue;
125 else if (c ==
',' || c ==
'+')
132 OSL_ASSERT(!
sType.empty());
133 retVal.push_back(std::make_pair(OUString(sType), sbufValue.makeStringAndClear()));
136 nTypeNameStart =
i + 1;
153 if (sbufValue.getLength())
155 OSL_ASSERT(!
sType.empty());
156 retVal.push_back(std::make_pair(OUString(sType), sbufValue.makeStringAndClear()));
161std::vector< std::pair< OUString, OUString> >
parseDN(std::u16string_view rRawString)
163 std::vector< std::pair<OUString, OUString> > retVal;
165 bool bInEscape =
false;
166 bool bInValue =
false;
168 sal_Int32 nTypeNameStart = 0;
169 std::u16string_view
sType;
170 OUStringBuffer sbufValue;
171 size_t length = rRawString.size();
181 sType = rRawString.substr(nTypeNameStart,
i - nTypeNameStart);
220 else if (c ==
',' || c ==
'+')
227 OSL_ASSERT(!
sType.empty());
228 retVal.emplace_back(
sType, sbufValue.makeStringAndClear());
231 nTypeNameStart =
i + 1;
251 if (!sbufValue.isEmpty())
253 OSL_ASSERT(!
sType.empty());
254 retVal.emplace_back(
sType, sbufValue.makeStringAndClear());
261 OUString
GetContentPart(
const OUString& _rRawString,
const css::security::CertificateKind &rKind )
263 char const * aIDs[] = {
"CN",
"OU",
"O",
"E",
nullptr };
266 if (rKind == css::security::CertificateKind_OPENPGP )
271 std::vector< std::pair< OUString, OUString > > vecAttrValueOfDN =
parseDN(_rRawString);
274 OUString sPartId = OUString::createFromAscii( aIDs[
i++] );
275 auto idn = std::find_if(vecAttrValueOfDN.cbegin(), vecAttrValueOfDN.cend(),
276 [&sPartId](
const std::pair< OUString, OUString >& dn) { return dn.first == sPartId; });
277 if (idn != vecAttrValueOfDN.cend())
278 retVal = idn->second;
279 if (!retVal.isEmpty())
282 return retVal.isEmpty() ? _rRawString : retVal;
285 OUString
GetHexString(
const css::uno::Sequence< sal_Int8 >& _rSeq,
const char* _pSep, sal_uInt16 _nLineBreak )
287 const sal_Int8* pSerNumSeq = _rSeq.getConstArray();
288 int nCnt = _rSeq.getLength();
290 const char pHexDigs[ 17 ] =
"0123456789ABCDEF";
291 char pBuffer[ 3 ] =
" ";
293 sal_uInt16 nBreakStart = _nLineBreak? _nLineBreak : 1;
294 sal_uInt16 nBreak = nBreakStart;
295 for(
int i = 0 ;
i < nCnt ; ++
i )
300 pBuffer[ 1 ] = pHexDigs[ nNum & 0x0F ];
302 pBuffer[ 0 ] = pHexDigs[ nNum ];
303 aStr.appendAscii( pBuffer );
307 aStr.appendAscii( _pSep );
310 nBreak = nBreakStart;
315 return aStr.makeStringAndClear();
std::pair< OUString, OUString > GetDNForCertDetailsView(std::u16string_view rRawString)
std::vector< std::pair< OUString, OUString > > parseDN(std::u16string_view rRawString)
OUString GetHexString(const css::uno::Sequence< sal_Int8 > &_rSeq, const char *_pSep, sal_uInt16 _nLineBreak)
OUString GetContentPart(const OUString &_rRawString, const css::security::CertificateKind &rKind)
OUString GetCertificateKind(const css::security::CertificateKind &rKind)
std::basic_string_view< charT, traits > trim(std::basic_string_view< charT, traits > str)