[Libreoffice-commits] core.git: include/svl include/vcl svl/source vcl/source

Ashod Nakashian ashod.nakashian at collabora.co.uk
Fri Aug 4 00:11:56 UTC 2017


 include/svl/cryptosign.hxx             |    3 ++
 include/vcl/filter/pdfdocument.hxx     |    1 
 include/vcl/pdfwriter.hxx              |    3 --
 svl/source/crypto/cryptosign.cxx       |   49 +++++++++++++++++++++++++++++++++
 vcl/source/filter/ipdf/pdfdocument.cxx |   46 ------------------------------
 5 files changed, 53 insertions(+), 49 deletions(-)

New commits:
commit 0a64fa41045eea8ea179bbf0eee306ffb5851500
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Tue Aug 1 15:04:56 2017 -0400

    svl: move DecodeHexString from vcl
    
    Change-Id: I86da993050bde20f9ff0413ad5424673647a0e5c
    Reviewed-on: https://gerrit.libreoffice.org/40720
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/include/svl/cryptosign.hxx b/include/svl/cryptosign.hxx
index 5d347c96d541..f8c1f36bdd8a 100644
--- a/include/svl/cryptosign.hxx
+++ b/include/svl/cryptosign.hxx
@@ -34,6 +34,9 @@ namespace svl {
 
 namespace crypto {
 
+/// Converts a hex-encoded string into a byte array.
+SVL_DLLPUBLIC std::vector<unsigned char> DecodeHexString(const OString& rHex);
+
 /// Helper to cryptographically sign and verify
 /// arbitrary data blocks.
 class SVL_DLLPUBLIC Signing
diff --git a/include/vcl/filter/pdfdocument.hxx b/include/vcl/filter/pdfdocument.hxx
index 98806a3f17e7..e36fb687e0a0 100644
--- a/include/vcl/filter/pdfdocument.hxx
+++ b/include/vcl/filter/pdfdocument.hxx
@@ -314,7 +314,6 @@ class VCL_DLLPUBLIC PDFDocument
     /// All editing takes place in this buffer, if it happens.
     SvMemoryStream m_aEditBuffer;
 
-    static int AsHex(char ch);
     /// Suggest a minimal, yet free signature ID to use for the next signature.
     sal_uInt32 GetNextSignature();
     /// Write the signature object as part of signing.
diff --git a/include/vcl/pdfwriter.hxx b/include/vcl/pdfwriter.hxx
index 78a28231ea10..b7ecbff71cd9 100644
--- a/include/vcl/pdfwriter.hxx
+++ b/include/vcl/pdfwriter.hxx
@@ -1231,9 +1231,6 @@ The following structure describes the permissions used in PDF security
     */
     void AddStream( const OUString& rMimeType, PDFOutputStream* pStream );
 
-    /// Fill a PDF signature template.
-    static bool Sign(PDFSignContext& rContext);
-
     /// Write rString as a PDF hex string into rBuffer.
     static void AppendUnicodeTextString(const OUString& rString, OStringBuffer& rBuffer);
 
diff --git a/svl/source/crypto/cryptosign.cxx b/svl/source/crypto/cryptosign.cxx
index 7d81ce90dcd7..1e0712fd8850 100644
--- a/svl/source/crypto/cryptosign.cxx
+++ b/svl/source/crypto/cryptosign.cxx
@@ -878,6 +878,55 @@ namespace svl {
 
 namespace crypto {
 
+static int AsHex(char ch)
+{
+    int nRet = 0;
+    if (rtl::isAsciiDigit(static_cast<unsigned char>(ch)))
+        nRet = ch - '0';
+    else
+    {
+        if (ch >= 'a' && ch <= 'f')
+            nRet = ch - 'a';
+        else if (ch >= 'A' && ch <= 'F')
+            nRet = ch - 'A';
+        else
+            return -1;
+        nRet += 10;
+    }
+    return nRet;
+}
+
+std::vector<unsigned char> DecodeHexString(const OString& rHex)
+{
+    std::vector<unsigned char> aRet;
+    size_t nHexLen = rHex.getLength();
+    {
+        int nByte = 0;
+        int nCount = 2;
+        for (size_t i = 0; i < nHexLen; ++i)
+        {
+            nByte = nByte << 4;
+            sal_Int8 nParsed = AsHex(rHex[i]);
+            if (nParsed == -1)
+            {
+                SAL_WARN("svl.crypto", "DecodeHexString: invalid hex value");
+                return aRet;
+            }
+            nByte += nParsed;
+            --nCount;
+            if (!nCount)
+            {
+                aRet.push_back(nByte);
+                nCount = 2;
+                nByte = 0;
+            }
+        }
+    }
+
+    return aRet;
+}
+
+
 #if defined(SVL_CRYPTO_NSS) || defined(SVL_CRYPTO_MSCRYPTO)
 
 bool Signing::Sign(OStringBuffer& rCMSHexBuffer)
diff --git a/vcl/source/filter/ipdf/pdfdocument.cxx b/vcl/source/filter/ipdf/pdfdocument.cxx
index 96960c407c1a..619041595c6b 100644
--- a/vcl/source/filter/ipdf/pdfdocument.cxx
+++ b/vcl/source/filter/ipdf/pdfdocument.cxx
@@ -1892,53 +1892,9 @@ std::vector<PDFObjectElement*> PDFDocument::GetSignatureWidgets()
     return aRet;
 }
 
-int PDFDocument::AsHex(char ch)
-{
-    int nRet = 0;
-    if (rtl::isAsciiDigit(static_cast<unsigned char>(ch)))
-        nRet = ch - '0';
-    else
-    {
-        if (ch >= 'a' && ch <= 'f')
-            nRet = ch - 'a';
-        else if (ch >= 'A' && ch <= 'F')
-            nRet = ch - 'A';
-        else
-            return -1;
-        nRet += 10;
-    }
-    return nRet;
-}
-
 std::vector<unsigned char> PDFDocument::DecodeHexString(PDFHexStringElement const* pElement)
 {
-    std::vector<unsigned char> aRet;
-    const OString& rHex = pElement->GetValue();
-    size_t nHexLen = rHex.getLength();
-    {
-        int nByte = 0;
-        int nCount = 2;
-        for (size_t i = 0; i < nHexLen; ++i)
-        {
-            nByte = nByte << 4;
-            sal_Int8 nParsed = AsHex(rHex[i]);
-            if (nParsed == -1)
-            {
-                SAL_WARN("vcl.filter", "PDFDocument::DecodeHexString: invalid hex value");
-                return aRet;
-            }
-            nByte += nParsed;
-            --nCount;
-            if (!nCount)
-            {
-                aRet.push_back(nByte);
-                nCount = 2;
-                nByte = 0;
-            }
-        }
-    }
-
-    return aRet;
+    return svl::crypto::DecodeHexString(pElement->GetValue());
 }
 
 PDFCommentElement::PDFCommentElement(PDFDocument& rDoc)


More information about the Libreoffice-commits mailing list