diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2017-08-01 15:04:56 -0400 |
---|---|---|
committer | Ashod Nakashian <ashnakash@gmail.com> | 2017-08-04 02:11:24 +0200 |
commit | 0a64fa41045eea8ea179bbf0eee306ffb5851500 (patch) | |
tree | 4ef71c9e6739da9e60bbde6e7eadfbb195d2894c /svl | |
parent | 12e13f1f177d6f203edfbef4b31e1e7d3d3d7e78 (diff) |
svl: move DecodeHexString from vcl
Change-Id: I86da993050bde20f9ff0413ad5424673647a0e5c
Reviewed-on: https://gerrit.libreoffice.org/40720
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Diffstat (limited to 'svl')
-rw-r--r-- | svl/source/crypto/cryptosign.cxx | 49 |
1 files changed, 49 insertions, 0 deletions
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) |