Skip to content

Commit

Permalink
Fix coverity warnings (#555)
Browse files Browse the repository at this point in the history
IB-7552

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma authored Oct 31, 2023
1 parent 7dc3ce9 commit a5868e6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
steps:
- name: Install Deps
run: |
dnf install -y \
dnf install -y --setopt=install_weak_deps=False \
git gcc-c++ cmake rpm-build xml-security-c-devel zlib-devel vim-common doxygen boost-test swig python3-devel java-1.8.0-openjdk-devel \
https://www.codesynthesis.com/download/xsd/4.0/linux-gnu/x86_64/xsd-4.0.0-1.x86_64.rpm
- name: Checkout
Expand All @@ -105,7 +105,7 @@ jobs:
container: ${{ matrix.container }}
strategy:
matrix:
container: ['ubuntu:20.04', 'ubuntu:22.04', 'ubuntu:23.04']
container: ['ubuntu:20.04', 'ubuntu:22.04', 'ubuntu:23.04', 'ubuntu:23.10']
env:
DEBIAN_FRONTEND: noninteractive
DEBFULLNAME: github-actions
Expand Down
2 changes: 1 addition & 1 deletion cmake
22 changes: 12 additions & 10 deletions src/crypto/Digest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,20 @@ Digest::~Digest() = default;

vector<unsigned char> Digest::addDigestInfo(vector<unsigned char> digest, string_view uri)
{
vector<unsigned char> oid;
switch(toMethod(uri))
{
case NID_sha1: oid = {0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14}; break;
case NID_sha224: oid = {0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04, 0x05, 0x00, 0x04, 0x1c}; break;
case NID_sha256: oid = {0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20}; break;
case NID_sha384: oid = {0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x05, 0x00, 0x04, 0x30}; break;
case NID_sha512: oid = {0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40}; break;
case NID_sha1: digest.insert(digest.cbegin(),
{0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14}); break;
case NID_sha224: digest.insert(digest.cbegin(),
{0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04, 0x05, 0x00, 0x04, 0x1c}); break;
case NID_sha256: digest.insert(digest.cbegin(),
{0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20}); break;
case NID_sha384: digest.insert(digest.begin(),
{0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x05, 0x00, 0x04, 0x30}); break;
case NID_sha512: digest.insert(digest.cbegin(),
{0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40}); break;
default: break;
}
if(!oid.empty())
digest.insert(digest.begin(), oid.begin(), oid.end());
return digest;
}

Expand All @@ -74,7 +76,7 @@ vector<unsigned char> Digest::digestInfoDigest(const std::vector<unsigned char>
return {};
const ASN1_OCTET_STRING *value {};
X509_SIG_get0(sig.get(), nullptr, &value);
return { value->data, value->data + value->length };
return { value->data, std::next(value->data, value->length) };
}

string Digest::digestInfoUri(const std::vector<unsigned char> &digest)
Expand Down Expand Up @@ -141,7 +143,7 @@ int Digest::toMethod(string_view uri)
if(uri == URI_SHA3_384 || uri == URI_RSA_PSS_SHA3_384) return NID_sha3_384;
if(uri == URI_SHA3_512 || uri == URI_RSA_PSS_SHA3_512) return NID_sha3_512;
#endif
THROW("Digest method URI '%.*s' is not supported.", uri.size(), uri.data());
THROW("Digest method URI '%.*s' is not supported.", int(uri.size()), uri.data());
}

string Digest::toRsaUri(const string &uri)
Expand Down

0 comments on commit a5868e6

Please sign in to comment.