mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-26 08:10:02 +02:00
moved md5 to slsSupportlib, added md5_helper.c
This commit is contained in:
parent
ba122fe2ad
commit
2ff50750f5
@ -5,7 +5,6 @@ set(SOURCES
|
|||||||
src/CmdProxy.cpp
|
src/CmdProxy.cpp
|
||||||
src/CmdParser.cpp
|
src/CmdParser.cpp
|
||||||
src/Pattern.cpp
|
src/Pattern.cpp
|
||||||
../slsSupportLib/opensslMd5/md5.c
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(slsDetectorObject OBJECT
|
add_library(slsDetectorObject OBJECT
|
||||||
@ -14,7 +13,6 @@ add_library(slsDetectorObject OBJECT
|
|||||||
|
|
||||||
target_include_directories(slsDetectorObject PUBLIC
|
target_include_directories(slsDetectorObject PUBLIC
|
||||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
|
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
|
||||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../slsSupportLib/opensslMd5>"
|
|
||||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
|
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -36,7 +34,6 @@ set(PUBLICHEADERS
|
|||||||
include/sls/Detector.h
|
include/sls/Detector.h
|
||||||
include/sls/Result.h
|
include/sls/Result.h
|
||||||
include/sls/Pattern.h
|
include/sls/Pattern.h
|
||||||
../slsSupportLib/opensslMd5/md5.h
|
|
||||||
)
|
)
|
||||||
|
|
||||||
#Shared library
|
#Shared library
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#include "Module.h"
|
#include "Module.h"
|
||||||
#include "SharedMemory.h"
|
#include "SharedMemory.h"
|
||||||
#include "md5.h"
|
|
||||||
#include "sls/ClientSocket.h"
|
#include "sls/ClientSocket.h"
|
||||||
#include "sls/ToString.h"
|
#include "sls/ToString.h"
|
||||||
#include "sls/bit_utils.h"
|
#include "sls/bit_utils.h"
|
||||||
#include "sls/container_utils.h"
|
#include "sls/container_utils.h"
|
||||||
#include "sls/file_utils.h"
|
#include "sls/file_utils.h"
|
||||||
|
#include "sls/md5_helper.h"
|
||||||
#include "sls/network_utils.h"
|
#include "sls/network_utils.h"
|
||||||
#include "sls/sls_detector_exceptions.h"
|
#include "sls/sls_detector_exceptions.h"
|
||||||
#include "sls/sls_detector_funcs.h"
|
#include "sls/sls_detector_funcs.h"
|
||||||
@ -3406,18 +3406,6 @@ sls_detector_module Module::readSettingsFile(const std::string &fname,
|
|||||||
return myMod;
|
return myMod;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Module::calculateChecksum(char *buffer, ssize_t bytes) {
|
|
||||||
MD5_CTX c;
|
|
||||||
MD5_Init(&c);
|
|
||||||
MD5_Update(&c, buffer, bytes);
|
|
||||||
unsigned char out[MD5_DIGEST_LENGTH];
|
|
||||||
MD5_Final(out, &c);
|
|
||||||
std::ostringstream oss;
|
|
||||||
for (int i = 0; i != MD5_DIGEST_LENGTH; ++i)
|
|
||||||
oss << std::hex << std::setw(2) << std::setfill('0') << +out[i];
|
|
||||||
return oss.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Module::programFPGAviaBlackfin(std::vector<char> buffer) {
|
void Module::programFPGAviaBlackfin(std::vector<char> buffer) {
|
||||||
// send program from memory to detector
|
// send program from memory to detector
|
||||||
LOG(logINFO) << "Sending programming binary (from pof) to module "
|
LOG(logINFO) << "Sending programming binary (from pof) to module "
|
||||||
@ -3428,7 +3416,7 @@ void Module::programFPGAviaBlackfin(std::vector<char> buffer) {
|
|||||||
client.Send(filesize);
|
client.Send(filesize);
|
||||||
|
|
||||||
// checksum
|
// checksum
|
||||||
std::string checksum = calculateChecksum(buffer.data(), filesize);
|
std::string checksum = sls::md5_calculate_checksum(buffer.data(), filesize);
|
||||||
LOG(logDEBUG1) << "Checksum:" << checksum;
|
LOG(logDEBUG1) << "Checksum:" << checksum;
|
||||||
char cChecksum[MAX_STR_LENGTH];
|
char cChecksum[MAX_STR_LENGTH];
|
||||||
memset(cChecksum, 0, MAX_STR_LENGTH);
|
memset(cChecksum, 0, MAX_STR_LENGTH);
|
||||||
@ -3544,7 +3532,7 @@ void Module::programFPGAviaNios(std::vector<char> buffer) {
|
|||||||
client.Send(filesize);
|
client.Send(filesize);
|
||||||
|
|
||||||
// checksum
|
// checksum
|
||||||
std::string checksum = calculateChecksum(buffer.data(), filesize);
|
std::string checksum = sls::md5_calculate_checksum(buffer.data(), filesize);
|
||||||
LOG(logDEBUG1) << "Checksum:" << checksum;
|
LOG(logDEBUG1) << "Checksum:" << checksum;
|
||||||
char cChecksum[MAX_STR_LENGTH];
|
char cChecksum[MAX_STR_LENGTH];
|
||||||
memset(cChecksum, 0, MAX_STR_LENGTH);
|
memset(cChecksum, 0, MAX_STR_LENGTH);
|
||||||
|
@ -743,7 +743,6 @@ class Module : public virtual slsDetectorDefs {
|
|||||||
std::string getTrimbitFilename(detectorSettings settings, int e_eV);
|
std::string getTrimbitFilename(detectorSettings settings, int e_eV);
|
||||||
sls_detector_module readSettingsFile(const std::string &fname,
|
sls_detector_module readSettingsFile(const std::string &fname,
|
||||||
bool trimbits = true);
|
bool trimbits = true);
|
||||||
std::string calculateChecksum(char *buffer, ssize_t bytes);
|
|
||||||
void programFPGAviaBlackfin(std::vector<char> buffer);
|
void programFPGAviaBlackfin(std::vector<char> buffer);
|
||||||
void programFPGAviaNios(std::vector<char> buffer);
|
void programFPGAviaNios(std::vector<char> buffer);
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@ set(SOURCES
|
|||||||
src/UdpRxSocket.cpp
|
src/UdpRxSocket.cpp
|
||||||
src/sls_detector_exceptions.cpp
|
src/sls_detector_exceptions.cpp
|
||||||
# src/sls_detector_defs.cpp
|
# src/sls_detector_defs.cpp
|
||||||
|
src/md5.c
|
||||||
|
src/md5_helper.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# Header files to install as a part of the library
|
# Header files to install as a part of the library
|
||||||
@ -44,6 +46,8 @@ if(SLS_DEVEL_HEADERS)
|
|||||||
include/sls/versionAPI.h
|
include/sls/versionAPI.h
|
||||||
include/sls/ZmqSocket.h
|
include/sls/ZmqSocket.h
|
||||||
include/sls/bit_utils.h
|
include/sls/bit_utils.h
|
||||||
|
include/sls/mdf5.h
|
||||||
|
include/sls/md5_helper.h
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -222,7 +222,13 @@
|
|||||||
|
|
||||||
# include <stddef.h>
|
# include <stddef.h>
|
||||||
|
|
||||||
|
|
||||||
# ifdef __cplusplus
|
# ifdef __cplusplus
|
||||||
|
/*
|
||||||
|
* Modifications 2021 Paul Scherrer Institut
|
||||||
|
* namespace sls added
|
||||||
|
*/
|
||||||
|
namespace sls {
|
||||||
extern "C" {
|
extern "C" {
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
@ -372,5 +378,8 @@ int MD5_Final(unsigned char *md, MD5_CTX *c);
|
|||||||
void md5_block_data_order(MD5_CTX *c, const void *p, size_t num);
|
void md5_block_data_order(MD5_CTX *c, const void *p, size_t num);
|
||||||
# ifdef __cplusplus
|
# ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
|
|
9
slsSupportLib/include/sls/md5_helper.h
Normal file
9
slsSupportLib/include/sls/md5_helper.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "sls/md5.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
std::string md5_calculate_checksum(char *buffer, ssize_t bytes);
|
||||||
|
} // namespace sls
|
@ -224,13 +224,17 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modification 2021 Paul Scherrer Institut
|
* Modification 2021 Paul Scherrer Institut
|
||||||
* Header included was md5_local.h
|
* Header included was md5_local.h
|
||||||
* and included string.h header
|
* and string.h header was included
|
||||||
|
* sls namespace added
|
||||||
*/
|
*/
|
||||||
|
#include "sls/md5.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "md5.h"
|
#ifdef __cplusplus
|
||||||
|
namespace sls {
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modification 2021 Paul Scherrer Institut
|
* Modification 2021 Paul Scherrer Institut
|
||||||
@ -504,4 +508,8 @@ int HASH_FINAL(unsigned char *md, HASH_CTX *c)
|
|||||||
HASH_MAKE_STRING(c, md);
|
HASH_MAKE_STRING(c, md);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} // namespace sls
|
||||||
|
#endif
|
28
slsSupportLib/src/md5_helper.cpp
Normal file
28
slsSupportLib/src/md5_helper.cpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include "sls/md5_helper.h"
|
||||||
|
|
||||||
|
#include <iomanip>
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
|
std::string md5_calculate_checksum(char *buffer, ssize_t bytes) {
|
||||||
|
MD5_CTX c;
|
||||||
|
if (!MD5_Init(&c)) {
|
||||||
|
throw std::runtime_error(
|
||||||
|
"Could not calculate md5 checksum.[initializing]");
|
||||||
|
}
|
||||||
|
if (!MD5_Update(&c, buffer, bytes)) {
|
||||||
|
throw std::runtime_error("Could not calculate md5 checksum.[Updating]");
|
||||||
|
}
|
||||||
|
unsigned char out[MD5_DIGEST_LENGTH];
|
||||||
|
if (!MD5_Final(out, &c)) {
|
||||||
|
throw std::runtime_error("Could not calculate md5 checksum.[Final]");
|
||||||
|
}
|
||||||
|
std::ostringstream oss;
|
||||||
|
for (int i = 0; i != MD5_DIGEST_LENGTH; ++i)
|
||||||
|
oss << std::hex << std::setw(2) << std::setfill('0') << +out[i];
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
Loading…
x
Reference in New Issue
Block a user